target=${1:-http://web1.com}
while true # loop forever, until ctrl c pressed.
do
for i in $(seq 10) # perfrom the inner command 10 times.
do
curl $target > /dev/null & # send out a curl request, the & indicates not to wait for the response.
done
wait # after 100 requests are sent out, wait for their processes to finish before the next iteration.
done
我想通過一次提供多個 HTTP 請求來訓練我的 HTTP 負載平衡。我發現這段代碼可以幫助我一次向 web1.com 發送 10 個序列 HTTP 請求。但是,我希望代碼在達到 15000 個請求時停止。
所以總共會有 1500 次發送 HTTP 請求。
感謝你們對我的幫助
更新
我決定使用嘿。 https://serverfault.com/a/1082007/861352
我使用這個命令來運行請求
hey -n 100 -q 2 -c 1 http://web1.com -A
哪一個:
-n: stop the request when it reaches 100 request
-q: give a break for 2 (not request /second but query /second) to avoid flooding requests at once
-c: send the request at once 1 request
http://web1.com = my web
-A = accept header, I have an error when removing -A
uj5u.com熱心網友回復:
這有效:
target=${1:-http://web1.com}
limit=1500
count=0
while true # loop forever, until ctrl c pressed.
do
for i in $(seq 10) # perfrom the inner command 10 times.
do
count=$(expr $count 1) # increments 1
curl -sk $target > /dev/null & # send out a curl request, the & indicates not to wait for the response
done
wait # after 100 requests are sent out, wait for their processes to finish before the next iteration.
if [ $count -ge $limit ];then
exit 0
fi
done
uj5u.com熱心網友回復:
也許您真正需要的是一個基本的命令列壓力測驗工具。
比如siege就特別簡單好用:
siege --delay 1 --concurrent 10 --reps 1500 http://web1.com
會做幾乎你所期望的......
關于圍城的介紹文章
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/455942.html
上一篇:使用python發送curl請求
