memcached.txt 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 three object for object caching:
  60. * $wgMemc, controlled by $wgMainCacheType
  61. * $parserMemc, controlled by $wgParserCacheType
  62. * $messageMemc, controlled by $wgMessageCacheType
  63. If you set CACHE_NONE to one of the three control variable, (default
  64. value for $wgMainCacheType), MediaWiki still create a MemCacheClient,
  65. but requests to it are no-ops and we always fall through to the
  66. database. If the cache daemon can't be contacted, it should also
  67. disable itself fairly smoothly.
  68. By default, $wgMemc is used but when it is $parserMemc or $messageMemc
  69. this is mentioned below.
  70. == Keys used ==
  71. (incomplete, out of date)
  72. Date Formatter:
  73. key: $wgDBname:dateformatter
  74. ex: wikidb:dateformatter
  75. stores: a single instance of the DateFormatter class
  76. cleared by: nothing
  77. expiry: one hour
  78. Difference Engine:
  79. key: $wgDBname:diff:version:{MW_DIFF_VERSION}:oldid:$old:newid:$new
  80. ex: wikidb:diff:version:1.11a:oldid:1:newid:2
  81. stores: body of a difference
  82. cleared by: nothing
  83. expiry: one week
  84. Interwiki:
  85. key: $wgDBname:interwiki:$prefix
  86. ex: wikidb:interwiki:w
  87. stores: object from the interwiki table of the database
  88. expiry: $wgInterwikiExpiry
  89. cleared by: nothing
  90. Lag time of the databases:
  91. key: $wgDBname:lag_times
  92. ex: wikidb:lag_times
  93. stores: array mapping the database id to its lag time
  94. expiry: 5 secondes
  95. cleared by: nothing
  96. Localisation:
  97. key: $wgDBname:localisation:$lang
  98. ex: wikidb:localisation:de
  99. stores: array of localisation settings
  100. set in: Language::loadLocalisation()
  101. expiry: none
  102. cleared by: Language::loadLocalisation()
  103. Message Cache:
  104. stored in: $messageMemc
  105. key: $wgDBname:messages, $wgDBname:messages-hash, $wgDBname:messages-status
  106. ex: wikidb:messages, wikidb:messages-hash, wikidb:messages-status
  107. stores: an array where the keys are DB keys and the values are messages
  108. set in: wfMessage(), Article::editUpdates() and Title::moveTo()
  109. expiry: $wgMsgCacheExpiry
  110. cleared by: nothing
  111. Newtalk:
  112. key: $wgDBname:newtalk:ip:$ip
  113. ex: wikidb:newtalk:ip:123.45.67.89
  114. stores: integer, 0 or 1
  115. set in: User::loadFromDatabase()
  116. cleared by: User::saveSettings() # ?
  117. expiry: 30 minutes
  118. Parser Cache:
  119. stored in: $parserMemc
  120. key: $wgDBname:pcache:idhash:$pageid-$renderkey!$hash
  121. $pageid: id of the page
  122. $renderkey: 1 if action=render, 0 otherwise
  123. $hash: hash of user options applied to the page, see ParserOptions::optionsHash()
  124. ex: wikidb:pcache:idhash:1-0!1!0!!en!2
  125. stores: ParserOutput object
  126. modified by: WikiPage::doEditUpdates() or PoolWorkArticleView::doWork()
  127. expiry: $wgParserCacheExpireTime or less if it contains short lived functions
  128. key: $wgDBname:pcache:idoptions:$pageid
  129. stores: CacheTime object with an additional list of used options for the hash,
  130. serves as ParserCache pointer.
  131. modified by: ParserCache::save()
  132. expiry: The same as the ParserCache entry it points to.
  133. Ping limiter:
  134. controlled by: $wgRateLimits
  135. key: $wgDBname:limiter:action:$action:ip:$ip,
  136. $wgDBname:limiter:action:$action:user:$id,
  137. mediawiki:limiter:action:$action:ip:$ip and
  138. mediawiki:limiter:action:$action:subnet:$sub
  139. ex: wikidb:limiter:action:edit:ip:123.45.67.89,
  140. wikidb:limiter:action:edit:user:1012
  141. mediawiki:limiter:action:edit:ip:123.45.67.89 and
  142. mediawiki:limiter:action:$action:subnet:123.45.67
  143. stores: number of action made by user/ip/subnet
  144. cleared by: nothing
  145. expiry: expiry set for the action and group in $wgRateLimits
  146. Proxy Check: (deprecated)
  147. key: $wgDBname:proxy:ip:$ip
  148. ex: wikidb:proxy:ip:123.45.67.89
  149. stores: 1 if the ip is a proxy
  150. cleared by: nothing
  151. expiry: $wgProxyMemcExpiry
  152. Revision text:
  153. key: $wgDBname:revisiontext:textid:$id
  154. ex: wikidb:revisiontext:textid:1012
  155. stores: text of a revision
  156. cleared by: nothing
  157. expiry: $wgRevisionCacheExpiry
  158. Sessions:
  159. controlled by: $wgSessionsInObjectCache
  160. key: $wgBDname:session:$id
  161. ex: wikidb:session:38d7c5b8d3bfc51egf40c69bc40f8be3
  162. stores: $SESSION, useful when using a multi-sever wiki
  163. expiry: one hour
  164. cleared by: session_destroy()
  165. Sidebar:
  166. stored in: $parserMemc
  167. controlled by: $wgEnableSidebarCache
  168. key: $wgDBname:sidebar
  169. ex: wikidb:sidebar
  170. stores: the html output of the sidebar
  171. expiry: $wgSidebarCacheExpiry
  172. cleared by: MessageCache::replace()
  173. Special:Allpages:
  174. key: $wgDBname:allpages:ns:$ns
  175. ex: wikidb:allpages:ns:0
  176. stores: array of pages in a namespace
  177. expiry: one hour
  178. cleared by: nothing
  179. Special:Recentchanges (feed):
  180. stored in: $messageMemc
  181. key: $wgDBname:rcfeed:$format:$limit:$hideminor:$target and
  182. rcfeed:$format:timestamp
  183. ex: wikidb:rcfeed:rss:50:: and rcfeed:rss:timestamp
  184. stores: xml output of feed
  185. expiry: one day
  186. clear by: maintenance/rebuildrecentchanges.php script, or
  187. calling Special:Recentchanges?action=purge&feed=rss,
  188. Special:Recentchanges?action=purge&feed=atom,
  189. but note need $wgGroupPermissions[...]['purge'] permission.
  190. ... more to come ...