$conf['cache_default_class'] = 'MemCacheDrupal';
$conf['cache_default_class'] = 'DrupalAPCCache';

For $conf['cache_backends'] I turned it into array with [] - how about this one?

Comments

Phizes’s picture

Status: Active » Closed (fixed)

$conf['cache_default_class'] defines the default class to use for caching, your configuration above would not cause problems as $conf['cache_default_class'] = 'MemCacheDrupal'; would be overwritten by $conf['cache_default_class'] = 'DrupalAPCCache'; and DrupalAPCCache will be the class used for caching for any cache which is not specifically set to a different class. I'm guessing this is not what you want though.

You can only have one default cache class. $conf['cache_backends'][] can have multiple entries as it lists all the available include files from which you can define a cache class.

You can specify a class on a cache by cache basis like so, using the Drupal database cache, and cache for as an example: $conf['cache_class_cache_form'] = 'DrupalDatabaseCache';

Anonymous’s picture

Yes, I'm actually not sure if it's what I want.. Shouldn't APC function without a cache_default_class set? I have already included the cache backend for it.

Anyways, the reason I asked is that I've seen some very inconsistent results when the APC module is enabled and/or Varnish. drupal_get_form for a profile2 form is semi-cached when I don't want it to be (old values sometimes display), rules break down (entity not found/variables empty), different roles get different cache results, errors after turning on/off modules, user pictures printing wrong older pictures and so on. Anything that could be fixed easily do you think as I'm at a loss with the module unfortunately (server APC works fine though).

My settings.php with all three enabled would be:

$conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc';
$conf['cache_default_class'] = 'MemCacheDrupal';
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';

// Add Varnish as the page cache handler.
$conf['cache_backends'][] = 'sites/all/modules/varnish/varnish.cache.inc';
$conf['cache_class_cache_page'] = 'VarnishCache';
// Drupal 7 does not cache pages when we invoke hooks during bootstrap.
// This needs to be disabled.
$conf['page_cache_invoke_hooks'] = FALSE;

/**
* Add APC Caching.
*/
$conf['cache_backends'][] = 'sites/all/modules/apc/drupal_apc_cache.inc';
$conf['cache_default_class'] = 'DrupalAPCCache';
//$conf['apc_show_debug'] = TRUE; // Remove the slashes to use debug mode.

Phizes’s picture

You can only set $conf['cache_default_class'] once, either you choose APC for your default cache class or you choose Memcache, currently you are using APC as your default class.

The default class is like the 'fallback' for when a cache does not have a particular cache class assigned to it.

I think the things that you should check are 1) is APC getting badly fragmented 2) Is APC running out of memory and having to dump cached data

Things you need to do are 1) Decide whether to use DrupalAPCCache or MemCacheDrupal as your default cache class, you can only choose one, currently you are assigning first Memcache, then APC so APC is currently your default cache 2) Choose which cache bins go to Memcache, and which ones go to APC and assign the individual bins accordingly. Make sure neither run out of memory.

I'm quite certain that your APC cache is running out of memory and/or very, very fragmented, do you have the apc.php status file that comes with apc setup? If so check the cache expunge rate is not high, ideally it should not expunge at all, check that your cache full count is 0 and check the fragmentation/number of graph bits aren't too many.

I would go through the following steps: 1) Disable all cache backends except for default Drupal 2) Check that the APC cache is not getting full while just caching files, if it is, you will need to increase the amount of memory 3) Enable APC Drupal module to cache small caches such as cache, cache_bootstrap, do not set it as the default cache class, keep cache_form, and cache_update in the database 4) Check that APC is not running out of memory and that everything functions correctly 5) Enable Memcache and configure it, I prefer to use one memcache instance for all the bins, set it as the default cache class 6) Check that nothing is running out of memory and that your site functions correctly. 7) Lastly add varnish back into the mix and set it up.

By breaking everything into steps and adding one caching method at a time you can pinpoint your problem, if it is indeed a problem with caching.

Alternatively, you can choose to disable either Memcache or APC for Drupal caching purposes, and just use one of them, I just use Memcache. Keep in mind even if you disable the APC drupal module, your files will still be cached by APC, which is good.

Phizes’s picture

Status: Closed (fixed) » Active
Anonymous’s picture

Hi Phizes,

Thanks for the detailed reply! I've set my memory limit for APC to 256MB, stats are:

Hits: 2910769 (100.0%)
Misses: 1438 (0.0%)
Used: 118.8 MBytes (46.4%)
Free: 137.2 MBytes (53.6%)
Fragmentation: 6.72% ( 9.2 MBytes out of 137.2 MBytes in 362 fragments)

Cache full count is 0.
Max file size is 1M.
apc.ttl 7200
apc.num_files_hint 1024 (I notice 1383 entries though do I need to increase this?)
apc.gc_ttl 3600

Most of the files seem to be created like two days ago 2012/10/02 07:02:00
There are quite a few lines on those pie and bar charts :) Would that mean its too fragmented?

BTW, my memcache is set to 512mb, though when I check the report in Drupal, it seems only like 8-10mb is used - site is still in development with not many other users. Is this correct? Would usage be higher with more users or roughly the same? Sessions are not being cached by memcache.

I suppose just using APC without the module will be good enough for now though but would be good to diagnose the problem.. Perhaps the cache bins need to be set properly like you say..

Phizes’s picture

APC statistics seem to be fine, you do need to diagnose that problem though. Personally, I found that using the APC module (and therefore the APC user cache) while doing development work led to the APC cache getting very fragmented from all the cache clearing of the user cache which caused me more grief. With about half your cache used I'm not sure if the amount of fragmentation you have would be a problem but I'm pedantic towards fragmentation and try to keep it to less than about 10 - 20 fragments, while you have 362 fragments. One of the maintainers of an APC module told me that it should no longer be a problem with more recent versions of the APC extension, so I guess YMMV.

I'm not sure on the effects of the APC file hints setting, the documentation says it helps APC optimize hash tables, so I would increase it to be a little larger than the maximum amount of files which get cached.

I found my Memcached instances grew quite a bit larger in production, but I guess it depends on your specific use case, I mean we have a really simple site that's only anonymous traffic and it never goes above 2 - 3 megabytes with page caching, but there are only around 14 pages currently. It just depends on how much Drupal can actually cache, and it would get larger as more content is added due to the field cache, for example.

If you are still running into problems with forms, and the forms are kept in the database, your problem quite possibly lies elsewhere.

When you do get sorted out, could you please mark the issue as fixed? I'm trying to help clear up issue queues where possible. :)

R.Muilwijk’s picture

Status: Active » Closed (works as designed)