We hope you enjoy reading this blog post

If you need help with website or marketing, book a call with our team for a free 360° overview and actionable recommendations report. Book a call

Speed up Drupal performance with APC (Alternate PHP Cache)

Speed up Drupal performance with APC (Alternate PHP Cache)

Today I will be talking about APC (Alternate PHP Cache) and how to install it on Ubuntu servers to speed up Drupal. So lets get right to it.

Before we begin I think it’s a good idea to set a performance benchmark to gain a better sense of the effect APC will have on site performance. One way to do this is use the Apache Benchmark (ab) tool (substituting your own website of course):

ab -n 10 -c 10 http://www.somewhere.com/

This will hit the server with 10 requests with a maximum of 5 requests running concurrently. Repeat the test a couple times then average out your results to get a sense of where your performance stands before we install APC. These were my results:

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:        0    1   1.7      0       3
Processing:  2962 5500 2640.3   7789    8089
Waiting:     2679 5277 2719.3   6963    8088
Total:       2965 5502 2638.9   7789    8089
Percentage of the requests served within a certain time (ms)
  50%   7789
  66%   8032
  75%   8050
  80%   8059
  90%   8089
  95%   8089
  98%   8089
  99%   8089
 100%   8089 (longest request) WOW!!! Not good at all…
Now lets see how APC will help us to improve performance.
Step 1:

First we have to install PECL and the latest PHP-dev packages. You might already have these packages installed, but it doesn’t hurt to run them again to make sure.

sudo aptitude install php-pear
sudo aptitude install php5-dev
sudo aptitude install apache2-dev

Step 2:

*Please note there are some excremental modules that are part of APC. Do not enable them including debugging feature. Simply type [no] for each module.

sudo pecl install apc

Step 3:

To enable in APC all we need to do is edit the php.ini configuration file:

sudo nano /etc/php5/apache2/php.ini

# Add this to the bottom of the file:

extension=apc.so
apc.enabled = 1
apc.shm_size = 48

Once we restart Apache, APC will be enabled with a memory limit of 48MB. This should be enough for most Drupal installs, but if you have a lot of Drupal modules enabled you may want to come back and increase this number later. If there is not enough memory in the APC cache you may end up hurting your performance instead of enhancing it. Restart Apache to finish the installation:

sudo service apache2 restart

And that’s it! APC is now installed and running.

Lets try to run our test again to see how APC is performing:

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   2.1      0       4
Processing:   394  411  10.1    412     428
Waiting:      394  404   7.9    404     421
Total:        394  413  11.1    414     432
Percentage of the requests served within a certain time (ms)
  50%    414
  66%    416
  75%    420
  80%    425
  90%    432
  95%    432
  98%    432
  99%    432
 100%    432 (longest request)
Huge improvement over our initial test. Now our Drupal website is much faster. Enjoy coding…

Like our blog? Subscribe to our newsletter.

Over 4000 marketers love it. Receive information on best marketing practices, exclusive offers, and ways to boost efficiency, quality, and productivity.
* indicates required
marketing drives leads. We drive Marketing.

You Might Also Like