Problem/Motivation

memcache stampede protection allows to serve expired cache entries in order to avoid locking
to many processes at the same time.

The first process which tries to retrieve the cache entry therefore then creates a lock and does not retrieve a cache entry.
Most of the usages of cache entries then will recalculate the value and call cache_set(), which releases the lock for that
particular entry.
Sadly exceptions confirm the rule, so that some examples just calculate the value,
but don't set the cache entries. For those entries the cache_set
is done later, for example on __destruct or KernelEvents::Terminate (D8)

Proposed resolution

Allow to opt out of stampede protected for particular cache bins/cids.

Remaining tasks

User interface changes

API changes

Comments

dawehner’s picture

Issue summary: View changes
dawehner’s picture

Status: Active » Needs review
StatusFileSize
new6.84 KB

Initial implementation.

fabianx’s picture

Status: Needs review » Reviewed & tested by the community

Fantastic patch!

Even has really nice tests. RTBC.

jeremy’s picture

Status: Reviewed & tested by the community » Needs work

It sounds like we should default to disabling stampede protection for everything in your documented example? Is there any reason we'd not want to default to disabling these bins and cids?

jeremy’s picture

Issue tags: +7.x-1.4 blocker
fabianx’s picture

Yes, that would be variables / module_implements for bootstrap and i18n - though I have to look up the actual prefix.

However cache_render was _just_ an example ...

fabianx’s picture

So lets remove cache_render and use 'i18n:string:*' as the defaults here.

Proposal:

Add the defaults to a $defaults class variable as a const (or any better place), use this as the default in variable_get and we should be good here.

Lets however document both use-cases (if not done already):

- a) variables has their own lock protection, which memcache protection interferes with

- b) module_implements is written just at the end of the request, which can be lengthy.
- b) i18n just writes on class destruction, which can also be the end of the request

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new7.22 KB
new1.61 KB

It sounds like we should default to disabling stampede protection for everything in your documented example? Is there any reason we'd not want to default to disabling these bins and cids?

Nice idea!

- b) i18n just writes on class destruction, which can also be the end of the request

... I wonder whether

Given that this variable is just used in a single place, I went with keeping it inline.

Let's keep the documentation in README.txt a bit more generic and explain the actual individual cases inline.

fabianx’s picture

Status: Needs review » Needs work
  1. +++ b/README.txt
    @@ -141,16 +141,14 @@ drupal_page_footer()/module_implements_write_cache(). Allow to disable the
       $conf['memcache_stampede_protection_ignore'] = array(
    -    // Ignore the entire cache_render bin.
    -    'cache_render',
         // Ignore some CIDs of cache_bootstrap.
    

    Lets keep an example, please, but lets use:

    cache_foo

    to clearly mark it as an example and not a recommendation.

  2. +++ b/memcache.inc
    @@ -495,7 +495,20 @@ class MemCacheDrupal implements DrupalCacheInterface {
    +        // Variables have their own protection.
    +        'variables'
    

    ... their own lock protection

  3. +++ b/memcache.inc
    @@ -495,7 +495,20 @@ class MemCacheDrupal implements DrupalCacheInterface {
    +        // I18n is a class destructor to write the cache.
    

    uses a class destructor

Some nits, then back to RTBC

dawehner’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.16 KB
new7.32 KB

Some nits, then back to RTBC

But fair ones.

fabianx’s picture

RTBC + 1

  • Jeremy committed e4b67a0 on 7.x-1.x
    Issue #2377587: by dawehner, Fabianx, Jeremy: disable stampede...
jeremy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for your excellent work on this!

I rewrote the README explanation to try and make it clearer, and the inline documentation to conform to the standards in the rest of the module. I also added more useful output for the tests so it's easier to understand what's being tested.

Committed:
http://cgit.drupalcode.org/memcache/commit/?id=e4b67a0

fabianx’s picture

Is it worth to set this to backport?

jeremy’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Fixed » Patch (to be ported)

Sure, patch welcome :)

  • Jeremy committed 9b17152 on 6.x-1.x
    Issue #2377587 allow configurable disabling of stampede protection,...
jeremy’s picture

Status: Patch (to be ported) » Fixed
Issue tags: -7.x-1.4 blocker

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.