Home > Blockchain >  curl code : stop send http request when it reach specific amount?
curl code : stop send http request when it reach specific amount?

Time:04-03

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

I want to train my HTTP load balancing by giving multiple HTTP requests in one time. I found this code to help me to send 10 sequence HTTP requests to web1.com at one time. However, I want the code to stop when reaches 15000 requests.

so in total, there will be 1500 times to send HTTP requests.

thank you for helping me

CodePudding user response:

this works:

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

CodePudding user response:

Maybe what you're really looking for is a basic command-line stress-test tool.

For instance siege is particularly simple and easy to use:

siege --delay 1 --concurrent 10 --reps 1500 http://web1.com

will do pretty much what you're expecting...

introduction article about siege

  • Related