As we observed before, configuring APC with low memory can be a drag on performance, causing high executing times.

We saw this recently for a client with a large web site on a dedicated server that approached 2bits.com for performance tuning.

They initially had eAccelerator running on Red Hat, but when their hosting provider upgraded the server, eAccelerator refused to run, because of an API change in compatibility and they missed the error messages in Apache's error log.

After doing a full audit of the site we gave them a report with the recommendations, among whichwas to install APC, since they are on newer PHP versions.

Their hosting provider did install APC, but there was no noticeable difference.

Using the apc.php script that is bundled with APC, we were able to pinpoint the problem: poor cache hit ratio:

As you can see, fragmentation is very bad an d we only get the benefitof 16% cache hit ratio. This is because their hosting provider only installed APC, but did not check if it needs tuning or not.

This site has 99 enabled modules and 6 themes, and the default 30MB of APC is not enough.

So, we tuned APC to increase the apc.shm_size parameter to 128MB, and what a difference that made:

We now have 99% cache hit rate, and zero fragmentation.

And we are up to 308 requests per second too.

Server memory usage dropped significantly too, because each Apache process just retrieves the op-code from APC's cache rather than loading and parsing each Drupal module.

If this server was short of memory, we could reduce APC's memory further based on the actual consumption, say to 50MB or so. But it is better to wait for a while and see if the usage pattern changes before doing this kind of adjustment.

Comments

Tue, 2009/09/22 - 17:19

Thx for the great tutorial Mr.Bahi. I have an inquiry:
APC runtime settings says that apc.shm_size= 256M (we have 2GB of RAM), however the graph shows that total memory is 30MB only (which is totally fragmanted in our case).
What could be the issue?

You probably need to raise the system's shared memory maximum from 32MB (likely if Linux) to 256MB+ with "sysctl -w kernel.shmmax=268435456". It appears another possibility to get more memory for APC is to use multiple 30MB segments (php.ini: apc.shm_segments=8). I suspect one single segment would be more optimal than multiple segments, but maybe not by that much..

Thu, 2010/05/13 - 07:20

Hi

I have activated APC and most of the time memory usgae is not more than 50%. Its a 4gb dedicated server and APC is set up at 512 MB. But there seems to be good amount of fragmentation on server though as a % its not very high. Is it normal or i need to work on this

Wed, 2011/01/26 - 15:34

Those who have limited resources for APC may consider using apc.filters. Setting it to include only very common files results in very high hit percentage with a limited memory.
Example to exclude admin files and include only php and inc files
apc.filters = "+inc$,+php$,-admin"

Or for very limited resources you can also consider excluding contributed modules so you can cache Drupal core only.
apc.filters = "+inc$,+php$,-admin,-sites/all/modules"

Wed, 2011/01/26 - 15:56

forgot to include modules:
apc.filters = "+module$,+php$,+inc$,-admin"

or just exclude install and test files:
apc.filters = "-install$,-test$,-admin"

Tue, 2012/02/14 - 13:07

I just installed APC and configured it with 100MB of cache. Right now i am getting 98.9% hit and 1.1% miss. 17% of the cache is free. I am getting 0.91% framentation and im not sure how to get rid of that. Any help?

Just FYI the server has 2GB of ram and currently each HTTPD process shows about 60-90MB under RES per process when i do Top but overall apache memory usage on the server is 11%.

Is your Drupal or Backdrop CMS site slow?
Is it suffering from server resources shortages?
Is it experiencing outages?
Contact us for Drupal or Backdrop CMS Performance Optimization and Tuning Consulting