From 4bd371ffc6e8d84b0bec6eaffeae8b536b0f79f4 Mon Sep 17 00:00:00 2001 From: Sebastian Grewe Date: Fri, 6 Dec 2013 14:58:37 +0100 Subject: [PATCH] [IMPROVED] Check system load, dashboard updates This will suspend any dashboard updates if the system load exceeds a configurable threshold. Graphs will not update until the system load is again below the threshold. See dist config for new option. Should help those pools suffering from too many live update users. --- public/include/config/global.inc.dist.php | 15 +++++++++++++++ public/include/pages/api/getdashboarddata.inc.php | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/public/include/config/global.inc.dist.php b/public/include/config/global.inc.dist.php index bf0961bc..28a7bf96 100644 --- a/public/include/config/global.inc.dist.php +++ b/public/include/config/global.inc.dist.php @@ -456,4 +456,19 @@ $config['cookie']['secure'] = false; **/ $config['smarty']['cache'] = 0; $config['smarty']['cache_lifetime'] = 30; + +/** + * System load setting + * + * This will disable loading of some API calls in case the system + * loads exceeds the defined max setting. Useful to temporaily suspend + * live statistics on a server that is too busy to deal with requests. + * + * Options + * max = float, maximum system load + * + * Defaults: + * max = 10.0 + **/ +$config['system']['load']['max'] = 10.0; ?> diff --git a/public/include/pages/api/getdashboarddata.inc.php b/public/include/pages/api/getdashboarddata.inc.php index 94541365..95d3b061 100644 --- a/public/include/pages/api/getdashboarddata.inc.php +++ b/public/include/pages/api/getdashboarddata.inc.php @@ -3,6 +3,14 @@ // Make sure we are called from index.php if (!defined('SECURITY')) die('Hacking attempt'); +// System load check +if ($load = @sys_getloadavg()) { + if (isset($config['system']['load']['max']) && $load[0] > $config['system']['load']['max']) { + header('HTTP/1.1 503 Too busy, try again later'); + die('Server too busy. Please try again later.'); + } +} + // Check user token and access level permissions $user_id = $api->checkAccess($user->checkApiKey($_REQUEST['api_key']), @$_REQUEST['id']);