Memcached

From Freephile Wiki
Revision as of 13:32, 20 March 2024 by Admin (talk | contribs)
Jump to navigation Jump to search

Memcached is a BSD licensed, high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering. See the Caching Story that explains how every web application eventually turns to caching to increase performance.

See Also:

Try

echo stats | nc 127.0.0.1 11211

"Cache is King" - borrowed from the aphorism "Cash is King" For a full exploration of object caching in MediaWiki see https://www.mediawiki.org/wiki/Object_cache

Making cache scalable[edit | edit source]

MediaWiki connects to memcached through a proxy called McRouter (Mick-ROW-ter) [1] Mcrouter was developed by Meta engineering back in 2014 for scaling memcached deployments [2]. It's a core component of cache infrastructure at Facebook and Instagram where mcrouter handles almost 5 billion requests per second at peak.

Because the routing and feature logic are abstracted from the client in mcrouter deployments, the client may simply communicate with destination hosts through mcrouter over a TCP connection using standard memcached protocol. Typically, little or no client modification is needed to use mcrouter, which was designed to be a drop-in proxy between the client and memcached hosts.

Mcrouter supports typical memcache protocol commands like get, set, delete, etc. and specific commands to access stats, version and so on.[3]

MediaWiki Interfaces[edit | edit source]

WANObjectCache (or WANCache) is the primary interface in MediaWiki for interacting with Memcached and mcrouter. As the name implies, WANObjectCache is a multi-datacenter aware caching interface. See the class docs for more detail on using and deploying WANObjectCache. Source in Gerrit includes a README describing stats that go into StatsD

Aside: WANObjectCache can also be deployed using Dynomite as the intermediary - to use Amazon's Dynamo cache in a distributed way. See the 2007 whitepaper for details on Amazon's Dynamo.

If you are a MediaWiki developer - especially a front-end dev, you've probably seen references in code to the 'BagOStuff' and wondered "what the heck is it?" BagOStuff is an abstract Class representing a cache/ephemeral data store. Concrete classes then build upon or implement BagOStuff in ways that are compatible with those concrete storage mechanisms. [4] WANCache builds on top of BagOStuff, which is the lower level key-value interface to Memcached and other storage backends.

illustration of Memcached flow from MediaWiki

References[edit source]