Randomize thumbnail failure key TTL a bit to avoid stampedes
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 25 Apr 2014 18:25:51 +0000 (11:25 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 25 Apr 2014 18:33:10 +0000 (11:33 -0700)
Change-Id: Ibf268b646a9eb2acfaa649d634c5278133091158

thumb.php

index 707f1e2..a5bdc5b 100644 (file)
--- a/thumb.php
+++ b/thumb.php
@@ -374,7 +374,8 @@ function wfGenerateThumbnail( File $file, array $params, $thumbName ) {
        register_shutdown_function( function() use ( &$done, $key ) {
                if ( !$done ) { // transform() gave a fatal
                        global $wgMemc;
-                       $wgMemc->incrWithInit( $key, 3600 );
+                       // Randomize TTL to reduce stampedes
+                       $wgMemc->incrWithInit( $key, 3600 + mt_rand( 0, 300 ) );
                }
        } );
 
@@ -412,7 +413,8 @@ function wfGenerateThumbnail( File $file, array $params, $thumbName ) {
        $done = true; // no PHP fatal occured
 
        if ( !$thumb || $thumb->isError() ) {
-               $wgMemc->incrWithInit( $key, 3600 );
+               // Randomize TTL to reduce stampedes
+               $wgMemc->incrWithInit( $key, 3600 + mt_rand( 0, 300 ) );
        }
 
        return array( $thumb, $errorHtml );