memcached.txt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 = [ "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 = [
  53. "127.0.0.1:11211", # one gig on this box
  54. [ "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. See MessageCache.php.
  102. Newtalk:
  103. key: $wgDBname:newtalk:ip:$ip
  104. ex: wikidb:newtalk:ip:123.45.67.89
  105. stores: integer, 0 or 1
  106. set in: User::loadFromDatabase()
  107. cleared by: User::saveSettings() # ?
  108. expiry: 30 minutes
  109. Parser Cache:
  110. access: ParserCache
  111. backend: $wgParserCacheType
  112. key: $wgDBname:pcache:idhash:$pageid-$renderkey!$hash
  113. $pageid: id of the page
  114. $renderkey: 1 if action=render, 0 otherwise
  115. $hash: hash of user options applied to the page, see ParserOptions::optionsHash()
  116. ex: wikidb:pcache:idhash:1-0!1!0!!en!2
  117. stores: ParserOutput object
  118. modified by: WikiPage::doEditUpdates() or PoolWorkArticleView::doWork()
  119. expiry: $wgParserCacheExpireTime or less if it contains short lived functions
  120. key: $wgDBname:pcache:idoptions:$pageid
  121. stores: CacheTime object with an additional list of used options for the hash,
  122. serves as ParserCache pointer.
  123. modified by: ParserCache::save()
  124. expiry: The same as the ParserCache entry it points to.
  125. Ping limiter:
  126. controlled by: $wgRateLimits
  127. key: $wgDBname:limiter:action:$action:ip:$ip,
  128. $wgDBname:limiter:action:$action:user:$id,
  129. mediawiki:limiter:action:$action:ip:$ip and
  130. mediawiki:limiter:action:$action:subnet:$sub
  131. ex: wikidb:limiter:action:edit:ip:123.45.67.89,
  132. wikidb:limiter:action:edit:user:1012
  133. mediawiki:limiter:action:edit:ip:123.45.67.89 and
  134. mediawiki:limiter:action:$action:subnet:123.45.67
  135. stores: number of action made by user/ip/subnet
  136. cleared by: nothing
  137. expiry: expiry set for the action and group in $wgRateLimits
  138. Proxy Check: (deprecated)
  139. key: $wgDBname:proxy:ip:$ip
  140. ex: wikidb:proxy:ip:123.45.67.89
  141. stores: 1 if the ip is a proxy
  142. cleared by: nothing
  143. expiry: $wgProxyMemcExpiry
  144. Revision text:
  145. key: $wgDBname:revisiontext:textid:$id
  146. ex: wikidb:revisiontext:textid:1012
  147. stores: text of a revision
  148. cleared by: nothing
  149. expiry: $wgRevisionCacheExpiry
  150. Sessions:
  151. controlled by: $wgSessionsInObjectCache
  152. key: $wgBDname:session:$id
  153. ex: wikidb:session:38d7c5b8d3bfc51egf40c69bc40f8be3
  154. stores: $SESSION, useful when using a multi-sever wiki
  155. expiry: one hour
  156. cleared by: session_destroy()
  157. Sidebar:
  158. access: WANObjectCache
  159. controlled by: $wgEnableSidebarCache
  160. key: $wgDBname:sidebar
  161. ex: wikidb:sidebar
  162. stores: the html output of the sidebar
  163. expiry: $wgSidebarCacheExpiry
  164. cleared by: MessageCache::replace()
  165. Special:Allpages:
  166. key: $wgDBname:allpages:ns:$ns
  167. ex: wikidb:allpages:ns:0
  168. stores: array of pages in a namespace
  169. expiry: one hour
  170. cleared by: nothing
  171. Special:Recentchanges (feed):
  172. backend: $wgMessageCacheType
  173. key: $wgDBname:rcfeed:$format:$limit:$hideminor:$target and
  174. rcfeed:$format:timestamp
  175. ex: wikidb:rcfeed:rss:50:: and rcfeed:rss:timestamp
  176. stores: xml output of feed
  177. expiry: one day
  178. clear by: maintenance/rebuildrecentchanges.php script, or
  179. calling Special:Recentchanges?action=purge&feed=rss,
  180. Special:Recentchanges?action=purge&feed=atom,
  181. but note need $wgGroupPermissions[...]['purge'] permission.
  182. ... more to come ...