Made BloomFilterTitleHasLogs refresh odds linear to be smoother
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 17 Feb 2015 09:37:33 +0000 (01:37 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 17 Feb 2015 09:37:33 +0000 (01:37 -0800)
Change-Id: I25a4de8cf3537c9b3f27002e8bbb210322decec5

includes/cache/bloom/BloomFilters.php

index 9b710d7..8017bac 100644 (file)
@@ -26,8 +26,11 @@ class BloomFilterTitleHasLogs {
        public static function mergeAndCheck(
                BloomCache $bcache, $domain, $virtualKey, array $status
        ) {
+               $ttr = 5; // try to refresh before this many seconds
                $age = microtime( true ) - $status['asOfTime']; // seconds
-               $scopedLock = ( mt_rand( 1, (int)pow( 3, max( 0, 5 - $age ) ) ) == 1 )
+               $chance = min( 1, $age / $ttr );
+
+               $scopedLock = ( mt_rand( 1, 1e9 ) <= 1e9 * $chance )
                        ? $bcache->getScopedLock( $virtualKey )
                        : false;