Difference between revisions of "MemCached.doc (MediaWiki)"
m (navbar template) |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | {{mediawiki dev doc|MemCached.doc}} | |
− | |||
− | |||
==Text== | ==Text== | ||
− | ===memcached support for MediaWiki=== From ca August 2003, MediaWiki | + | ===memcached support for MediaWiki=== |
− | has optional support for memcached, a "high-performance, distributed | + | From ca August 2003, MediaWiki has optional support for memcached, a "high-performance, distributed memory object caching system". For general information on it, see: http://www.danga.com/memcached/ |
− | memory object caching system". For general information on it, see: | + | |
− | http://www.danga.com/memcached/ Memcached is likely more trouble than a | + | Memcached is likely more trouble than a small site will need, but for a larger site with heavy load, like Wikipedia, it should help lighten the load on the database servers by caching data and objects in memory. |
− | small site will need, but for a larger site with heavy load, like | + | ====Requirements==== |
− | Wikipedia, it should help lighten the load on the database servers by | + | * PHP must be compiled with --enable-sockets |
− | caching data and objects in memory. ====Requirements==== * PHP must be | + | * libevent: http://www.monkey.org/~provos/libevent/ |
− | compiled with --enable-sockets * libevent: | + | *:(as of 2003-08-11, 0.7a is current) |
− | http://www.monkey.org/~provos/libevent/ *:(as of 2003-08-11, 0.7a is | + | * optionally, epoll-rt patch for Linux kernel: |
− | current) * optionally, epoll-rt patch for Linux kernel: | + | *:http://www.xmailserver.org/linux-patches/nio-improve.html |
− | *:http://www.xmailserver.org/linux-patches/nio-improve.html * | + | * memcached: http://www.danga.com/memcached/download.bml |
− | memcached: http://www.danga.com/memcached/download.bml *:(as of this | + | *:(as of this writing, 1.1.9 is current) |
− | writing, 1.1.9 is current) Memcached and libevent are under BSD-style | + | |
− | licenses. The server should run on Linux and other Unix-like systems... | + | Memcached and libevent are under BSD-style licenses. |
− | you can run multiple servers on one machine or on multiple machines on | + | |
− | a network; storage can be distributed across multiple servers, and | + | The server should run on Linux and other Unix-like systems... you can run multiple servers on one machine or on multiple machines on a network; storage can be distributed across multiple servers, and multiple web servers can use the same cache cluster. |
− | multiple web servers can use the same cache cluster. | + | |
+ | |||
<center><nowiki> | <center><nowiki> | ||
− | ********************* W A R N I N G ! ! ! ! ! *********************** | + | ********************* W A R N I N G ! ! ! ! ! *********************** |
</nowiki></center> | </nowiki></center> | ||
− | Memcached has no security or authentication. Please ensure that your | + | Memcached has no security or authentication. Please ensure that your server is appropriately firewalled, and that the port(s) used for memcached servers are not publicly accessible. Otherwise, anyone on the internet can put data into and read data from your cache. |
− | server is appropriately firewalled, and that the port(s) used for | + | |
− | memcached servers are not publicly accessible. Otherwise, anyone on the | + | An attacker familiar with MediaWiki internals could use this to give themselves developer access and delete all data from the wiki's database, as well as getting all users' password hashes and e-mail addresses. |
− | internet can put data into and read data from your cache. An attacker | ||
− | familiar with MediaWiki internals could use this to give themselves | ||
− | developer access and delete all data from the wiki's database, as well | ||
− | as getting all users' password hashes and e-mail addresses. | ||
<center><nowiki> | <center><nowiki> | ||
− | ********************* W A R N I N G ! ! ! ! ! *********************** | + | ********************* W A R N I N G ! ! ! ! ! *********************** |
− | </nowiki></center> ====Setup==== | + | </nowiki></center> |
− | If you want to start small, just run one memcached on your web server: | + | |
− | memcached -d -l 127.0.0.1 -p 11000 -m 64 (to run in daemon mode, | + | ====Setup==== |
− | accessible only via loopback interface, on port 11000, using up to 64MB | + | If you want to start small, just run one memcached on your web server: |
− | of memory) In your LocalSettings.php file, set: $wgUseMemCached = true; | + | |
− | $wgMemCachedServers = array( "127.0.0.1:11000" ); The wiki should then | + | memcached -d -l 127.0.0.1 -p 11000 -m 64 |
− | use memcached to cache various data. To use multiple servers | + | (to run in daemon mode, accessible only via loopback interface, on port 11000, using up to 64MB of memory) |
− | (physically separate boxes or multiple caches on one machine on a | + | |
− | large-memory x86 box), just add more items to the array. To increase | + | In your LocalSettings.php file, set: |
− | the weight of a server (say, because it has twice the memory of the | + | |
− | others and you want to spread usage evenly), make its entry a subarray: | + | $wgUseMemCached = true; |
− | + | $wgMemCachedServers = array( "127.0.0.1:11000" ); | |
− | + | The wiki should then use memcached to cache various data. To use multiple servers (physically separate boxes or multiple caches on one machine on a large-memory x86 box), just add more items to the array. To increase the weight of a server (say, because it has twice the memory of the others and you want to spread usage evenly), make its entry a subarray: | |
− | + | ||
− | + | NaodW29-pre314ba41d77a1ba100000001 | |
− | As of this writing, MediaWiki includes version 1.0.10 of the PHP | + | |
− | memcached client by Ryan Gilfether <hotrodder@rocketmail.com>. | + | ====PHP client for memcached==== |
− | You'll find some documentation for it in the 'php-memcached' | + | As of this writing, MediaWiki includes version 1.0.10 of the PHP memcached client by Ryan Gilfether <hotrodder@rocketmail.com>. You'll find some documentation for it in the 'php-memcached' subdirectory under the present one. |
− | subdirectory under the present one. We intend to track updates, but if | + | |
− | you want to check for the lastest released version, see | + | We intend to track updates, but if you want to check for the lastest released version, see http://www.danga.com/memcached/apis.bml |
− | http://www.danga.com/memcached/apis.bml If you don't set | + | |
− | $wgUseMemCached, we still create a MemCacheClient, but requests to it | + | If you don't set $wgUseMemCached, we still create a MemCacheClient, but requests to it are no-ops and we always fall through to the database. If the cache daemon can't be contacted, it should also disable itself fairly smoothly. |
− | are no-ops and we always fall through to the database. If the cache | + | |
− | daemon can't be contacted, it should also disable itself fairly | + | ====Keys used==== |
− | smoothly. ====Keys used==== | + | *User: |
− | *User: *:key: $wgDBname:user:id:$sId *:ex: wikidb:user:id:51 *:stores: | + | *:key: $wgDBname:user:id:$sId |
− | instance of class User *:set in: User::loadFromSession() *:cleared by: | + | *:ex: wikidb:user:id:51 |
− | User::saveSettings(), UserTalkUpdate::doUpdate() *Newtalk: *:key: | + | *:stores: instance of class User |
− | $wgDBname:newtalk:ip:$ip *:ex: wikidb:newtalk:ip:123.45.67.89 *:stores: | + | *:set in: User::loadFromSession() |
− | integer, 0 or 1 *:set in: User::loadFromDatabase() *:cleared by: | + | *:cleared by: User::saveSettings(), UserTalkUpdate::doUpdate() |
− | User::saveSettings() # ? *:expiry set to 30 minutes *LinkCache: *:key: | + | |
− | $wgDBname:lc:title:$title *:ex: | + | *Newtalk: |
− | wikidb:lc:title:Wikipedia:Welcome,_Newcomers! *:stores: cur_id of page, | + | *:key: $wgDBname:newtalk:ip:$ip |
− | or 0 if page does not exist *:set in: LinkCache::addLink() | + | *:ex: wikidb:newtalk:ip:123.45.67.89 |
+ | *:stores: integer, 0 or 1 | ||
+ | *:set in: User::loadFromDatabase() | ||
+ | *:cleared by: User::saveSettings() # ? | ||
+ | *:expiry set to 30 minutes | ||
+ | |||
+ | *LinkCache: | ||
+ | *:key: $wgDBname:lc:title:$title | ||
+ | *:ex: wikidb:lc:title:Wikipedia:Welcome,_Newcomers! | ||
+ | *:stores: cur_id of page, or 0 if page does not exist | ||
+ | *:set in: LinkCache::addLink() | ||
*:cleared by: LinkCache::clearBadLink() | *:cleared by: LinkCache::clearBadLink() | ||
*::should be cleared on page deletion and rename | *::should be cleared on page deletion and rename |
Latest revision as of 16:00, 7 December 2005
Text
memcached support for MediaWiki
From ca August 2003, MediaWiki has optional support for memcached, a "high-performance, distributed memory object caching system". For general information on it, see: http://www.danga.com/memcached/
Memcached is likely more trouble than a small site will need, but for a larger site with heavy load, like Wikipedia, it should help lighten the load on the database servers by caching data and objects in memory.
Requirements
- PHP must be compiled with --enable-sockets
- libevent: http://www.monkey.org/~provos/libevent/
- (as of 2003-08-11, 0.7a is current)
- optionally, epoll-rt patch for Linux kernel:
- memcached: http://www.danga.com/memcached/download.bml
- (as of this writing, 1.1.9 is current)
Memcached and libevent are under BSD-style licenses.
The server should run on Linux and other Unix-like systems... you can run multiple servers on one machine or on multiple machines on a network; storage can be distributed across multiple servers, and multiple web servers can use the same cache cluster.
Memcached has no security or authentication. Please ensure that your server is appropriately firewalled, and that the port(s) used for memcached servers are not publicly accessible. Otherwise, anyone on the internet can put data into and read data from your cache.
An attacker familiar with MediaWiki internals could use this to give themselves developer access and delete all data from the wiki's database, as well as getting all users' password hashes and e-mail addresses.
Setup
If you want to start small, just run one memcached on your web server:
memcached -d -l 127.0.0.1 -p 11000 -m 64
(to run in daemon mode, accessible only via loopback interface, on port 11000, using up to 64MB of memory)
In your LocalSettings.php file, set:
$wgUseMemCached = true; $wgMemCachedServers = array( "127.0.0.1:11000" );
The wiki should then use memcached to cache various data. To use multiple servers (physically separate boxes or multiple caches on one machine on a large-memory x86 box), just add more items to the array. To increase the weight of a server (say, because it has twice the memory of the others and you want to spread usage evenly), make its entry a subarray:
NaodW29-pre314ba41d77a1ba100000001
PHP client for memcached
As of this writing, MediaWiki includes version 1.0.10 of the PHP memcached client by Ryan Gilfether <hotrodder@rocketmail.com>. You'll find some documentation for it in the 'php-memcached' subdirectory under the present one.
We intend to track updates, but if you want to check for the lastest released version, see http://www.danga.com/memcached/apis.bml
If you don't set $wgUseMemCached, we still create a MemCacheClient, but requests to it are no-ops and we always fall through to the database. If the cache daemon can't be contacted, it should also disable itself fairly smoothly.
Keys used
- User:
- key: $wgDBname:user:id:$sId
- ex: wikidb:user:id:51
- stores: instance of class User
- set in: User::loadFromSession()
- cleared by: User::saveSettings(), UserTalkUpdate::doUpdate()
- Newtalk:
- key: $wgDBname:newtalk:ip:$ip
- ex: wikidb:newtalk:ip:123.45.67.89
- stores: integer, 0 or 1
- set in: User::loadFromDatabase()
- cleared by: User::saveSettings() # ?
- expiry set to 30 minutes
- LinkCache:
- key: $wgDBname:lc:title:$title
- ex: wikidb:lc:title:Wikipedia:Welcome,_Newcomers!
- stores: cur_id of page, or 0 if page does not exist
- set in: LinkCache::addLink()
- cleared by: LinkCache::clearBadLink()
- should be cleared on page deletion and rename
- MediaWiki namespace:
- key: $wgDBname:messages
- ex: wikidb:messages
- stores: an array where the keys are DB keys and the values are messages
- set in: wfMsg(), Article::editUpdates() both call wfLoadAllMessages()
- cleared by: nothing
- Watchlist:
- key: $wgDBname:watchlist:id:$userID
- ex: wikidb:watchlist:id:4635
- stores: HTML string
- cleared by: nothing, expiry time $wgWLCacheTimeout (1 hour)
- note: emergency optimisation only
- IP blocks:
- key: $wgDBname:ipblocks
- ex: wikidb:ipblocks
- stores: array of arrays, for the BlockCache class
- cleared by: BlockCache:clear()
... more to come ...
Edit Log
- 2005-06-13 Transcribed from docs for MediaWiki version 1.4.5