APC Settings / Performance - Full Cache and Fragmentation

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Lloyd's picture

Just installed APC on a server that hosts just a few sites. I also enabled the Cache Router module on one site, and each site has Boost running. Originally I installed APC 3.1.6 but apparently there is an issue with that version and it doesn't load Drupal modules into Cache. So everything looked good, but I upgraded to 3.1.7 and now there are many more files being loaded into cache (good) but I'm filling up the cache and getting fragmentation as well.

I've attached a printout of apc.php but here are my current settings.

apc.cache_by_default 1
apc.canonicalize 1
apc.coredump_unmap 0
apc.enable_cli 0
apc.enabled 1
apc.file_md5 0
apc.file_update_protection 2
apc.filters
apc.gc_ttl 1200
apc.include_once_override 0
apc.lazy_classes 0
apc.lazy_functions 0
apc.max_file_size 1M
apc.mmap_file_mask /tmp/apc.nNLTQG
apc.num_files_hint 1024
apc.preload_path
apc.report_autofilter 0
apc.rfc1867 0
apc.rfc1867_freq 0
apc.rfc1867_name APC_UPLOAD_PROGRESS
apc.rfc1867_prefix upload_
apc.rfc1867_ttl 3600
apc.serializer default
apc.shm_segments 1
apc.shm_size 128M
apc.slam_defense 1
apc.stat 1
apc.stat_ctime 0
apc.ttl 86400
apc.use_request_time 1
apc.user_entries_hint 4096
apc.user_ttl 86400
apc.write_lock 1

What should I be doing to fix the issue? Just keep bumping up the shm_size? I feel okay going up to about 256M but that would be the upper limit on this server right now. Do I need to be increasing kernel.shmmax in addition to apc.shm_size? I believe that's still at 32M. How about apc.ttl and apc.user_ttl? I've seen some posts about changing that to 0 but I'm not sure what affect that would have on my sites.

Any help would be appreciated. I'm going to go ahead and boost shm_size up to 160M now to see if that helps with anything.

Thanks

AttachmentSize
APC.pdf35.4 KB

Comments

Looks good to me. Important

dalin's picture

Looks good to me.

Important stuff:
Cache full count: 0
Fragmentation: 0.28%

--


Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his

Woops. I thought I added a

Lloyd's picture

Woops. I thought I added a new post but I replaced the original. Disregard dalin's post above saying it "looks good to me". He was referring to my original APC settings before the upgrade when I had no gragmentation and no full cache count since not many files were being cached. Sorry for any confustion.

Yes, that new pdf is

brianmercer's picture

Yes, that new pdf is horrible. The APC cache is full. It's had to clear the cache of entries 160 times in the first 24 minutes.

You mention cache router module which suggests that you've enabled APC as a data cache.

APC can be used as a code cache (opcode) which requires no Drupal modules. If you're using 128M of code you're using a hella lot of modules.

If you're using the cache router module to cache data you may need to exclude the page cache from APC. That one gets pretty big. With that APC config you're caching on a disk file anyways, and not in RAM. You might be better off putting the page cache back in your db.

Drupal code can be about 30M with no modules up to maybe 100M with tons of modules. Drupal caches, excluding the page cache, can be pretty small with a simple site, just 2M to 5M, to fairly large with views caches, etc. That's per site.

You can increase the size of the APC cache by changing "apc.shm_size 128M" to a larger size. You can also limit what goes into the code cache by using apc.filters (using apc.filters requires apc.cache_by_default 0).

You can limit which cache tables go into the APC data cache by changing your settings.php file.

So deploying APC:

  1. decide whether you're doing just code or code and data
  2. decide whether you're doing RAM or disk file
  3. decide which php code you want in the code cache
  4. decide which data you're putting in the APC data cache
  5. adjust the size of the APC cache to fit what you've decided

Cached files: = 1280 (125.5

Peter Bowey's picture

Cached files: = 1280 (125.5 MBytes)

and you have only allocated 128M!

Free Memory: 1015.3 KBytes (0.8%)

You need to increase the apc.shm_size
or limit the number of files cached!

--
Linux: Web Developer
Peter Bowey Computer Solutions
Australia: GMT+9:30
(¯`·..·[ Peter ]·..·´¯)

sym links

John_B's picture

With multiple sites but not multi-sites, you might cut down on the memory required to cache opcode by replacing shared Drupal code in in all but one site with symlinks to the same code in one site.

Memory

Sarah Thornton's picture

Good trick, load the devel module and look at the amount of memory a page can take up, use the largest page as a rough guide as to how much memory to allocate to APC as a minimum.