• October 12, 2024

Curl Load Test

Simple load testing script (in bash) | by Bharath Raja

Simple load testing script (in bash) | by Bharath Raja

curl -L | bash -s 20 “This keeps hitting your server at the rate of 20 calls/second until you ask it to stop. The just redirects to the raw script from Github (shown below) ExplanationThere’s a while true loop that has a sleep 1 in it so the block get executed every $(($(date +%s) — START)) | awk ‘{print int($1/60)”:”int($1%60)}’This is for printing the current minute and second of the execution (12:45) there’s a for loop that runs the number of times given as the first argument. Inside that, a function is called with the url and & so that it’s run in the $2 &Inside the get function, we have a verbose silent curl to make the request. Then piped to tr removes all the newline. Then the following awk command appends a —– 05:23:19 PM to it and logs it in /temp/ -v date=”$(date +’%r’)” ‘{print $0″\n—–”, date}’ >> /tmp/ you want to add custom headers, add it in the curl command in the Not having `inline code` options in medium is a bit painfulEdit: Medium has implemented inline code and it works great
How to quickly stress test a web server | Bots!

How to quickly stress test a web server | Bots!

The Curl syntax allows you to specify sequences and sets of URL’s. Say for example we’re going to run a load stress test against Google we can run…
curl -s “1-1000]”
This will make 1000 calls to google i. e.
\…
So say you want to stress test your web application and it won’t complain if it’s fed an extra parameter, 10, 000 calls could be done something like.
curl -s “1-10000]”
Multiple Pages, easy just add each page to the command line.
curl -s “1-1000]” “1-1000]”
Or even…
curl -s “1, 2}[1-1000]”
Timing
Using the time command we can get a view on our performance
time curl -s “1, 2}[1-1000]”
real 0m0. 606s
user 0m0. 009s
sys 0m0. 008s
Simulating consecutive users
OK, this is great for sending a whole bunch of calls one after the other but what about simultaneous calls. For this we can place the Curl calls in a script and set them running in the background. i. e.
curl -s “1, 2}[1-1000]” &
pidlist=”$pidlist $! ”
for job in $pidlist do
echo $job
wait $job || let “FAIL+=1”
done
if [ “$FAIL” == “0”]; then
echo “YAY! ”
else
echo “FAIL! ($FAIL)”
fi
Then run time
Caveats
This does not simulate user behaviour exactly as the browser is not only downloading the page but all attached images, javascripts, stylesheet etc. You could simulate this too by adding the URL’s to the url command.
Src:
How to test a website loading speed using the curl command

How to test a website loading speed using the curl command

If you need an accurate measurement of how quickly (or slowly) your websites load, give the curl command a try.
If you’re a web admin, data can be your best friend. Unique visitors, browser identifiers, value per visit, cost per conversion, conversion rates, total number of sessions or visits, top pages, traffic sources, time spent on site, interactions per visit, bounce rate, exit pages–these are metrics which can empower you in those many meetings with those above you in the chain of command. But what about the metrics that help you do your job? One such metric is website loading speed. If your site is slow to load, you’re going to have frustrated customers and clients. How do you measure the load time of your site? Sure, you could point your browser to the page and click a stopwatch. But to do that effectively, you’d have to first clear your browser’s cache, otherwise you’ll get inaccurate data. SEE: 10 free alternatives to Microsoft Word and Excel (TechRepublic download) One way to get a more accurate reading of site load time is by using the curl command. Curl is a tool used to transfer data via various protocols. With it we can time the loading of a website with considerable accuracy. With this command we can see: Total time before a request received a response (time_namelookup) Total time when the TCP protocol was completed on the remote server (time_connect) Time when file transfer was started (time_pretransfer) The time the first byte was to be transmitted to the remote server (time_starttransfer) Time used to complete the response (time_total) What you’ll need The only things you’ll need to make this work are: The curl command (which can be installed on Linux, Windows, and macOS) A website to test
I’ll be demonstrating on Pop! _OS Linux. How to install curl Chances are your Linux distribution includes curl by default. If not, it’s found in the standard repositories and can be installed with commands like: sudo apt-get install curl -y
sudo dnf install curl -y
Usage With curl installed, we can now run the command to test load time of your site. Although the command to test for the five different times is long, it’s actually quite easy to understand. The command itself is: curl -s -w ‘Testing Website Response Time for:%{url_effective}\n\nLookup Time:\t\t%{time_namelookup}\nConnect Time:\t\t%{time_connect}\nPre-transfer Time:\t%{time_pretransfer}\nStart-transfer Time:\t%{time_starttransfer}\n\nTotal Time:\t\t%{time_total}\n’ -o /dev/null ADDRESS
Where ADDRESS is either the URL or IP address of the website to be tested. The three options used are: -s – will show an error if the command fails-w – make curl display results of the command in the terminal window (stdout)-o – output to a fileThe output of the command will display in an easy to read format (Figure A). Figure A The output of the command run on an instance of your site uses HTTPS, you can add the following: Time measured for the entire SSL communication process (time_appconnect). Time measured for redirection (time_redirect). This command would be: curl -s -w ‘Testing Website Response Time for:%{url_effective}\n\nLookup Time:\t\t%{time_namelookup}\nConnect Time:\t\t%{time_connect}\nAppCon Time:\t\t%{time_appconnect}\nRedirect Time:\t\t%{time_redirect}\nPre-transfer Time:\t%{time_pretransfer}\nStart-transfer Time:\t%{time_starttransfer}\n\nTotal Time:\t\t%{time_total}\n’ -o /dev/null ADDRESS
The results of this command are shown in Figure B. Figure B Testing HTTPS website load time with curl. How to create an easier command You could make this command considerably easier to run by creating a curl formatting file and then issuing the command calling the file. Here’s how. First, create a file with the command: nano ~/
In that file, paste the following: time_namelookup:%{time_namelookup}\n
time_connect:%{time_connect}\n
time_appconnect:%{time_appconnect}\n
time_pretransfer:%{time_pretransfer}\n
time_redirect:%{time_redirect}\n
time_starttransfer:%{time_starttransfer}\n
———-\n
time_total:%{time_total}\n
Save and close the file. Now run the command like so: curl -w “” -o /dev/null -s ADDRESS
Where ADDRESS is either the URL or IP address of the site to be tested. The output should be the same as if you ran the command with all of the options inline (Figure C). Figure C The command output looks that’s how you can get a more accurate measure of how quickly your websites are loading. Find out how you can get even more out of curl with the command man curl.
Open Source Weekly Newsletter
You don’t want to miss our tips, tutorials, and commentary on the Linux OS and open source applications.
Delivered Tuesdays
Sign up today
Also see How to become a software engineer: A cheat sheet (TechRepublic)Choosing your Windows 7 exit strategy: Four options (TechRepublic Premium)How to install a LAMP server on Ubuntu Server 19. 10 (TechRepublic)How to set a Linux hostname without rebooting (TechRepublic)How to deploy a container with Ansible (TechRepublic)FBI warns about snoopy smart TVs spying on you (ZDNet)The 10 most important iPhone apps of all time ()It takes work to keep your data private online. These apps can help (CNET)Must-read coverage: Programming languages and developer career resources (TechRepublic on Flipboard)
Image: iStockphoto/metamorworks

Frequently Asked Questions about curl load test

Leave a Reply

Your email address will not be published. Required fields are marked *