From 5c57d228945c92b17df04ce6778889b34cf7c3d8 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 25 Apr 2014 11:25:51 -0700 Subject: [PATCH] Randomize thumbnail failure key TTL a bit to avoid stampedes Change-Id: Ibf268b646a9eb2acfaa649d634c5278133091158 --- thumb.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/thumb.php b/thumb.php index 707f1e26cb..a5bdc5bb25 100644 --- 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 ); -- 2.20.1