Page MenuHomePhabricator

WANObjectCache: Document how lockTSE works (and what the abbrevation stands for)
Closed, ResolvedPublic

Description

Someone asked me what lockTSE does, and it ocurred to me that the high-level idea is not explained anywhere from what I could find. This should probably be added to the class docs somewhere, or as part of a larger Markdown file if/when we have one indexed in Doxygen for WANObjectCache.

Here's what I wrote ad-hoc to explain it, which might be of use:

Krinkle wrote:

The general idea behind lockTSE is to avoid stampedes on busy keys.

The main idiom for WANcache is WANObjectCache::getWithSet(key, ttl, callback[, options]).
Generally, if a value has expired, the callback is used to recompute the value, store it, and return it to the caller.

When lockTSE'is enabled, and the Memcached value has expired, WANObjectCache will first check and try to acquire a cluster-wide mutex lock via a Memcached. If another web request somewhere is also in this code path right now and is already regenerating the value as we speak, then the lockTSE option means the current request will not get a lock and thus return the known-expired value instead (unless it is both generally expired and older than the allowed staless, through the number of seconds passed via the lockTSE option).

This is similar in vein to how PoolCounter mitigates the "Michael Jackson effect" on the critical path around parsing of wiki pages, but applied more generally to small and medium size cache computations stored in Memchached.

Note: WANcache's TSE lock is cluster-wide within the DC, thus global for most intents and purposes, but truely global across DCs. It's a best-effort optimization, not a functional/logical requirement or guarantee of non-concurrency.

Ref:


Krinkle wrote:

I believe it stands for time-since-expiry,
which seems to have fallen off the documentation, but was mentioned in an earlier version of code.

https://github.com/wikimedia/mediawiki/commit/1ed292fa9ed97d72fb8412bc18b393e6a9f758e7

Event Timeline

Change 654509 had a related patch set uploaded (by Aaron Schulz; owner: Aaron Schulz):
[mediawiki/core@master] objectcache: improve "lockTSE" comments in WANObjectCache

https://gerrit.wikimedia.org/r/654509

Change 654509 merged by jenkins-bot:
[mediawiki/core@master] objectcache: improve "lockTSE" comments in WANObjectCache

https://gerrit.wikimedia.org/r/654509

Krinkle assigned this task to aaron.
Krinkle edited projects, added Performance-Team; removed Patch-For-Review.
Krinkle moved this task from Library to libs/objectcache on the MediaWiki-libs-ObjectCache board.