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
Comment #1
dawehnerComment #2
dawehnerInitial implementation.
Comment #3
fabianx commentedFantastic patch!
Even has really nice tests. RTBC.
Comment #4
jeremy commentedIt 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?
Comment #5
jeremy commentedComment #6
fabianx commentedYes, 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 ...
Comment #7
fabianx commentedSo 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
Comment #8
dawehnerNice idea!
... 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.
Comment #9
fabianx commentedLets keep an example, please, but lets use:
cache_foo
to clearly mark it as an example and not a recommendation.
... their own lock protection
uses a class destructor
Some nits, then back to RTBC
Comment #10
dawehnerBut fair ones.
Comment #11
fabianx commentedRTBC + 1
Comment #13
jeremy commentedThanks 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
Comment #14
fabianx commentedIs it worth to set this to backport?
Comment #15
jeremy commentedSure, patch welcome :)
Comment #17
jeremy commentedBackported, committed:
http://cgit.drupalcode.org/memcache/commit/?id=9b17152