memcached.txt 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. MediaWiki has optional support for memcached, a "high-performance,
  2. distributed memory object caching system". For general information
  3. on it, see: http://www.danga.com/memcached/
  4. Memcached is likely more trouble than a small site will need, but
  5. for a larger site with heavy load, like Wikipedia, it should help
  6. lighten the load on the database servers by caching data and objects
  7. in memory.
  8. == Installation ==
  9. Packages are available for Fedora, Debian, Ubuntu and probably other
  10. Linux distributions. If there's no package available for your
  11. distribution, you can compile it from source.
  12. == Compilation ==
  13. * PHP must be compiled with --enable-sockets
  14. * libevent: http://www.monkey.org/~provos/libevent/
  15. (as of 2003-08-11, 0.7a is current)
  16. * optionally, epoll-rt patch for Linux kernel:
  17. http://www.xmailserver.org/linux-patches/nio-improve.html
  18. * memcached: http://www.danga.com/memcached/download.bml
  19. (as of this writing, 1.1.9 is current)
  20. Memcached and libevent are under BSD-style licenses.
  21. The server should run on Linux and other Unix-like systems... you
  22. can run multiple servers on one machine or on multiple machines on
  23. a network; storage can be distributed across multiple servers, and
  24. multiple web servers can use the same cache cluster.
  25. ********************* W A R N I N G ! ! ! ! ! ***********************
  26. Memcached has no security or authentication. Please ensure that your
  27. server is appropriately firewalled, and that the port(s) used for
  28. memcached servers are not publicly accessible. Otherwise, anyone on
  29. the internet can put data into and read data from your cache.
  30. An attacker familiar with MediaWiki internals could use this to steal
  31. passwords and email addresses, or to make themselves a sysop and
  32. install malicious javascript on the site. There may be other types
  33. of vulnerability, no audit has been done -- so be safe and keep it
  34. behind a firewall.
  35. ********************* W A R N I N G ! ! ! ! ! ***********************
  36. == Setup ==
  37. If you installed memcached using a distro, the daemon should be started
  38. automatically using /etc/init.d/memcached.
  39. To start the daemon manually, use something like:
  40. memcached -d -l 127.0.0.1 -p 11211 -m 64
  41. (to run in daemon mode, accessible only via loopback interface,
  42. on port 11211, using up to 64MB of memory)
  43. In your LocalSettings.php file, set:
  44. $wgMainCacheType = CACHE_MEMCACHED;
  45. $wgMemCachedServers = array( "127.0.0.1:11211" );
  46. The wiki should then use memcached to cache various data. To use
  47. multiple servers (physically separate boxes or multiple caches
  48. on one machine on a large-memory x86 box), just add more items
  49. to the array. To increase the weight of a server (say, because
  50. it has twice the memory of the others and you want to spread
  51. usage evenly), make its entry a subarray:
  52. $wgMemCachedServers = array(
  53. "127.0.0.1:11211", # one gig on this box
  54. array("192.168.0.1:11211", 2 ) # two gigs on the other box
  55. );
  56. == PHP client for memcached ==
  57. MediaWiki uses a fork of Ryan T. Dean's pure-PHP memcached client.
  58. It also supports the PECL PHP extension for memcached.
  59. MediaWiki uses the ObjectCache class to retrieve instances of
  60. BagOStuff by purpose, controlled by the following variables:
  61. * $wgMainCacheType
  62. * $wgParserCacheType
  63. * $wgMessageCacheType
  64. If you set one of these to CACHE_NONE, MediaWiki still creates a
  65. BagOStuff object, but calls it to it are no-ops. If the cache daemon
  66. can't be contacted, it should also disable itself fairly smoothly.
  67. == Keys used ==
  68. (incomplete, out of date)
  69. Date Formatter:
  70. key: $wgDBname:dateformatter
  71. ex: wikidb:dateformatter
  72. stores: a single instance of the DateFormatter class
  73. cleared by: nothing
  74. expiry: one hour
  75. Difference Engine:
  76. key: $wgDBname:diff:version:{MW_DIFF_VERSION}:oldid:$old:newid:$new
  77. ex: wikidb:diff:version:1.11a:oldid:1:newid:2
  78. stores: body of a difference
  79. cleared by: nothing
  80. expiry: one week
  81. Interwiki:
  82. key: $wgDBname:interwiki:$prefix
  83. ex: wikidb:interwiki:w
  84. stores: object from the interwiki table of the database
  85. expiry: $wgInterwikiExpiry
  86. cleared by: nothing
  87. Lag time of the databases:
  88. key: $wgDBname:lag_times
  89. ex: wikidb:lag_times
  90. stores: array mapping the database id to its lag time
  91. expiry: 5 secondes
  92. cleared by: nothing
  93. Localisation:
  94. key: $wgDBname:localisation:$lang
  95. ex: wikidb:localisation:de
  96. stores: array of localisation settings
  97. set in: Language::loadLocalisation()
  98. expiry: none
  99. cleared by: Language::loadLocalisation()
  100. Message Cache:
  101. backend: $wgMessageCacheType
  102. key: $wgDBname:messages, $wgDBname:messages-hash, $wgDBname:messages-status
  103. ex: wikidb:messages, wikidb:messages-hash, wikidb:messages-status
  104. stores: an array where the keys are DB keys and the values are messages
  105. set in: wfMessage(), Article::editUpdates() and Title::moveTo()
  106. expiry: $wgMsgCacheExpiry
  107. cleared by: nothing
  108. Newtalk:
  109. key: $wgDBname:newtalk:ip:$ip
  110. ex: wikidb:newtalk:ip:123.45.67.89
  111. stores: integer, 0 or 1
  112. set in: User::loadFromDatabase()
  113. cleared by: User::saveSettings() # ?
  114. expiry: 30 minutes
  115. Parser Cache:
  116. access: ParserCache
  117. backend: $wgParserCacheType
  118. key: $wgDBname:pcache:idhash:$pageid-$renderkey!$hash
  119. $pageid: id of the page
  120. $renderkey: 1 if action=render, 0 otherwise
  121. $hash: hash of user options applied to the page, see ParserOptions::optionsHash()
  122. ex: wikidb:pcache:idhash:1-0!1!0!!en!2
  123. stores: ParserOutput object
  124. modified by: WikiPage::doEditUpdates() or PoolWorkArticleView::doWork()
  125. expiry: $wgParserCacheExpireTime or less if it contains short lived functions
  126. key: $wgDBname:pcache:idoptions:$pageid
  127. stores: CacheTime object with an additional list of used options for the hash,
  128. serves as ParserCache pointer.
  129. modified by: ParserCache::save()
  130. expiry: The same as the ParserCache entry it points to.
  131. Ping limiter:
  132. controlled by: $wgRateLimits
  133. key: $wgDBname:limiter:action:$action:ip:$ip,
  134. $wgDBname:limiter:action:$action:user:$id,
  135. mediawiki:limiter:action:$action:ip:$ip and
  136. mediawiki:limiter:action:$action:subnet:$sub
  137. ex: wikidb:limiter:action:edit:ip:123.45.67.89,
  138. wikidb:limiter:action:edit:user:1012
  139. mediawiki:limiter:action:edit:ip:123.45.67.89 and
  140. mediawiki:limiter:action:$action:subnet:123.45.67
  141. stores: number of action made by user/ip/subnet
  142. cleared by: nothing
  143. expiry: expiry set for the action and group in $wgRateLimits
  144. Proxy Check: (deprecated)
  145. key: $wgDBname:proxy:ip:$ip
  146. ex: wikidb:proxy:ip:123.45.67.89
  147. stores: 1 if the ip is a proxy
  148. cleared by: nothing
  149. expiry: $wgProxyMemcExpiry
  150. Revision text:
  151. key: $wgDBname:revisiontext:textid:$id
  152. ex: wikidb:revisiontext:textid:1012
  153. stores: text of a revision
  154. cleared by: nothing
  155. expiry: $wgRevisionCacheExpiry
  156. Sessions:
  157. controlled by: $wgSessionsInObjectCache
  158. key: $wgBDname:session:$id
  159. ex: wikidb:session:38d7c5b8d3bfc51egf40c69bc40f8be3
  160. stores: $SESSION, useful when using a multi-sever wiki
  161. expiry: one hour
  162. cleared by: session_destroy()
  163. Sidebar:
  164. access: WANObjectCache
  165. controlled by: $wgEnableSidebarCache
  166. key: $wgDBname:sidebar
  167. ex: wikidb:sidebar
  168. stores: the html output of the sidebar
  169. expiry: $wgSidebarCacheExpiry
  170. cleared by: MessageCache::replace()
  171. Special:Allpages:
  172. key: $wgDBname:allpages:ns:$ns
  173. ex: wikidb:allpages:ns:0
  174. stores: array of pages in a namespace
  175. expiry: one hour
  176. cleared by: nothing
  177. Special:Recentchanges (feed):
  178. backend: $wgMessageCacheType
  179. key: $wgDBname:rcfeed:$format:$limit:$hideminor:$target and
  180. rcfeed:$format:timestamp
  181. ex: wikidb:rcfeed:rss:50:: and rcfeed:rss:timestamp
  182. stores: xml output of feed
  183. expiry: one day
  184. clear by: maintenance/rebuildrecentchanges.php script, or
  185. calling Special:Recentchanges?action=purge&feed=rss,
  186. Special:Recentchanges?action=purge&feed=atom,
  187. but note need $wgGroupPermissions[...]['purge'] permission.
  188. ... more to come ...