Same cache is called on every request, or nearly every request, so a good candidate for the new cache_bootstrap bin.

Comments

catch’s picture

StatusFileSize
new931 bytes

Argh, wrong patch.

yched’s picture

Does this apply to _field_info_collate_fields() and _field_info_collate_types() as well ?

catch’s picture

StatusFileSize
new1.96 KB

I think it does.

yched’s picture

and _field_info_collate_fields() ? ;-)

catch’s picture

Title: Use cache_bootstrap for entity_get_info() » Use cache_bootstrap for entity and field info
StatusFileSize
new2.8 KB

If you insist :)

catch’s picture

dries’s picture

But where do we draw the line? If it is called on almost every request, it might harm the requests it is not called on?

The name cache_boostrap suggests that it should be called as part of the bootstrap process?

catch’s picture

I don't think we need to be so strict as to say you can only put thing in here which are 100% necessary to bootstrap Drupal to DRUPAL_BOOTSTRAP_FULL, or at least that wasn't my intention in the original patch. I originally wanted to call the bin cache_local, but that would've been too tied to using it with shared memory. However you can slightly stretch the definition of 'bootstrap' to include the bootstrapping of particular APIs when they're invoked - i.e. any request to the field API or entity API requires these specific caches.

We're never going to load stuff from cache_bootstrap that's not needed for a request, so the only implication for putting things in here which aren't 100% necessary for bootstrap is storage, and the additional impact of cache misses when that cache needs to be rebuilt per-web head. IMO the entity and field info caches are sufficiently low level, and infrequently rebuilt, that they're good candidates.

Either way this has to be done case by case - I think the menu router cache is also requested every request, but menu rebuilds and caching is quite expensive and frequent, so that might not be a good candidate.

yched’s picture

Dries, it seems you committed the field.info.inc part of this along with http://drupal.org/cvs?commit=288558

yched’s picture

Priority: Normal » Critical

Er, which means HEAD is broken because the patch had

+    cache_clear_all('field_info_fields', 'cache_field_bootstrap');

(instead of 'cache_bootstrap'), and cache_field_bootstrap table doesn't exist.

catch’s picture

StatusFileSize
new1.89 KB

Rollback

dries’s picture

Rolled back. Thanks!

yched’s picture

Priority: Critical » Normal

Thks :-). back to 'normal', then.

Status: Needs review » Needs work

The last submitted patch failed testing.

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new2.79 KB

Minus typo this time.

Status: Needs review » Needs work

The last submitted patch failed testing.

yched’s picture

Status: Needs work » Reviewed & tested by the community

I'll add that it only makes sense to cache field meta data (set of available [field|widget|formatter] types, set of actual field and instance definitions) in a different table than the one used for field values cache.

catch’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new5.77 KB

Not my day today, field tests pass locally with this one.

chx’s picture

There is indeed a balance to be made. The typical scenario is that you will have N webfrontends which will put cache_bootstrap in shared memory (apc/xcache variables, System V shm, black magic, whatever). Now, shared memory suffers from some problems: size as one segment is, by default is 32MB (on Linux and FreeBSD). Of course, you might have more than one segment but for some reason apc.shm_segments defaults to 1 so I have a bad suspicion that there are some (serious) disadvantage to several segments. As a working hypothesis, let's accept that 32MB is what we can work with. I will ask about the disadvantages of raising apc.shm_segments.

In that 32MB you need to stuff your op cache and cache_bootstrap. In other words, given the code size of Drupal, you better think twice when stuffing a complicated structure in cache_bootstrap. It's a great idea and very very useful but be careful. Menu was already raised and I would object that severely, for example. How big is this entity info your try to stuff in?

chx’s picture

Note that APC supports an MMAP mode where apc.shm_segments are disregarded and the shmmax is not in play at all so at least with APC the size is not a problem . However, explaining someone that in order to use cache_bootstrap efficiently, she might need to recompile APC with --enable-apc-mmap and change configuration to be able to raise the memory accessible to APC, that's fun.

catch’s picture

Entity info is one array for each defined entity, I can't see it being more than 1k or so. For comparison, I have a D6 site with over 1200 entries in the variables table, and that whole table in memory is 100k.

chx’s picture

Then that's good. It was worth a few followups to show we thought of this.

yched’s picture

Field types info amounts to 13k with core field types and widgets. This should reasonably reach at most 50k-100k with contrib field types.
Field definitions size growth is a little harder to predict. On my setup (9 fields, 15 instances), this amounts to 19k. At this rate, 100 fields and 200 instances would roughly raise to something like 250k.

R.Muilwijk’s picture

StatusFileSize
new2.76 KB

+1 for me!

Attached is a new patch which applies. Alot of the previous touched files do not need any patch anymore because a function has been added to common.inc:6374 to clear the cache.

/**
 * Resets the cached information about entity types.
 */
function entity_info_cache_clear() {
  drupal_static_reset('entity_get_info');
  cache_clear_all('entity_info', 'cache_bootstrap');
}
yched’s picture

Status: Needs review » Needs work

rdf.test still has

cache_clear_all('entity_info', 'cache');

Other than that, this can bet set back to RTBC, as per #21.

R.Muilwijk’s picture

Status: Needs work » Needs review
StatusFileSize
new3.51 KB

Hmmz that got in with a recent commit I guess... or just missed it. New patch attached.

raymond@raymond-laptop:/srv/drupal/drupal$ grep -r "'entity_info'" *
includes/common.inc:    $drupal_static_fast['entity_info'] = &drupal_static(__FUNCTION__);
includes/common.inc:  $entity_info = &$drupal_static_fast['entity_info'];
includes/common.inc:    if ($cache = cache_get('entity_info', 'cache_bootstrap')) {
includes/common.inc:      $entity_info = module_invoke_all('entity_info');
includes/common.inc:      drupal_alter('entity_info', $entity_info);
includes/common.inc:      cache_set('entity_info', $entity_info, 'cache_bootstrap');
includes/common.inc:  cache_clear_all('entity_info', 'cache_bootstrap');
raymond@raymond-laptop:/srv/drupal/drupal$ grep -r "'field_info_fields'" *
modules/field/field.info.inc:    cache_clear_all('field_info_fields', 'cache_bootstrap');
modules/field/field.info.inc:    if ($cached = cache_get('field_info_fields', 'cache_bootstrap')) {
modules/field/field.info.inc:      cache_set('field_info_fields', $definitions, 'cache_bootstrap');
yched’s picture

Status: Needs review » Reviewed & tested by the community

Thx !

catch’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

Now this is cached per language, I think this is won't fix.

R.Muilwijk’s picture

The change catch mentioned can be found in http://drupal.org/node/503550. I still would like to have a look into this. cache_field is not likely to be cached in APC on every webnode. So it could still be a good change to move 'field_info_types' to a different bin then 'cache_field'.