r90942 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90941‎ | r90942 | r90943 >
Date:06:30, 28 June 2011
Author:tstarling
Status:ok
Tags:
Comment:
MFT r85862: configurable purging for MySQL cache
Modified paths:
  • /branches/wmf/1.17wmf1/includes/objectcache/SqlBagOStuff.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/includes/objectcache/SqlBagOStuff.php
@@ -8,17 +8,28 @@
99 class SqlBagOStuff extends BagOStuff {
1010 var $lb, $db, $serverInfo;
1111 var $lastExpireAll = 0;
 12+ var $purgePeriod = 100;
1213
1314 /**
1415 * Constructor. Parameters are:
1516 * - server: A server info structure in the format required by each
1617 * element in $wgDBServers.
 18+ *
 19+ * - purgePeriod: The average number of object cache requests in between
 20+ * garbage collection operations, where expired entries
 21+ * are removed from the database. Or in other words, the
 22+ * reciprocal of the probability of purging on any given
 23+ * request. If this is set to zero, purging will never be
 24+ * done.
1725 */
1826 public function __construct( $params ) {
1927 if ( isset( $params['server'] ) ) {
2028 $this->serverInfo = $params['server'];
2129 $this->serverInfo['load'] = 1;
2230 }
 31+ if ( isset( $params['purgePeriod'] ) ) {
 32+ $this->purgePeriod = intval( $params['purgePeriod'] );
 33+ }
2334 }
2435
2536 protected function getDB() {
@@ -200,15 +211,20 @@
201212 }
202213
203214 protected function garbageCollect() {
204 - /* Ignore 99% of requests */
205 - if ( !mt_rand( 0, 100 ) ) {
206 - $now = time();
207 - /* Avoid repeating the delete within a few seconds */
208 - if ( $now > ( $this->lastExpireAll + 1 ) ) {
209 - $this->lastExpireAll = $now;
210 - $this->expireAll();
211 - }
 215+ if ( !$this->purgePeriod ) {
 216+ // Disabled
 217+ return;
212218 }
 219+ // Only purge on one in every $this->purgePeriod requests.
 220+ if ( $this->purgePeriod !== 1 && mt_rand( 0, $this->purgePeriod - 1 ) ) {
 221+ return;
 222+ }
 223+ $now = time();
 224+ // Avoid repeating the delete within a few seconds
 225+ if ( $now > ( $this->lastExpireAll + 1 ) ) {
 226+ $this->lastExpireAll = $now;
 227+ $this->expireAll();
 228+ }
213229 }
214230
215231 public function expireAll() {
Property changes on: branches/wmf/1.17wmf1/includes/objectcache/SqlBagOStuff.php
___________________________________________________________________
Added: svn:mergeinfo
216232 Merged /branches/new-installer/phase3/includes/objectcache/SqlBagOStuff.php:r43664-66004
217233 Merged /branches/wmf-deployment/includes/objectcache/SqlBagOStuff.php:r53381,60970
218234 Merged /branches/REL1_15/phase3/includes/objectcache/SqlBagOStuff.php:r51646
219235 Merged /branches/wmf/1.16wmf4/includes/objectcache/SqlBagOStuff.php:r67177,69199,76243,77266
220236 Merged /branches/sqlite/includes/objectcache/SqlBagOStuff.php:r58211-58321
221237 Merged /trunk/phase3/includes/objectcache/SqlBagOStuff.php:r83590,85862,89512-89513

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85862In SQLBagOStuff: make it possible to change the purge period, or disable purg...tstarling03:59, 12 April 2011

Status & tagging log