diff options
Diffstat (limited to 'modules/throttle.module')
-rw-r--r-- | modules/throttle.module | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/modules/throttle.module b/modules/throttle.module index 1781b108d..15e8c2e10 100644 --- a/modules/throttle.module +++ b/modules/throttle.module @@ -14,12 +14,7 @@ * should consider disabling logic when the throttle_level gets to 4 or 5. */ function throttle_status() { - if (variable_get('throttle_enable', 0)) { - return variable_get('throttle_level', 0); - } - else { - return 0; - } + return variable_get('throttle_level', 0); } @@ -33,7 +28,7 @@ function throttle_exit() { ** referred to in the admin page as the 'probability limiter', roughly ** limiting throttle related database calls to 1 in N. */ - if ((variable_get('throttle_enable', 0)) && (!rand(0, variable_get("throttle_probability_limiter", 9)))) { + if (!rand(0, variable_get("throttle_probability_limiter", 9))) { /* ** Note: The rand() function is supported by PHP 3+. However, prior to ** PHP 4.2.0 it needs to be seeded with a call to srand(). It is important @@ -100,10 +95,6 @@ function throttle_help($section = "admin/help#throttle") { // throttle module configuration options function throttle_settings() { - // enable/disable auto-throttle - $group = form_radios(t("Enable auto-throttle"), 'throttle_enable', variable_get('throttle_enable', 0), array("1" => t("enabled"), "0" => t("disabled")), t("Enable auto-throttling congestion control mechanism. Allows your site to adapt under extreme user loads, such as being linked by Slashdot. To use the auto-throttle you must also enable the '<a href=\"%access_log\">access log</a>' from the statistics module.", array("%access_log" => url("admin/system/modules/statistics")))); - $output = form_group(t("Auto-throttle status"), $group); - // tune auto-throttle $throttles = array(1 => "1 (0,1,2,3,4,5)", 5 => "5 (0,5,10,15,20,25)", 10 => "10 (0,10,20,30,40,50)", 12 => "12 (0,12,24,36,48,60)", 15 => "15 (0,15,30,45,60,75)", 20 => "20 (0,20,40,60,80,100)", 30 => "30 (0,30,60,90,120,150)", 50 => "50 (0,50,100,150,200,250)", 60 => "60 (0,60,120,180,240,300)", 100 => "100 (0,100,200,300,400,500", 500 => "500 (0,500,1000,1500,2000,2500", 1000 => "1000 (0,1000,2000,3000,4000,5000)"); $group = form_select(t("Auto-throttle multiplier"), 'throttle_multiplier', variable_get('throttle_multiplier', 60), $throttles, "The 'auto-throttle multiplier' is the number of hits in the past 60 seconds required to trigger a higher throttle level. For example, if you set the multiplier to 60, and your site is getting less than 60 hits a minute, then the throttle will be at a level of 0. Only once you start getting more than 60 hits a minute will the throttle level go to 1. If you start getting more than 120 hits a minute, the throttle becomes 2. This continues until your site is sustaining more than 300 hits per minute, at which time the throttle reaches a maximum level of 5. In the pop down menu, the first number is the multiplier, and the numbers in parenthesis are how many hits are required to switch to each throttle level. The more powerful your server, the higher you should set the multiplier value."); @@ -118,31 +109,26 @@ function throttle_settings() { // displays admin oriented "Throttle status" block function throttle_display_throttle_block() { if (user_access('access throttle block')) { - if (variable_get('throttle_enable', 0)) { - /* the throttle is enabled: display the status of all throttle config */ - $throttle = module_invoke("throttle", "status"); - $multiplier = variable_get('throttle_multiplier', 60); - $minimum = $throttle * $multiplier; - $limiter = variable_get("throttle_probability_limiter", 9); - /* calculate probability limiter's odds of updating throttle */ - $probability = substr((($limiter / ($limiter + 1) * 100) - 100) * -1, 0, 4); - - if ($throttle < 5) { - $maximum = (($throttle + 1) * $multiplier) - 1; - $output .= t("Current level: %level (%min - %max)", array("%level" => $throttle, "%min" => $minimum, "%max" => $maximum)) ."<br />\n"; - } - else { - $output .= t("Current level: %level (%min+)", array("%level" => $throttle, "%min" => $minimum)) ."<br />\n"; - } - $output .= t("Probability: %probability%", array("%probability" => $probability)) ."<br />\n"; - if ($throttle < 5) { - $recent_activity = db_fetch_object(db_query("SELECT COUNT(timestamp) AS hits FROM {accesslog} WHERE timestamp >= %d", (time() - 60))); - $output .= "<br />". t("This site has served %pages in the past minute.", array("%pages" => format_plural($recent_activity->hits , "1 page", "%count pages"))); - _throttle_update($recent_activity->hits); - } + /* the throttle is enabled: display the status of all throttle config */ + $throttle = module_invoke("throttle", "status"); + $multiplier = variable_get('throttle_multiplier', 60); + $minimum = $throttle * $multiplier; + $limiter = variable_get("throttle_probability_limiter", 9); + /* calculate probability limiter's odds of updating throttle */ + $probability = substr((($limiter / ($limiter + 1) * 100) - 100) * -1, 0, 4); + + if ($throttle < 5) { + $maximum = (($throttle + 1) * $multiplier) - 1; + $output .= t("Current level: %level (%min - %max)", array("%level" => $throttle, "%min" => $minimum, "%max" => $maximum)) ."<br />\n"; } else { - $output .= t("Throttle: <a href=\"%status\">disabled</a>", array("%status" => url("admin/system/modules/throttle"))) ."<br />\n"; + $output .= t("Current level: %level (%min+)", array("%level" => $throttle, "%min" => $minimum)) ."<br />\n"; + } + $output .= t("Probability: %probability%", array("%probability" => $probability)) ."<br />\n"; + if ($throttle < 5) { + $recent_activity = db_fetch_object(db_query("SELECT COUNT(timestamp) AS hits FROM {accesslog} WHERE timestamp >= %d", (time() - 60))); + $output .= "<br />". t("This site has served %pages in the past minute.", array("%pages" => format_plural($recent_activity->hits , "1 page", "%count pages"))); + _throttle_update($recent_activity->hits); } } return $output; |