06 - May - 2009

Drupal quick optimisation; Caching and APC

Post by Chris H
Ixis Service

What sort of performance increase would you expect to see by simply using Alternative PHP Cache (APC) and Drupal caching? APC is an extension that caches the compiled PHP bytecode hence avoiding the overhead of parsing and compiling source code for every single request.

The following benchmarks were performed using ApacheBench with 1000 requests (50 concurrently). The requests were sent to the frontpage of the site, which is quite intensive in terms of modules ( views // panels // custom modules - 259 queries to be exact)
Stato!
Drupal version: 5.x
Node count:46,000
Users: 24,000

APC OFF / DRUPAL CACHING OFF
-----------------------------------------------------
Time taken for tests: 194.665231 seconds
Failed requests: 1 (Connect: 0, Length: 1, Exceptions: 0) Write errors: 0
Requests per second: 5.14 [#/sec] (mean)
Time per request: 194.665 [ms] (mean, across all concurrent requests)

APC OFF / DRUPAL CACHING ON
----------------------------------------------------
Time taken for tests: 29.776744 seconds
Failed requests: 0 Write errors: 0
Requests per second: 33.58 [#/sec] (mean)
Time per request: 29.777 [ms] (mean, across all concurrent requests)

APC ON / DRUPAL CACHING OFF
----------------------------------------------------
Time taken for tests: 53.677419 seconds
Failed requests: 1 (Connect: 0, Length: 1, Exceptions: 0) Write errors: 0
Requests per second: 18.63 [#/sec] (mean)
Time per request: 53.677 [ms] (mean, across all concurrent requests)

APC ON / DRUPAL CACHING ON
----------------------------------------------------
Time taken for tests: 4.329999 seconds
Failed requests: 0 Write errors: 0
Requests per second: 230.95 [#/sec] (mean)
Time per request: 43.300 [ms] (mean)
Time per request: 4.330 [ms] (mean, across all concurrent requests)

As you can see initially with APC / drupal caching off the time to serve the total request was 194 seconds. This drops heavily to 29s with drupal caching only, and to 53s purely with APC enabled.

This is expected on the site in question as the page had more database queries than PHP code.

The biggest gain comes when combining both drupal caching & APC which reduces the time taken from 194.6 to 4.3 seconds, a very respectable 45x faster (or just as importantly a 45x increase in requests per second)

In summary simply enabling drupal cache + APC gives a great performance improvement for very little time spent. Installing the PECL module is extremely quick (literally an aptitude/yum install php-pecl-apc) (tip for RHEL - you may need to remount /tmp with exec flags first)

APC will be included in the core of PHP 6 which is also good to know moving forward and will be our preferred route given we've had segmentation faults when benchmarking eAccelerator

After enabling APC you may went to spend some time tuning it further. One of the first place to look is the bundled apc.php included, which gives a detailed breakdown of the current memory usage / runtime settings. As a minimum you can check your cache hit ratio here and if this is too low the size of each shared memory segment needs to be increased from the default 30meg, more parameters can be found here

Picture of Chris H

Chris H

Commercial Director

Comments

Thanks for the write-up. Implemented APC out of the box here and seeing roughly 25 times in speed before any further tweaking.

arobbo

Add new comment

Share this article

Sign up to our newsletter!

Our thoughts

Let's work together

Get in touch and find out how we can empower your organisation.
Back to top