Article Index

apache

The acronym LAMP refers to a solution stack of software, usually free and open source software, used to run dynamic Web sites or servers. It stand for:

  • Linux, for the operating system;
  • Apache, the Web server;
  • MySQL, the database management system (or database server);
  • Perl, Python, and PHP, the programming languages.

&160;ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.
Apache-utils package contains utility programs for webservers and some add-on programs useful for any webserver. These include:

  • ab (Apache benchmark tool)
  • Logresolve (Resolve IP addresses to hostname in logfiles)
  • htpasswd (Manipulate basic authentication files)
  • htdigest (Manipulate digest authentication files)
  • dbmmanage (Manipulate basic authentication files in DBM format, using perl)
  • htdbm (Manipulate basic authentication files in DBM format, using APR)
  • rotatelogs (Periodically stop writing to a logfile and open a new one)
  • split-logfile (Split a single log including multiple vhosts)
  • checkgid (Checks whether the caller can setgid to the specified group)
  • check_forensic (Extract mod_log_forensic output from apache log files)

This package Apache-Utils can be install through apt or YaST depending if you are using a Debian base distro or OpenSuse

Prerequistes

  • Define realistic objectives, do not create too much virtual clients if you do not have usually that kind of user traffic..
  • For example an objective could be: number of users served, or percentage of the requests served within a certain time
  • This tool ab do not simulate realistic user behavior, it just hit a page without being able to simulate a complex workflow (like login, navigate and do things users usually do)
  • Try to monitor at the same time the CPU/Memory consumed in order not to make false assumption on apache settings (use top d 1)

Attention

It is an iterative process!

  1. Benchmark,
  2. Change settings and
  3. Restart benchmark.

It is very important to only change a setting a time in order to better identify what is really bringing something! By changing only one settings at a time, you can:

  • Better see the influence on CPU, memory (you must look also at resources, a server swapping to disk is never good)
  • There is not so much universal settings bringing a speed kick (except DNSlookup off, keep alive small), some settings are depending on your Linux kernel version, CPU class, disk speed, network latency

Other components

mysql While tuning apache, you will see that most of the time is used in PHP/MySQL, for MySQL recommend to run at the same time tuning-primer.sh, read more here


Usage

ab [ -A auth-username:password ] [ -c concurrency ] [ -C cookie-name=value ] [ -d ] [ -e csv-file ] [ -g gnuplot-file ] [ -h ] [ -H custom-header ] [ -i ] [ -k ] [ -n requests ] [ -p POST-file ] [ -P proxy-auth-username:password ] [ -q ] [ -s ] [ -S ] [ -t timelimit ] [ -T content-type ] [ -v verbosity] [ -V ] [ -w ] [ -x <table>-attributes ] [ -X proxy[:port] ] [ -y <tr>-attributes ] [ -z <td>-attributes ] [http://]hostname[:port]/path

Options

-A auth-username:password
Supply BASIC Authentication credentials to the server. The username and password are separated by a single : and sent on the wire base64 encoded. The string is sent regardless of whether the server needs it (i.e., has sent an 401 authentication needed).
-c concurrency
Number of multiple requests to perform at a time. Default is one request at a time.
-C cookie-name=value
Add a Cookie: line to the request. The argument is typically in the form of a name=value pair. This field is repeatable.
-d
Do not display the "percentage served within XX [ms] table". (legacy support).
-e csv-file
Write a Comma separated value (CSV) file which contains for each percentage (from 1% to 100%) the time (in milliseconds) it took to serve that percentage of the requests. This is usually more useful than the 'gnuplot' file; as the results are already 'binned'.
-g gnuplot-file
Write all measured values out as a 'gnuplot' or TSV (Tab separate values) file. This file can easily be imported into packages like Gnuplot, IDL, Mathematica, Igor or even Excel. The labels are on the first line of the file.
-h
Display usage information.
-H custom-header
Append extra headers to the request. The argument is typically in the form of a valid header line, containing a colon-separated field-value pair (i.e., "Accept-Encoding: zip/zop;8bit").
-i
Do HEAD requests instead of GET.
-k
Enable the HTTP KeepAlive feature, i.e., perform multiple requests within one HTTP session. Default is no KeepAlive.
-n requests
Number of requests to perform for the benchmarking session. The default is to just perform a single request which usually leads to non-representative benchmarking results.
-p POST-file
File containing data to POST.
-P proxy-auth-username:password
Supply BASIC Authentication credentials to a proxy en-route. The username and password are separated by a single : and sent on the wire base64 encoded. The string is sent regardless of whether the proxy needs it (i.e., has sent an 407 proxy authentication needed).
-q
When processing more than 150 requests, ab outputs a progress count on stderr every 10% or 100 requests or so. The -q flag will suppress these messages.
-s
When compiled in (ab -h will show you) use the SSL protected https rather than the http protocol. This feature is experimental and very rudimentary. You probably do not want to use it.
-S
Do not display the median and standard deviation values, nor display the warning/error messages when the average and median are more than one or two times the standard deviation apart. And default to the min/avg/max values. (legacy support).
-t timelimit
Maximum number of seconds to spend for benchmarking. This implies a -n 50000 internally. Use this to benchmark the server within a fixed total amount of time. Per default there is no timelimit.
-T content-type
Content-type header to use for POST data.
-v verbosity
Set verbosity level - 4 and above prints information on headers, 3 and above prints response codes (404, 200, etc.), 2 and above prints warnings and info.
-V
Display version number and exit.
-w
Print out results in HTML tables. Default table is two columns wide, with a white background.
-x <table>-attributes
String to use as attributes for <table>. Attributes are inserted <table here >.
-X proxy[:port]
Use a proxy server for the requests.
-y <tr>-attributes
String to use as attributes for <tr>.
-z <td>-attributes
String to use as attributes for <td>.


Some real examples

time /usr/sbin/ab2 -n 500 -c 30 http://www.waltercedric.com
This will make 500 requests on them and hammering localhost for 30 seconds

After tuning Before tuning
Benchmarking www.waltercedric.com Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 500 requests
Server Software:&160;&160;&160;&160;&160;&160;&160; NOYB
Server Hostname:&160;&160;&160;&160;&160;&160;&160; www.waltercedric.com
Server Port:&160;&160;&160;&160;&160;&160;&160;&160;&160;&160;&160; 80
Document Path:&160;&160;&160;&160;&160;&160;&160;&160;&160; /index.php
Document Length:&160;&160;&160;&160;&160;&160;&160; 45532 bytes
Concurrency Level:&160;&160;&160;&160;&160; 30
Time taken for tests:&160;&160; 38.576375 seconds
Complete requests:&160;&160;&160;&160;&160; 500
Failed requests:&160;&160;&160;&160;&160;&160;&160; 19&160;
&160;&160; (Connect: 0, Length: 19, Exceptions: 0)
Write errors:&160;&160;&160;&160;&160;&160;&160;&160;&160;&160; 0
Total transferred:&160;&160;&160;&160;&160; 23000106 bytes
HTML transferred:&160;&160;&160;&160;&160;&160; 22762106 bytes
Requests per second:&160;&160;&160; 12.96 [#/sec] (mean)
Time per request:&160;&160;&160;&160;&160;&160; 2314.582 [ms] (mean)
Time per request:&160;&160;&160;&160;&160;&160; 77.153 [ms] (mean, across all concurrent requests)
Transfer rate:&160;&160;&160;&160;&160;&160;&160;&160;&160; 582.25 [Kbytes/sec] received
Connection Times (ms)
&160;&160;&160;&160;&160;&160;&160;&160;&160;&160;&160;&160;&160; min&160; mean[+/-sd] median&160;&160; max
Connect:&160;&160;&160;&160;&160;&160;&160; 0&160;&160;&160; 8&160; 36.9&160;&160;&160;&160;&160; 0&160;&160;&160;&160; 207
Processing:&160;&160; 394 2239 345.3&160;&160; 2237&160;&160;&160; 6223
Waiting:&160;&160;&160;&160;&160; 379 2197 340.9&160;&160; 2190&160;&160;&160; 6173
Total:&160;&160;&160;&160;&160;&160;&160; 397 2247 344.2&160;&160; 2239&160;&160;&160; 6223
Percentage of the requests served within a certain time (ms)
&160; 50%&160;&160; 2239
&160; 66%&160;&160; 2294
&160; 75%&160;&160; 2327
&160; 80%&160;&160; 2357
&160; 90%&160;&160; 2457
&160; 95%&160;&160; 2560
&160; 98%&160;&160; 2973
&160; 99%&160;&160; 3341
100%&160;&160; 6223 (longest request)
real&160;&160;&160; 0m38.617s
user&160;&160;&160; 0m0.024s
sys&160;&160;&160;&160; 0m0.240s

Benchmarking www.waltercedric.com
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 500 requests

Server Software:&160;&160;&160;&160;&160;&160;&160; NOYB
Server Hostname:&160;&160;&160;&160;&160;&160;&160; www.waltercedric.com
Server Port:&160;&160;&160;&160;&160;&160;&160;&160;&160;&160;&160; 80

Document Path:&160;&160;&160;&160;&160;&160;&160;&160;&160; /index.php
Document Length:&160;&160;&160;&160;&160;&160;&160; 45532 bytes

Concurrency Level:&160;&160;&160;&160;&160; 30
Time taken for tests:&160;&160; 108.897481 seconds
Complete requests:&160;&160;&160;&160;&160; 500
Failed requests:&160;&160;&160;&160;&160;&160;&160; 19
&160;&160; (Connect: 0, Length: 19, Exceptions: 0)
Write errors:&160;&160;&160;&160;&160;&160;&160;&160;&160;&160; 0
Total transferred:&160;&160;&160;&160;&160; 23000106 bytes
HTML transferred:&160;&160;&160;&160; 23000106 bytes
Requests per second:&160;&160;&160; 4.59 [#/sec] (mean)
Time per request:&160;&160;&160;&160;&160;&160; 6533.849 [ms] (mean)
Time per request:&160;&160;&160;&160;&160;&160; 217.795 [ms] (mean, across all concurrent requests)
Transfer rate:&160;&160;&160;&160;&160;&160;&160;&160;&160; 178.41 [Kbytes/sec] received

Connection Times (ms)
&160;&160;&160;&160;&160;&160;&160;&160;&160;&160;&160;&160;&160; min&160; mean[+/-sd] median&160;&160; max
Connect:&160;&160;&160;&160;&160;&160;&160; 0&160; 114 478.9&160;&160;&160;&160;&160; 0&160;&160;&160; 2276
Processing:&160;&160; 336 6186 1665.2&160;&160; 6108&160;&160; 16189
Waiting:&160;&160;&160; -5148 5982 1982.8&160;&160; 6066&160;&160; 16009
Total:&160;&160;&160;&160;&160;&160;&160; 391 6301 1580.2&160;&160; 6120&160;&160; 17093

Percentage of the requests served within a certain time (ms)
&160; 50%&160;&160; 6120
&160; 66%&160;&160; 6453
&160; 75%&160;&160; 6778
&160; 80%&160;&160; 7046
&160; 90%&160;&160; 7861
&160; 95%&160;&160; 8516
&160; 98%&160; 10110
&160; 99%&160; 12418
100%&160; 17093 (longest request)

real&160;&160;&160; 1m48.905s
user&160;&160;&160; 0m0.024s
sys&160;&160;&160;&160; 0m0.152s

&160;

time /usr/sbin/ab2 -kc 10 -t 30 http://www.waltercedric.com
This will open 10 connections, using Keep-Alive on them and hammering localhost for 30 seconds


Same tests but without mod_security

  • Mod_security is a module for Apache which act like a software firewall
  • Depending on the number of rules, can greatly affect through output speed


time /usr/sbin/ab2 -kc 10 -t 30 http://www.waltercedric.com
This will open 10 connections, using Keep-Alive on them and hammering localhost for 30 seconds

real&160;&160;&160; 0m39.040s
user&160;&160;&160; 0m0.020s
sys&160;&160;&160;&160; 0m0.208s

Nearly one second more with mod_security gotroot rules, worth the added security!

If you want to know more options and how to use apache ab check the apache ab/ab2 man page click here for this man page

How to optimize Apache/Joomla/PHP

I forward You to some of my previous articles:

And more ideas here Secure, Safe, Fast Linux Hosting

You might like also

Clue a command line tool for Apache Lucene search software
Lucene Core  is an open-source search software, provides #Java-based indexing and search technology, as well as spellchecking, hit highlighting and advanced analysis/tokenization capabilities. Luke is a handy development and diagnostic tool, which accesses already existing Lucene indexes and allows you to display and modify their content. Luke is awesome, but often times it is not feasible to inspect an index on a remote machine using a GUI. That's where Clue comes in. You can SSH into your production box and …
2213 Days ago
Apache POI contribution patches
The Apache POI Project's mission is to create and maintain #Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft's OLE 2 Compound Document format (OLE2). In short, you can read and write MS Excel files using #Java. In addition, you can read and write MS Word and MS PowerPoint files using #Java. Apache POI is your #Java Excel solution (for Excel 97-2008). We have a complete API for porting other OOXML and …
2460 Days ago
Need for Speed? mod_pagespeed from Google
mod_pagespeed is the latest addition to our family of products, performing on-the-fly optimization in the Apache™ 2 HTTP Server. It provides webmasters and web developers that manage their Apache 2 configuration with technology that applies Page Speed performance best practices automatically. Webmasters can get the benefits of the optimizations without having to manually going back and fixing the performance issues that Page Speed detects. This solution is valid if you do not want to carefully optimize your site, and it …
3400 Days ago
Subversion and mod Security
I was receiving some strange errors (HTTP error 501) while committing to my public subversion (http://svn.waltercedric.com), all my problems were related to mod security This error 501 means most of the time that the client changed authentication halfway through the commit. That is, it started the commit by sending http requests with a Basic auth header of user1, and then a few requests later it sent a Basic auth header with a different user. Yes but.. …
3939 Days ago
No Thumbnail was found
From http://www.mysqlperformanceblog.com Percona XtraDB includes all of InnoDB’s ACID-compliant design and advanced MVCC architecture, and adds features, more tunability, more metrics, more scalability on many cores, and better memory usage. We choose features and fixes based on customer requests and on our best judgment of real-world needs. We have not included all the InnoDB patches available. For example Google’s well-known InnoDB patch set is omitted (at least for now). The first version of our new storage engine is 1.0.2-1, which …
4023 Days ago
Site optimization: it's all about your image size and format
I really like this small Firefox extension Smushit as it allow to quickly check if all my images are optimized for the best size and thus speed of rendering. But wait IE/Opera/Chrome can still use this bookmarlet :-) to optimize the images found on any web page! From http://www.smushit.com/ Image optimization is an art that not many people master. There are many good image editing tools that allow us to get the best visual result for a certain file size …
4050 Days ago
No Thumbnail was found
From WikiPedia Inline linking (also known as hotlinking, leeching, piggy-backing, direct linking, offsite image grabs and bandwidth theft) is the use of a linked object, often an image, from one site into a web page belonging to a second site. The second site is said to have an inline link to the site where the object is located. This is not just Bandwidth Stealing, as It cost CPU and bandwidth which means less performance for your visitors, It cost a …
4072 Days ago
How to install mod_security 2.5.7
ModSecurityTM is an open source intrusion detection and prevention engine for web applications (or a web application firewall). Operating as an Apache Web server module or standalone, the purpose of ModSecurity is to increase web application security, protecting web applications from known and unknown attacks. from http://www.modsecurity.org/ You'll have to create a free account at https://bsn.breach.com to get the real link # cd # wget https://bsn.breach.com/downloads/t=5156aa8803d6f186cf38688be522a402/modsecurity-apache/modsecurity-apache_2.5.7.tar.gz # tar -zxfv modsecurity-apache_2.5.7.tar.gz # cd modsecurity-apache_2.5.7/apache2 # ./configure # make Copy the library …
4075 Days ago
No Thumbnail was found
A lot of people have tried numerous times to download files from my download section without success, the error message was always the same Unrecoverable error "PCLZIP_ERR_BAD_FORMAT (-10)" Also, Some tried to unpack the zip file locally using stuffit/Winrar/7Zip and get an error suggesting that the archive is damaged. Only Internet Explorer users were having issues, this is because of Internet explorer not able to handle compression of all file types. I solved the issue by changing my mod_deflate.conf which …
4209 Days ago
No Thumbnail was found
This module controls the setting of the Expires HTTP header and the max-age directive of the Cache-Control HTTP header in server responses. The expiration date can set to be relative to either the time the source file was last modified, or to the time of the client access. These HTTP headers are an instruction to the client about the document's validity and persistence. If cached, the document may be fetched from the cache rather than from the source until this …
4531 Days ago