curl代码:达到特定数量时停止发送http请求?
curl code : stop send http request when it reach specific amount?
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 请求。
谢谢你帮助我
update
我决定用嘿。
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
这个有效:
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
也许您真正需要的是基本的 command-line stress-test 工具。
比如siege特别简单好用:
siege --delay 1 --concurrent 10 --reps 1500 http://web1.com
几乎可以满足您的期望...
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 请求。
谢谢你帮助我
update
我决定用嘿。 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
这个有效:
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
也许您真正需要的是基本的 command-line stress-test 工具。
比如siege特别简单好用:
siege --delay 1 --concurrent 10 --reps 1500 http://web1.com
几乎可以满足您的期望...