It does not matter if it is used Nginx, Apache, Lighttpd or other, any network administrator who has a web server will want at some point to know how fast the web server responds to a given number of queries.
Apache Benchmark + GNUPlot
This time we will use a tool called Apache Benchmark, which although it has 'apache' in its name, is NOT just for measuring Apache performance, but can also be used for Nginx and others. Actually, I'll use it to measure the performance of Nginx.
We will also use GNUPlot, which will help us to make graphs like these with a few lines:
Installing Apache Benchmark and GNUPlot
Apache Benchmark is a tool that we can use after installing the Apache package, GNUPlot will be available after installing the package of the same name. So then ...
On distros like Debian, Ubuntu or similar:
sudo apt-get install apache2 gnuplot
In distros like ArchLinux or derivatives:
sudo pacman -S apache gnuplot
We only need to install the Apache package, we do not need to start it or configure anything else, just installing it will be enough.
Using Apache Benchmark
What we will do is send a specific number of requests (100) in groups of several (from 20 to 20) to a specific site. We will save the result in a .csv file (result.csv) and then process it with GNUPloit, the line would be:
ab -g resultados.csv -n 100 -c 20 http://nuestro-sitio-web.com/
It is very important to put the final / in the URL of the site to be measured.
This is the output or log that shows me when I test a site on my network:
This is ApacheBench, Version 2.3 <$ Revision: 1638069 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking gutl.jovenclub.cu (be patient) ..... done
Server Software: nginx Server Hostname: gutl.jovenclub.cu Server Port: 80Document Path: /
Document Length: 206 bytes Concurrency Level: 20 Time taken for tests: 0.101 seconds Complete requests: 100 Failed requests: 27 (Connect: 0, Receive: 0, Length: 27, Exceptions: 0) Non-2xx responses: 73 Total transferred: 1310933 bytes HTML transferred: 1288952 bytes
Requests per second: 993.24 [# / sec] (mean)
Time per request: 20.136 [ms] (mean) Time per request: 1.007 [ms] (mean, across all concurrent requests) Transfer rate: 12715.49 [Kbytes / sec] received Connection Times (ms) min mean [+/- sd] median max Connect: 0 1 0.2 1 1 Processing: 1 17 24.8 4 86 Waiting: 1 15 21.5 4 76 Total: 1 18 24.8 5 87 Percentage of the requests served within a certain time (ms) 50% 5 66% 6 75% 22 80% 41 90% 62 95% 80 98% 87 99% 87
100% 87 (longest request)
I have marked in red what I consider to be the most important thing, which has been more or less:
Data of the server we are testing, as well as the URL in question.
Number of requests per second.
How many milliseconds it took the server to attend the request that took the longest, that is, the one that took the longest to be answered.
With this information, they can have an idea of ​​how long it will take for the server to attend that number of requests, they can then add a better cache system, deactivate modules that they do not use, etc etc, run the test again and see if performance improved or not .
I recommend running the test 2 or 3 times, so that you create something like a margin, because rarely the results of two tests in a row are identical.
Other useful Apache Benchmark options or parameters:
-k -H 'Accept-Encoding: gzip, deflate' : With this ab will accept the cache and compression that the server has configured, so the times will be lower.
-f urls.txt : So instead of just testing the site's index, it will carry out tests on the URLs that we specify in that file.
Anyway ... take a look at man ab for you to see.
Show the result in a graph:
To put this output in an image, that is, in a more visual medium and that many times, it is everything that managers manage to understand ... for this we will use as I said before, GNUPlot
In the same folder where we have the file results.csv (remember, we just generated with the above command) we are going to create a file called gnuplot.p:
nano plot.p
In it we will put the following:
set terminal png size 600 set output "results.png"set title"100 requests, 20 concurrent requests "set size ratio 0.6 set grid and set xlabel"petitions"set ylabel"response time (ms)"plot"results.csv"using 9 smooth sbezier with lines title"gutl.jovenclub.cu"
I have indicated in red what you should always check. That is and from top to bottom:
Name of the image file to be generated
Number of total and concurrent requests.
Name of the file that we just generated.
Domain we work on.
Once we put that in, save and exit (Ctrl + O and then Ctrl + X), we will execute the following:
gnuplot plot.p
And voila, that will generate the graph with the desired name, mine is:
The end!
Apache Benchmark has a lot more options, there are also many combinations that we can use to make our performance test even more complete.