In this recipe, we will learn some performance tuning configurations that may help to squeeze out the last bit of performance from the available hardware. Before diving into performance tuning, we need to evaluate our servers and set a benchmark which can be used to measure improvements after any changes. We will be using a well known HTTP benchmarking tool, Apache Bench (ab). Various other benchmarking tools are available and each one has its own feature set. You can choose the one that best suits your needs.
You will need two systems: one with the web server software installed and another to run Apache Bench. You will need root access or access to an account with similar privileges.
You will also need to modify a few network parameters to handle a large network load. You will also need to set a higher open files limit, in limits.conf
, on both systems. Check the Tuning TCP Stack recipe in Chapter 2, Networking.
apache2-utils
:$ sudo apt-get install apache2-utils
ab
tool as follows:$ ab -h
ab
:$ ab -n 10000 -c 200 -t 2 -k "http://192.168.56.103/index.php"
It will take some time to complete the command depending on the parameters. You should see similar results to the following (partial) output:
Additionally, you may want to benchmark your server for CPU, memory, and IO performance. Check the Setting performance benchmarks recipe in Chapter 13, Performance Monitoring.
Now that we have a benchmark for server performance with stock installation, we can proceed with performance optimization. The following are some settings that are generally recommended for performance tuning:
mod_gzip
/mod_deflate
HostnameLookups
offkeepalive
, then set keepalive timeout
AllowOverride
or completely disable it with AllowOverride none
ExtendedStatus
; this is useful while testing but not in productionworker_processes
to the count of your CPU cores or simply set it to auto
worker_connections
to test multiple values to find the best match for your serverskeepalive_requests
and keepalive_timeout
values; these reduce the overhead of creating new connectionskeepalive
valueaccess_log
; this will reduce IO requests while loggingsendfile
directive to use an efficient sendfile()
call from the operating systemVarious other tools are available for benchmarking different features of the web server. The following are some well known tools, as well as a few latest additions: