From f10cf4756e1ba8f07c78ab919de09c28db212650 Mon Sep 17 00:00:00 2001
From: Dries Buytaert Notes on using the statistics: \$dbrows is the number or rows you want returned in your array. The function To implement the throttle, you should do something like this:";
@@ -178,20 +148,7 @@ function statistics_help($section = "admin/help#statistics") {
$output .= "
";
$output .= "
Example: statistics_title_list(\"timestamp\",\"5\");
Throttle
throttle_status()
will return a number from 0 to 5. 0 means that there is no throttle enabled at this time. Each number above that is a progressively more throttled system... To disable a feature when a site first begins to get busy, disable it at a throttle of 2 or 3. To hold on to the bitter end, wait until 4 or 5. \$throttle = 0;
- /* verify that the statitistics module is installed */
- if (function_exists(throttle_status)) {
- \$throttle = throttle_status()
- }
- if (\$throttle >= \$my_throttle_value) {
- // throttle limit reached, disable stuff
- }
- else {
- // throttle limit not reached, execute normally
- }
Note: Even though the configuration for the throttle is handled by the throttle module, the throttle logic itself is part of the statistics module. The configuration has been separated in order to make things easier for the average site that will not be utilizing the throttling mechanism. More information about how the throttle works can be found on the throttle module help page. (Find the throttle help page %here-help if you have enabled the throttle module).
"; - $output = t($output, array("%throttle" => l(t("throttle module"), "admin/system/modules"), "%modules" => l(t("enabled"), "admin/system/modules"), "%permissions" => l(t("permissions section"), "admin/user/permission"), "%referers" => l(t("referrers log"), "admin/statistics/referrers"), "%access" => l(t("access log"), "admin/statistics/log"), "%configuration" => l(t("administer") ." » ". t("configuration"), "admin/system/modules/statistics"), "%here-block" => l(t("here"), "admin/system/block"), "%here-help" => l(t("here"), "admin/help#throttle"))); + $output = t($output, array("%modules" => l(t("enabled"), "admin/system/modules"), "%permissions" => l(t("permissions section"), "admin/user/permission"), "%referers" => l(t("referrers log"), "admin/statistics/referrers"), "%access" => l(t("access log"), "admin/statistics/log"), "%configuration" => l(t("administer") ." » ". t("configuration"), "admin/system/modules/statistics"), "%here-block" => l(t("here"), "admin/system/block"))); break; case 'admin/system/modules#description': $output = t("Logs access statistics for your site."); @@ -472,15 +429,6 @@ function statistics_cron() { /* clean expired access logs */ db_query("DELETE FROM {accesslog} WHERE ". time() ." - timestamp > ". variable_get("statistics_flush_accesslog_timer", 259200)); - - $throttle = variable_get("throttle_level", 0); - /* 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("statistics_throttle_cron_timestamp", 0))) { - /* If throttle is on, back off one notch to test server load */ - variable_set("throttle_level", $throttle - 1); - variable_set("statistics_throttle_cron_timestamp", time()); - watchdog("warning", t("cron: decreasing throttle to level '%level' to test server load.", array("%level" => ($throttle - 1)))); - } } @@ -607,54 +555,4 @@ function statistics_nodeapi(&$node, $op, $arg = 0) { } } -/* internal throttle function - do not call from other modules */ -function _throttle_update($recent_activity) { - $throttle = throttle_status(); - $multiplier = variable_get("throttle_multiplier", 60); - - for ($i = 0; $i <= 5; $i++) { - if (($i * $multiplier) <= $recent_activity) { - $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("statistics_throttle_cron_timestamp", time()); - /* log the change */ - if ($throttle_new < $throttle) { - watchdog("message", "message: '". $recent_activity ."' hits in past minute; throttle decreased to level ". $throttle_new); - } - else { - watchdog("warning", "warning: '". $recent_activity ."' hits in past minute; throttle increased to level ". $throttle_new); - } - } - } -} - -/*********************** - * Auto-throttle API * - ***********************/ - -/* external throttle functions - call this from other modules, themes, etc */ -function throttle_status() { - if (variable_get("throttle_enable", 0)) { - return variable_get("throttle_level", 0); - } - else { - return 0; - } -} - ?> -- cgit v1.2.3