Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/67880


Change subject: Use adaptive TTL in LocalFile to deal with memcached flapping 
better.
......................................................................

Use adaptive TTL in LocalFile to deal with memcached flapping better.

* This is similar to FileBackendStore.

Change-Id: I4b260e70963afb677415574150ff15e02d5e9ef1
---
M includes/filerepo/file/LocalFile.php
M includes/objectcache/BagOStuff.php
2 files changed, 22 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/80/67880/1

diff --git a/includes/filerepo/file/LocalFile.php 
b/includes/filerepo/file/LocalFile.php
index b21b87a..d507a5d 100644
--- a/includes/filerepo/file/LocalFile.php
+++ b/includes/filerepo/file/LocalFile.php
@@ -271,8 +271,9 @@
                        }
                }
 
-               // Cache presence for 1 week and negatives for 1 day
-               $wgMemc->set( $key, $cache, $this->fileExists ? 86400 * 7 : 
86400 );
+               // Cache presence for up to 1 week and negatives for 1 day
+               $ttl = $wgMemc->adaptiveTTL( $this->timestamp, .1, 300, 7 * 
86400, 86400 );
+               $wgMemc->set( $key, $cache, $ttl );
        }
 
        /**
diff --git a/includes/objectcache/BagOStuff.php 
b/includes/objectcache/BagOStuff.php
index 857943e..395530c 100644
--- a/includes/objectcache/BagOStuff.php
+++ b/includes/objectcache/BagOStuff.php
@@ -291,6 +291,25 @@
        }
 
        /**
+        * Use the last-modified timestamp of an object to determine a cache TTL
+        *
+        * @param string|int|bool $mtime Object timestamp or false if does not 
exist
+        * @param float $factor A number in the range (0,1)
+        * @param int $minTTL Minimum seconds to cache object
+        * @param int $maxTTL Maximum seconds to cache object
+        * @param int $missingTTL Seconds to cache non-existence [defaults to 
$minTTL]
+        * @return int Time to cache object in seconds
+        */
+       public function adaptiveTTL( $mtime, $factor, $minTTL, $maxTTL, 
$missingTTL = null ) {
+               if ( $mtime === null || $mtime === false ) {
+                       return is_int( $missingTTL ) ? $missingTTL : $minTTL;
+               } else {
+                       $age = time() - wfTimestamp( TS_UNIX, $mtime );
+                       return min( $maxTTL, max( $minTTL, floor( $factor * 
$age ) ) );
+               }
+       }
+
+       /**
         * @param $text string
         */
        public function debug( $text ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/67880
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4b260e70963afb677415574150ff15e02d5e9ef1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to