summaryrefslogtreecommitdiff
path: root/modules/throttle
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2004-01-05 22:39:42 +0000
committerDries Buytaert <dries@buytaert.net>2004-01-05 22:39:42 +0000
commit7cf848279ceec2f8870fe80f4be6343c37528f1e (patch)
treeacc68edc80e6bdd2df12330b6ed507e67298789e /modules/throttle
parent82d45931ac7be842576e82410ac564ad8ab5c8b1 (diff)
downloadbrdo-7cf848279ceec2f8870fe80f4be6343c37528f1e.tar.gz
brdo-7cf848279ceec2f8870fe80f4be6343c37528f1e.tar.bz2
- Implemented feature request/bug #4973: removed the throttle module's dependence
on cron to make adjusting the throttle level more responsive (when configured to).
Diffstat (limited to 'modules/throttle')
-rw-r--r--modules/throttle/throttle.module62
1 files changed, 14 insertions, 48 deletions
diff --git a/modules/throttle/throttle.module b/modules/throttle/throttle.module
index 518f34d48..772fdcd9f 100644
--- a/modules/throttle/throttle.module
+++ b/modules/throttle/throttle.module
@@ -43,13 +43,10 @@ function throttle_exit() {
*/
$throttle = throttle_status();
- // if we're at throttle level 5, we don't do anything
- if ($throttle < 5) {
- $multiplier = variable_get("throttle_multiplier", 60);
- // count all hits in past sixty seconds
- $recent_activity = db_fetch_object(db_query("SELECT COUNT(timestamp) AS hits FROM {accesslog} WHERE timestamp >= %d", (time() - 60)));
- _throttle_update($recent_activity->hits);
- }
+ $multiplier = variable_get("throttle_multiplier", 60);
+ // count all hits in past sixty seconds
+ $recent_activity = db_fetch_object(db_query("SELECT COUNT(timestamp) AS hits FROM {accesslog} WHERE timestamp >= %d", (time() - 60)));
+ _throttle_update($recent_activity->hits);
}
}
@@ -77,12 +74,9 @@ function throttle_help($section = "admin/help#throttle") {
$output .= "<h3>Configuring the throttle module</h3><p>The %throttle-config for the throttle allows you to turn it on and off, as well as to fine-tune how sensitive it is.</p>";
$output .= "<h4>enable auto-throttle:</h4><blockquote>This first option on the throttle module configuration screen allows you to enable or disable the auto-throttling mechanism. Note that the access-log must also be enabled via the %statistics-config for the auto-throttling mechanism to have any effect.</blockquote>";
$output .= "<h4>auto-throttle multiplier:</h4><blockquote><p>This second option allows you to tune the auto-throttle mechanism. The auto-throttle mechanism supports six throttle levels, from 0 (off) to 5 (maximum). The current throttle level is based upon how many pages have been accessed on your site in the past 60 seconds - the more pages being displayed, the higher the throttle level. This multiplier defines how many hits are required to switch from one throttle level to the next.</p>";
- $output .= "<p>For example, with a throttle multiplier of 20: Once 20 pages have been accessed on your site within a period of 60 seconds, the throttle level will be incremented to a level of 1. Once 40 pages have been accessed on your site within a period of 60 seconds, the throttle level will be incremented to a level of 2. And so on, until 100 pages are accessed on your site within a period of 60 seconds, at which time the throttle level will be set to a maximum level of 5.</p>";
- $output .= "<p>Upon reaching a throttle level of 5, access logs and the auto-throttle checking mechanism is automatically disabled. It is only renabled by cron after a period of time defined by \"auto-throttle cron test\", explained below.</p></blockquote>";
+ $output .= "<p>For example, with a throttle multiplier of 20: Once 20 pages have been accessed on your site within a period of 60 seconds, the throttle level will be incremented to a level of 1. Once 40 pages have been accessed on your site within a period of 60 seconds, the throttle level will be incremented to a level of 2. And so on, until 100 pages are accessed on your site within a period of 60 seconds, at which time the throttle level will be set to a maximum level of 5.</p></blockquote>";
$output .= "<h4>auto-throttle probability limiter:</h4><blockquote><p>This option allows you to minimize the performance impact of the auto-throttle. If we refer to the probability limiter as P, then P% of all pages generated by your site will perform an extra database query to verify that the current throttle level is appropriate to the current server load.</p>";
$output .= "<p>As a rule of thumb, the higher your multiplier, the lower your probability limiter should be. For example, if you have a multiplier of 100, then you logically don't need to check the throttle level more than once out of every 100 page views, so the probability limiter should be set to 1%. As database queries are \"expensive\", it's recommended that you keep the probability limiter to the smallest percentage possible, while still high enough to react quickly to a change in server load.</p></blockquote>";
- $output .= "<h4>auto-throttle cron test:</h4><blockquote><p>The auto-throttle dynamically adjusts its level upward, but not downward. That is to say, if you have a multiplier of 20 and you get 45 hits in one minute, your throttle level will be adjusted to a level of 2. If a few minutes later you only get 35 hits in one minute, the throttle level will <strong>NOT</strong> be adjusted down to a level of 1. This prevents the throttle from bouncing back and forth between two levels.</p>";
- $output .= "<p>In order for the throttle level to be dropped, \"cron.php\" must be called regularly. This option then defines how often the level will be dropped by one to test the server load. If the server load is no longer as high as it was, the level will stay where it is, until the cron test period passes again and cron drops the throttle level again. This process repeats until the throttle is returned to a throttle level of 0.</p></blockquote>";
$output .= "<h3>Throttle block</h3><p>This block displays some statistics regarding the current throttle and its configuration. It is recommended that only site administrators receive the \"%throttle-access\" permission bit required to view this block. It does not display information that would interest a normal site end-user.</p>";
$output .= "<p>Don't forget to enable the block %throttle-block-enable.</p>";
$output .= "<h3>Permissions</h3><p>This module has one permission that needs to be configured in %permissions.</p>";
@@ -116,24 +110,11 @@ function throttle_settings() {
$probabilities = array(0 => "100%", 1 => "50%", 2 => "33.3%", 3 => "25%", 4 => "20%", 5 => "16.6%", 7 => "12.5%", 9 => "10%", 19 => "5%", 99 => "1%", 199 => ".5%", 399 => ".25%", 989 => ".1%");
$group .= form_select(t("Auto-throttle probability limiter"), "throttle_probability_limiter", variable_get("throttle_probability_limiter", 9), $probabilities, "The auto-throttle probability limiter is an efficiency mechanism to statistically reduce the overhead of the auto-throttle. The limiter is expressed as a percentage of page views, so for example if set to the default of 10% we only perform the extra database query to update the current level 1 out of every 10 page views. The busier your site, the lower you should set the limiter value.");
$period = array(1800 => format_interval(1800), 3600 => format_interval(3600), 7200 => format_interval(7200), 10800 => format_interval(10800), 14400 => format_interval(14400), 18000 => format_interval(18000), 21600 => format_interval(21600), 43200 => format_interval(43200), 64800 => format_interval(64800), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800));
- $group .= form_select(t("Auto-throttle cron test"), "throttle_cron_timer", variable_get("throttle_cron_timer", 10800), $period, "The auto-throttle cron test value specifies how frequently the throttle level will be automatically lowered, testing server load. After this amount of time, if your throttle level is greater than 0, it will be reduced by 1. If your site is no longer sustaining as heavy a load as it was when it increased the throttle, it will stay at this reduced level. If your site is still sustaining a heavy load, the throttle level will soon be increased again. Requires cron.");
$output .= form_group(t("Auto-throttle tuning"), $group);
return $output;
}
-function throttle_cron() {
- $throttle = throttle_status();
- /* check if throttle is currently on and if it's time to drop level */
- if (($throttle) && ((time() - variable_get("throttle_cron_timer", 10800)) > variable_get("throttle_cron_timestamp", 0))) {
- /* If throttle is on, back off one notch to test server load */
- variable_set("throttle_level", $throttle - 1);
- variable_set("throttle_cron_timestamp", time());
- watchdog("warning", t("cron: decreasing throttle to level '%level' to test server load.", array("%level" => ($throttle - 1))));
- }
-}
-
-
// displays admin oriented "Throttle status" block
function throttle_display_throttle_block() {
if (user_access("access throttle block")) {
@@ -146,7 +127,6 @@ function throttle_display_throttle_block() {
/* calculate probability limiter's odds of updating throttle */
$probability = substr((($limiter / ($limiter + 1) * 100) - 100) * -1, 0, 4);
- $output .= t("Throttle: %status", array("%status" => l(t("enabled"), "admin/system/modules/throttle"))) ."<br />\n";
if ($throttle < 5) {
$maximum = (($throttle + 1) * $multiplier) - 1;
$output .= t("Current level: %level (%min - %max)", array("%level" => $throttle, "%min" => $minimum, "%max" => $maximum)) ."<br />\n";
@@ -186,33 +166,19 @@ function _throttle_update($hits) {
$multiplier = variable_get("throttle_multiplier", 60);
for ($i = 0; $i <= 5; $i++) {
- if (($i * $multiplier) <= $hits) {
+ if ($i * $multiplier <= $hits) {
$throttle_new = $i;
}
}
- if ($throttle_new != $throttle) {
- /*
- ** reduce throttle if new throttle would be 3+ less than current throttle,
- ** (all other throttle reduction done by _cron hook), increase throttle if
- ** new throttle would be greater than current throttle.
- */
- if (($throttle_new < ($throttle - 2)) || ($throttle_new > $throttle)) {
- /* update throttle level */
- variable_set("throttle_level", $throttle_new);
- /*
- ** update the global timestamp, preventing cron.php from jumping in
- ** too quickly, allowing for user defined period to first pass.
- */
- variable_set("throttle_cron_timestamp", time());
- /* log the change */
- if ($throttle_new < $throttle) {
- watchdog("regular", "message: '". $hits ."' hits in past minute; throttle decreased to level ". $throttle_new);
- }
- else {
- watchdog("warning", "warning: '". $hits ."' hits in past minute; throttle increased to level ". $throttle_new);
- }
- }
+ // log the change
+ if ($throttle_new < $throttle) {
+ variable_set("throttle_level", $throttle - 1);
+ watchdog("regular", "message: '". $hits ."' hits in past minute; throttle decreased to level ". $throttle_new);
+ }
+ if ($throttle_new > $throttle) {
+ variable_set("throttle_level", $throttle + 1);
+ watchdog("warning", "warning: '". $hits ."' hits in past minute; throttle increased to level ". $throttle_new);
}
}