]> git.openstreetmap.org Git - nominatim.git/commitdiff
restrict to one sleep per bucket. A second sleep while already sleeping results...
authorBrian Quinion <openstreetmap@brian.quinion.co.uk>
Mon, 10 Dec 2012 01:36:33 +0000 (01:36 +0000)
committerBrian Quinion <openstreetmap@brian.quinion.co.uk>
Mon, 10 Dec 2012 01:36:33 +0000 (01:36 +0000)
lib/init-website.php
lib/leakybucket.php
utils/blocks.php

index 445bbc7ced2e5048f31766c78f6d0b40225c478f..8603e309f426f888bb8bd1834ee8a6b86be75736 100644 (file)
                        $m->add('sleepCounter', 0);
                        $iCurrentSleeping = $m->increment('sleepCounter');
                }
                        $m->add('sleepCounter', 0);
                        $iCurrentSleeping = $m->increment('sleepCounter');
                }
-               if ($iCurrentSleeping >= CONST_ConnectionBucket_MaxSleeping)
+               if ($iCurrentSleeping >= CONST_ConnectionBucket_MaxSleeping || isBucketSleeping($aBucketKeys))
                {
                        // Too many threads sleeping already.  This becomes a hard block.
                        $fBucketVal = doBucket($aBucketKeys, CONST_ConnectionBucket_BlockLimit, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit);
                }
                else
                {
                {
                        // Too many threads sleeping already.  This becomes a hard block.
                        $fBucketVal = doBucket($aBucketKeys, CONST_ConnectionBucket_BlockLimit, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit);
                }
                else
                {
+                       setBucketSleeping($aBucketKeys, true);
                        sleep(($fBucketVal - CONST_ConnectionBucket_WaitLimit)/CONST_ConnectionBucket_LeakRate);
                        $fBucketVal = doBucket($aBucketKeys, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit);
                        sleep(($fBucketVal - CONST_ConnectionBucket_WaitLimit)/CONST_ConnectionBucket_LeakRate);
                        $fBucketVal = doBucket($aBucketKeys, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_LeakRate, CONST_ConnectionBucket_BlockLimit);
+                       setBucketSleeping($aBucketKeys, false);
                }
                $m->decrement('sleepCounter');
        }
                }
                $m->decrement('sleepCounter');
        }
@@ -48,3 +50,4 @@
        }
 
        header('Content-type: text/html; charset=utf-8');
        }
 
        header('Content-type: text/html; charset=utf-8');
+
index 778fe580fe6e065eeb06fef7b0368608e55945a4..6d4e8f293d4987bc1619419c9345ab32a477fc22 100644 (file)
@@ -26,7 +26,7 @@
                        $aCurrentBlock = $m->get($sKey);
                        if (!$aCurrentBlock)
                        {
                        $aCurrentBlock = $m->get($sKey);
                        if (!$aCurrentBlock)
                        {
-                               $aCurrentBlock = array($iRequestCost, $t);
+                               $aCurrentBlock = array($iRequestCost, $t, false);
                        }
                        else
                        {
                        }
                        else
                        {
                return $iMaxVal;
         }
 
                return $iMaxVal;
         }
 
+       function isBucketSleeping($asKey)
+       {
+               $m = getBucketMemcache();
+               if (!$m) return false;
+
+               foreach($asKey as $sKey)
+               {
+                       $aCurrentBlock = $m->get($sKey);
+                       if ($aCurrentBlock[2]) return true;
+               }
+               return false;
+       }
+
+       function setBucketSleeping($asKey, $bVal)
+       {
+               $m = getBucketMemcache();
+               if (!$m) return false;
+
+               $iMaxVal = 0;
+               $t = time();
+
+               foreach($asKey as $sKey)
+               {
+                       $aCurrentBlock = $m->get($sKey);
+                       $aCurrentBlock[2] = $bVal;
+                       $m->set($sKey, $aCurrentBlock, $t + 1 + $aCurrentBlock[0]/CONST_ConnectionBucket_LeakRate);
+               }
+               return true;
+       }
+
        function byValue1($a, $b)
        {
                if ($a[1] == $b[1])
        function byValue1($a, $b)
        {
                if ($a[1] == $b[1])
                        $aBlockedList[$sKey] = array(
                                'totalBlocks' => $aDetails[0],
                                'lastBlockTimestamp' => $aDetails[1],
                        $aBlockedList[$sKey] = array(
                                'totalBlocks' => $aDetails[0],
                                'lastBlockTimestamp' => $aDetails[1],
+                               'isSleeping' => (isset($aCurrentBlock[2])?$aCurrentBlock[2]:false),
                                'currentBucketSize' => $iCurrentBucketSize,
                                'currentlyBlocked' => $iCurrentBucketSize + (CONST_ConnectionBucket_Cost_Reverse) >= CONST_ConnectionBucket_BlockLimit,
                                );
                                'currentBucketSize' => $iCurrentBucketSize,
                                'currentlyBlocked' => $iCurrentBucketSize + (CONST_ConnectionBucket_Cost_Reverse) >= CONST_ConnectionBucket_BlockLimit,
                                );
index 6dee2845b06bfeb315da6af32b08c07ae5f7f4e1..bd5efd0014f014c2b3fb50dc2daff4a28c46695c 100755 (executable)
 
                $aBlocks = getBucketBlocks();
                echo "\n";
 
                $aBlocks = getBucketBlocks();
                echo "\n";
-               printf(" %-40s | %12s | %7s | %13s | %31s\n", "Key", "Total Blocks", "Current", "Still Blocked", "Last Block Time");
-               printf(" %'--40s-|-%'-12s-|-%'-7s-|-%'-13s-|-%'-31s\n", "", "", "", "", "");
+               printf(" %-40s | %12s | %7s | %13s | %31s | %8s\n", "Key", "Total Blocks", "Current", "Still Blocked", "Last Block Time", "Sleeping");
+               printf(" %'--40s-|-%'-12s-|-%'-7s-|-%'-13s-|-%'-31s-|-%'-8s\n", "", "", "", "", "", "");
                foreach($aBlocks as $sKey => $aDetails)
                {
                foreach($aBlocks as $sKey => $aDetails)
                {
-                       printf(" %-40s | %12s | %7s | %13s | %31s\n", $sKey, $aDetails['totalBlocks'], 
+                       printf(" %-40s | %12s | %7s | %13s | %31s | %8s\n", $sKey, $aDetails['totalBlocks'], 
                                (int)$aDetails['currentBucketSize'], $aDetails['currentlyBlocked']?'Y':'N', 
                                (int)$aDetails['currentBucketSize'], $aDetails['currentlyBlocked']?'Y':'N', 
-                               date("r", $aDetails['lastBlockTimestamp']));
+                               date("r", $aDetails['lastBlockTimestamp']), $aDetails['isSleeping']?'Y':'N');
                }
                echo "\n";
        }
                }
                echo "\n";
        }