You are browsing a read-only backup copy of Wikitech. The primary site can be found at

Memcached: Difference between revisions

From Wikitech-static
Jump to navigation Jump to search
(→‎Mcrouter: add "read more" reference for mcrouter)
(Krinkle moved page Memcached to Memcached for MediaWiki)
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{warning|1= This page is under construction, please be patient :)}}
#REDIRECT [[Memcached for MediaWiki]]
[ Memcached] is deployed in several clusters on our infrastructure:
* MediaWiki Object Cache (mc10XX, mc20XX)
* Thumbor
* Wikitech on Cloud/Labs
* Swift
This page contains information about the MediaWiki Object cache, running on mc10XX hosts (in eqiad) and mc20XX hosts (in codfw).
== MediaWiki libraries/support ==
{{Navigation Wikimedia infrastructure|expand=mw}}
The Memcache setup changed in 2015 to be multi-datacenter aware. See also:
* [[mw:Manual:WANObjectCache.php]]
*<s>[[nutcracker]] (memcached proxy on all application servers)</s> (deprecated as of March 2019)
*[[Mcrouter]] (memcached proxy on all application servers)
=== WANObjectCache ===
==== WANCache✌️global:SqlBlobStore-blob:<wiki>:<content address> ====
When you have issues with a key from SqlBlobStore-blob it is possible to figure out which page this key is for, but the process takes a while.
You will want to run these queries on the analytics DB replicas to avoid impacting production.
addshore@stat1007:~$ analytics-mysql enwiki
mysql:research@dbstore1003.eqiad.wmnet [enwiki]> select * from content where content_address = "tt:963546992";
| content_id | content_size | content_sha1                    | content_model | content_address |
|  943285896 |      186750 | 17ti8zx1nn1o0u381j04ctr9nfjwvis |            3 | tt:963546992    |
1 row in set (14 min 34.84 sec)
mysql:research@dbstore1003.eqiad.wmnet [enwiki]> select * from slots where slot_content_id = 943285896;
| slot_revision_id | slot_role_id | slot_content_id | slot_origin |
|        951705319 |            1 |      943285896 |  951705319 |
1 row in set (7 min 26.09 sec)
Then you can navigate to the revision id
=== Mcrouter ===
Each MediaWiki api/appserver sees memcached through a local proxy called [[Mcrouter]]<ref>[ Introducing mcrouter: A memcached protocol router for scaling memcached deployments]</ref>. This daemon is configured with all the mc[1,2]0XX hosts as shards, and applies consistent hashing on the key name to know where to store it. The following example should help clarifying how things flow on this layer.
The MediaWiki translate extension stores the key WANCache:v:metawiki:translate-groups in memcached, using the WANObjectCache as library. For example, a GET command to retrieve the key's value is sent from MediaWiki to localhost:11213, where mcrouter is listening, and the command gets routed to mc1022. MediaWiki it totally ignorant about the mc[1,2]0XX host, it only knows about sending commands to a localhost port. A mcrouter admin command helps figure out where the key gets routed:<syntaxhighlight lang="bash">
elukey@mw1345:~$ echo "get __mcrouter__.route(get,WANCache:v:metawiki:translate-groups)" | nc localhost 11213 -q 2
VALUE __mcrouter__.route(get,WANCache:v:metawiki:translate-groups) 0 16
elukey@mw1345:~$ dig -x +short
</syntaxhighlight>Some things to notice:
* The special prefix __mcrouter__.route is interpreted by mcrouter as admin command, that in this case returns the proxy target of the consistent hashing of the key name.
* mcrouter listen on port 11213 on every MediaWiki hosts, meanwhile on every mc10XX host memcached listens on 11211.
To get a key and dump it to a file it is sufficient to:<syntaxhighlight lang="bash">
elukey@mw1345:~$ echo "get WANCache:v:metawiki:translate-groups" | nc localhost 11213 -q 2 > dump.txt
elukey@mw1345:~$ du -hs dump.txt
380K dump.txt
</syntaxhighlight>In this case the key's value is pretty big, and it needs PHP to be interpreted correctly (to unserialize it), but nonetheless we got some useful information (like the size of the key). This could be useful when it is necessary to quickly get how big a key is, rather than knowing its content.
== How Memcached works ==
[[Category:MediaWiki production]]

Latest revision as of 23:46, 27 July 2020