¡¡Compartenos!!

lunes, 9 de abril de 2012

ApacheBench - Benchmark para Apache

ApacheBench es una utilidad de benchmarking desarrollada por la Fundación Apache para medir, entre otros, el rendimiento del servidor web más importante en la actualidad.

Esta herramienta realiza las pruebas de carga enviando el número de request (peticiones) HTTP (incluso de forma concurrente) que solicitemos contra una determinada página web.


Una vez terminado el proceso, ApacheBench nos da información acerca de los tiempos minimos, máximos y promedio de tiempo que ha tardado en llevar a cabo estas peticiones, así como la tasa de transferencia o pedidos por segundo que el servidor pudo llevar a cabo.

ApacheBench puede resultar muy interesante para realizar un test de prueba que nos permita conocer si los cambios que hemos hecho en nuestro servidor web han logrado aumentar su rendimiento.

Esta herramienta manejable desde la consola de comandos es software libre bajo licencia Apache. Además al instalar el servidor de Apache se instala con él la última version deApacheBench.

Interesados en acceder a más información de esta utilidad con la que hacer de forma sencilla pero efectiva pruebas rendimiento en nuestro servidor pueden encontrarla desdeApacheBench.


La utilidad "ab" (Apache Benchmark) sirve para hacer pruebas de carga a un servidor apache.
Por ejemplo 100 consultas, con una concurrencia de 5 usuarios a la vez.
ab -n100 -c5 http://www.dominio.com/
No olvidar el "/" final en el URL
Probar con diferentes niveles de concurrencia. Y no olvidar ver las opciones con ab --info pues es batante flexible.
Usage: ab [options] [http://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make
    -t timelimit    Seconds to max. wait for responses
    -p postfile     File containing data to POST
    -T content-type Content-type header for POSTing
    -v verbosity    How much troubleshooting info to print
    -w              Print out results in HTML tables
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. 'Apache=1234. (repeatable)
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
                    Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes
                    are a colon separated username and password.
    -P attribute    Add Basic Proxy Authentication, the attributes
                    are a colon separated username and password.
    -X proxy:port   Proxyserver and port number to use
    -V              Print version number and exit
    -k              Use HTTP KeepAlive feature
    -d              Do not show percentiles served table.
    -S              Do not show confidence estimators and warnings.
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -h              Display usage information (this message)


When your run a webserver, which could be Apache, Nginx or Lighttpd, you may want to know how it is performing.
Actually usually any web server can handle a normal day of work, but what happens when the server under your administration gets, stumbled, or appears in Slashdot, or digg front pages, now a days even twitter may drive a lot of traffic to a webpage.
If that event occurs your server will be under real stress, and it is in that day when you want it to perform well, and survive the "attack".
It is usually not possible to know how it will do that day, until the D. day arrives, but you can figure out how it will be.
We will use ab, which is a tool that comes with Apache is the Apache Benchmarking tool.
First let's see what we need.
  1. The server you want to test with some different files
    • Simple html file
    • Simple php file
    • Simple image file
  2. Another computer with Apache installed (The one which will run the ab test)
  3. Be sure to have a good Bandwidth between the two of them, you can use iperf to check the network connection before
Lets create the files we are going to use for testing.
The .html file
[html]
[title]Simple HTML file for testing server[/title]
[h1]Heading number 1[/h1]
[p]With this file I will test an Apache server[/p]
[p][a href="http://www.go2linux.org"]Linux Operating System[/p]
[/html]
The .php file
[html]
[Title]PHP info[/title]
[?php

// Show all information, defaults to INFO_ALL
phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
phpinfo(INFO_MODULES);

?]
[/html]
The image file is a .jpg file of 72252 bytes.
Now go with the tests
It is assumed that you have put those files in the server you want to test, I have put myself in /tmp/ directory under the root directory of my server.
ab -kc 1000 -n 10000 http://www.some-site.cc/tmp/index.html
This will send 1000 concurrent connections 10.000 times, the results are shown like this.
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0       
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/  
Copyright (c) 2006 The Apache Software Foundation, http://www.apache.org/     

Benchmarking www.some-site.cc (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


Server Software:        Apache/2.2.9
Server Hostname:        www.some-site.cc
Server Port:            80

Document Path:          /tmp/index.html
Document Length:        207 bytes

Concurrency Level:      1000
Time taken for tests:   6.571282 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    9923
Total transferred:      5744865 bytes
HTML transferred:       2083869 bytes
Requests per second:    1521.77 [#/sec] (mean)
Time per request:       657.128 [ms] (mean)
Time per request:       0.657 [ms] (mean, across all concurrent requests)
Transfer rate:          853.71 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    3  26.1      0     225
Processing:     1   69 482.3     12    5947
Waiting:        0   68 482.3     12    5946
Total:          1   72 504.3     12    6143

Percentage of the requests served within a certain time (ms)
  50%     12
  66%     17
  75%     21
  80%     21
  90%     37
  95%     39
  98%    130
  99%   2647
 100%   6143 (longest request)
Now run it with the php file.
ab -kc 1000 -n 10000 http://www.some-site.cc/tmp/index.php
The results are:
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0      
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ 
Copyright (c) 2006 The Apache Software Foundation, http://www.apache.org/    

Benchmarking www.some-site.cc (be patient)
Completed 1000 requests                   
Completed 2000 requests                   
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


Server Software:        Apache/2.2.9
Server Hostname:        www.some-site.cc
Server Port:            80

Document Path:          /tmp/index.php
Document Length:        62446 bytes

Concurrency Level:      1000
Time taken for tests:   157.530617 seconds
Complete requests:      10000
Failed requests:        21
   (Connect: 0, Length: 21, Exceptions: 0)
Write errors:           0
Keep-Alive requests:    0
Total transferred:      628658346 bytes
HTML transferred:       626254006 bytes
Requests per second:    63.48 [#/sec] (mean)
Time per request:       15753.062 [ms] (mean)
Time per request:       15.753 [ms] (mean, across all concurrent requests)
Transfer rate:          3897.17 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0 3898 9601.3    132   93114
Processing:   711 4816 9077.5   2852  151641
Waiting:       96 4079 8403.1   2434  147921
Total:        964 8715 13258.0   4959  152406

Percentage of the requests served within a certain time (ms)
  50%   4959
  66%   6265
  75%   8895
  80%  11189
  90%  19319
  95%  25519
  98%  50649
  99%  69027
 100%  152406 (longest request)
And finally go for the image file, the results are:
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.141 $> apache-2.0               
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/          
Copyright (c) 2006 The Apache Software Foundation, http://www.apache.org/             

Benchmarking www.some-site.cc (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


Server Software:        Apache/2.2.9
Server Hostname:        www.some-site.cc
Server Port:            80

Document Path:          /tmp/38_TaylorSwift.jpg
Document Length:        72252 bytes

Concurrency Level:      1000
Time taken for tests:   30.131674 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Keep-Alive requests:    10000
Total transferred:      730617980 bytes
HTML transferred:       726894150 bytes
Requests per second:    331.88 [#/sec] (mean)
Time per request:       3013.167 [ms] (mean)
Time per request:       3.013 [ms] (mean, across all concurrent requests)
Transfer rate:          23679.20 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    5  49.6      0     552
Processing:   311  440 153.4    422    5346
Waiting:        7  190 172.0    201    4912
Total:        311  446 184.0    422    5898

Percentage of the requests served within a certain time (ms)
  50%    422
  66%    433
  75%    455
  80%    460
  90%    474
  95%    496
  98%    566
  99%    820
 100%   5898 (longest request)
Now let's have the output explained, the most of it is self explaining, but let's go to some of the most important points you may care about.
For the html file
Requests per second:    1521.77 [#/sec] (mean)
Time per request:       657.128 [ms] (mean)
For the php file
Requests per second:    63.48 [#/sec] (mean)
Time per request:       15753.062 [ms] (mean)
For the image file
Requests per second:    331.88 [#/sec] (mean)
Time per request:       3013.167 [ms] (mean)
As you can see, for a single .html file the server can serve 1521 requests per second, for the image size it can 331 requests per second, mostly because of the size of the image, but for the .php it can only attend 63 requests per second, because it involves too much CPU work, I MySQL would be involved, we might see even less performance, the time per request is also another good parameter to look at, as it lets you see the time the server needs to send the page to the user.
I would be a good idea to also run htop while running the "traffic generator" test over the web server.
That way, you will also see how your CPU is managing the load, here is an example of how this small vmware on Debian server is doing its job.
htop image while apache running
You can see that the CPU is working at 100%, and the cpu load is over 40, so it is really stressed.

No hay comentarios:

Publicar un comentario