Delivery speed optimization for Apache httpd and PHP
The exercise is this:
On a web site running Apache's httpd, PHP and MySQL server, what is the impact of a couple of simple and common optimizations. Namely, APC for PHP, and DEFLATE for httpd.
Load testing software
siege "is an http load testing and benchmarking utility". It simulates multiple web browsers operating contemporaneously downloading multiple files and pages from the target web site. At the end of the test it displays a number of statistics
What is APC?
APC is the Alternative PHP Cache package. Whereas without APC, each time PHP code is run by the web server it is first converted to bytecode before being interpreted, with APC installed and enabled, compiled bytecode is cached so that on subsequent executions of the PHP code, the compiling-into-bytecode step is is skipped, leading to faster execution times.
What is DEFLATE?
DEFLATE is an httpd output filter (mod_deflate). It compress what is sent to the user's web browser using gzip. In the test, DEFLATE was used to compress the text/html, text/plain, and text/xml types.
DEFLATE necessarily increases the amount of time it takes to generate a web page because it adds an extra processing step (the data compression). Ideally, this extra processing time is offset by the reduced time it takes to send the compressed web page to the user's browser over nominally "slow" links.
The test environment
The test was done using a CentOS Linux server running on a virtual machine, and an Apple Macmini running the siege software (see above). Both computers were on the same 100MB/s Ethernet subnetwork. The software versions used were:
Linux distribution on server | CentOS 6.3 |
Kernel version on server | 2.6.32-279.19.1.el6.x86_64 |
Apache httpd version | 2.2.15 |
PHP version | 5.3.3 |
PHP APC version | 3.1.9 |
MySQL server version |
5.1.67 |
Drupal version | 7.19 |
OS on client used for testing | Mac OS X 10.8.2 |
siege version | 2.74 |
Interesting numbers to examine include:
- Data transferred, and
- [Average] response time
Initial test results without APC and without DEFLATE:
Transactions: | 600 hits |
Availability: | 100.00 % |
Elapsed time: | 98.24 secs |
Data transferred: | 5.07 MB |
Response time: | 0.45 secs |
Transaction rate: | 6.11 trans/sec |
Throughput: | 0.05 MB/sec |
Concurrency: | 2.72 |
Successful transactions: | 600 |
Failed transactions: | 0 |
Longest transaction: | 0.95 |
Shortest transaction: | 0.14 |
Test results with APC:
Transactions: | 600 hits |
Availability: | 100.00 % |
Elapsed time: | 59.34 secs |
Data transferred: | 5.08 MB |
Response time: | 0.06 secs |
Transaction rate: | 10.11 trans/sec |
Throughput: | 0.09 MB/sec |
Concurrency: | 0.57 |
Successful transactions: | 600 |
Failed transactions: | 0 |
Longest transaction: | 0.82 |
Shortest transaction: | 0.03 |
Test results with APC and with DEFLATE:
Transactions: | 600 hits |
Availability: | 100.00 % |
Elapsed time: | 60.09 secs |
Data transferred: | 1.62 MB |
Response time: | 0.06 secs |
Transaction rate: | 9.99 trans/sec |
Throughput: | 0.03 MB/sec |
Concurrency: | 0.55 |
Successful transactions: | 600 |
Failed transactions: | 0 |
Longest transaction: | 0.19 |
Shortest transaction: | 0.03 |
Test results with APC, with DEFLATE, and with DeflateCompressionLevel set to 9:
Transactions: | 600 hits |
Availability: | 100.00 % |
Elapsed time: | 64.28 secs |
Data transferred: | 1.62 MB |
Response time: | 0.07 secs |
Transaction rate: | 9.33 trans/sec |
Throughput: | 0.03 MB/sec |
Concurrency: | 0.67 |
Successful transactions: | 600 |
Failed transactions: | 0 |
Longest transaction: | 1.17 |
Shortest transaction: | 0.03 |