From e27500be17fc41e7b430bc7da8897f47b6a24b7a Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 12 Apr 2011 03:59:47 +0000 Subject: [PATCH] In SQLBagOStuff: make it possible to change the purge period, or disable purging altogether. At Domas's suggestion, for deployment to Wikimedia very soon. --- includes/objectcache/SqlBagOStuff.php | 32 ++++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/includes/objectcache/SqlBagOStuff.php b/includes/objectcache/SqlBagOStuff.php index 7d87a24b77..10f42cdcd8 100644 --- a/includes/objectcache/SqlBagOStuff.php +++ b/includes/objectcache/SqlBagOStuff.php @@ -18,17 +18,28 @@ class SqlBagOStuff extends BagOStuff { var $db; var $serverInfo; var $lastExpireAll = 0; + var $purgePeriod = 100; /** * Constructor. Parameters are: * - server: A server info structure in the format required by each * element in $wgDBServers. + * + * - purgePeriod: The average number of object cache requests in between + * garbage collection operations, where expired entries + * are removed from the database. Or in other words, the + * reciprocal of the probability of purging on any given + * request. If this is set to zero, purging will never be + * done. */ public function __construct( $params ) { if ( isset( $params['server'] ) ) { $this->serverInfo = $params['server']; $this->serverInfo['load'] = 1; } + if ( isset( $params['purgePeriod'] ) ) { + $this->purgePeriod = intval( $params['purgePeriod'] ); + } } /** @@ -213,14 +224,19 @@ class SqlBagOStuff extends BagOStuff { } protected function garbageCollect() { - /* Ignore 99% of requests */ - if ( !mt_rand( 0, 100 ) ) { - $now = time(); - /* Avoid repeating the delete within a few seconds */ - if ( $now > ( $this->lastExpireAll + 1 ) ) { - $this->lastExpireAll = $now; - $this->expireAll(); - } + if ( !$this->purgePeriod ) { + // Disabled + return; + } + // Only purge on one in every $this->purgePeriod requests. + if ( $this->purgePeriod !== 1 && mt_rand( 0, $this->purgePeriod - 1 ) ) { + return; + } + $now = time(); + // Avoid repeating the delete within a few seconds + if ( $now > ( $this->lastExpireAll + 1 ) ) { + $this->lastExpireAll = $now; + $this->expireAll(); } } -- 2.20.1