Apache Benchmarks with ab and curl
In web server administration there is often a need to measure the performance of a website. Especially after updates to components such as Apache or PHP, there is a possibility that a well-functioning website may suddenly lose performance.
Two tools can help here to shed light on the matter or to make comparisons after configuration changes to see whether changes are going in the right direction.
On the one hand, there is Apache's own tool ab (Apache benchmark) under Linux
and, on the other hand, the console tool curl, which can be used to start and
measure web access on the console.
1. ab
ab provides benchmarks here and, if necessary, starts multiple accesses in
order to obtain a statistically objective picture. It can send accesses one
after the other or in parallel in order to determine the overall performance
of a web server. The number of tests is determined with the parameter -n. As
an example, a call to ab -n 5 <url> calls the said url 5 times and delivers
approximately the following report:
This is ApacheBench, Version 2.3 <$Revision: 1923142 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking <Servername> (be patient).....done
Server Software: Apache
Server Hostname: <Servername>
Server Port: 80
Document Path: /subdir
Document Length: 133099 bytes
Concurrency Level: 1
Time taken for tests: 7.824 seconds
Complete requests: 5
Failed requests: 0
Total transferred: 669680 bytes
HTML transferred: 665495 bytes
Requests per second: 0.64 [#/sec] (mean)
Time per request: 1564.802 [ms] (mean)
Time per request: 1564.802 [ms] (mean, across all concurrent requests)
Transfer rate: 83.59 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 0
Processing: 1480 1565 64.9 1600 1631
Waiting: 1391 1468 58.1 1507 1515
Total: 1480 1565 64.9 1600 1631
Percentage of the requests served within a certain time (ms)
50% 1591
66% 1608
75% 1608
80% 1631
90% 1631
95% 1631
98% 1631
99% 1631
100% 1631 (longest request)
What is particularly important for my tests is the line “Time taken for tests”, which indicates the total duration of the tests.
If the values of this benchmark are satisfactory, you should repeat them with
parallel tests. In principle, the call is simply extended by the parameter
-c:
ab -n 5 -c 2 <url>
In this case two simultaneous calls.
2. curl
Another tool for measuring the performance of web access is the curl program
mentioned above. The parameter -w "%{time_total}\n" is used to specify the
time required to fully load the page. In all of my tests with curl, this
time specification is the most meaningful.
There are other parameters with which time measurements of all network accesses can be made, but these are usually only necessary if there have been changes in the network infrastructure and these need to be measured.
time_total also does not contain the time necessary to render the entire
page; here, too, there are other parameters that are only really important for
web developers.
For all of these unmentioned parameters I would like to refer you to the Curl
manual (man curl)
curl -o /dev/null -sS -w "%{time_total}\n" <url>
3. Conclusion
Even with well-functioning web servers, it is a good idea to create and document the benchmak mentioned above. This way you always have a comparison and, if necessary, also values for orientation.