Sometimes the function "sys_getloadavg" doesn't return an array. This is a workaround.

This commit is contained in:
Michael Vogel 2015-12-15 23:26:58 +01:00
parent 791d152b8f
commit 6e03477598
7 changed files with 43 additions and 27 deletions

View file

@ -1948,3 +1948,15 @@ function validate_include(&$file) {
return true; return true;
} }
function current_load() {
if (!function_exists('sys_getloadavg'))
return false;
$load_arr = sys_getloadavg();
if (!is_array($load_arr))
return false;
return max($load_arr);
}

View file

@ -44,10 +44,11 @@ function cron_run(&$argv, &$argc){
$maxsysload = intval(get_config('system','maxloadavg')); $maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1) if($maxsysload < 1)
$maxsysload = 50; $maxsysload = 50;
if(function_exists('sys_getloadavg')) {
$load = sys_getloadavg(); $load = current_load();
if(intval($load[0]) > $maxsysload) { if($load) {
logger('system: load ' . $load[0] . ' too high. cron deferred to next scheduled run.'); if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. cron deferred to next scheduled run.');
return; return;
} }
} }

View file

@ -27,10 +27,11 @@ function cronhooks_run(&$argv, &$argc){
$maxsysload = intval(get_config('system','maxloadavg')); $maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1) if($maxsysload < 1)
$maxsysload = 50; $maxsysload = 50;
if(function_exists('sys_getloadavg')) {
$load = sys_getloadavg(); $load = current_load();
if(intval($load[0]) > $maxsysload) { if($load) {
logger('system: load ' . $load[0] . ' too high. Cronhooks deferred to next scheduled run.'); if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. Cronhooks deferred to next scheduled run.');
return; return;
} }
} }

View file

@ -58,10 +58,11 @@ function delivery_run(&$argv, &$argc){
$maxsysload = intval(get_config('system','maxloadavg')); $maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1) if($maxsysload < 1)
$maxsysload = 50; $maxsysload = 50;
if(function_exists('sys_getloadavg')) {
$load = sys_getloadavg(); $load = current_load();
if(intval($load[0]) > $maxsysload) { if($load) {
logger('system: load ' . $load[0] . ' too high. Delivery deferred to next queue run.'); if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. Delivery deferred to next queue run.');
return; return;
} }
} }

View file

@ -28,10 +28,11 @@ function discover_poco_run(&$argv, &$argc){
$maxsysload = intval(get_config('system','maxloadavg')); $maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1) if($maxsysload < 1)
$maxsysload = 50; $maxsysload = 50;
if(function_exists('sys_getloadavg')) {
$load = sys_getloadavg(); $load = current_load();
if(intval($load[0]) > $maxsysload) { if($load) {
logger('system: load ' . $load[0] . ' too high. discover_poco deferred to next scheduled run.'); if(intval($load) > $maxsysload) {
logger('system: load ' . $load . ' too high. discover_poco deferred to next scheduled run.');
return; return;
} }
} }

View file

@ -26,14 +26,14 @@ function poller_run(&$argv, &$argc){
unset($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data);
}; };
if(function_exists('sys_getloadavg')) { $load = current_load();
if($load) {
$maxsysload = intval(get_config('system','maxloadavg')); $maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1) if($maxsysload < 1)
$maxsysload = 50; $maxsysload = 50;
$load = sys_getloadavg(); if(intval($load) > $maxsysload) {
if(intval($load[0]) > $maxsysload) { logger('system: load ' . $load . ' too high. poller deferred to next scheduled run.');
logger('system: load ' . $load[0] . ' too high. poller deferred to next scheduled run.');
return; return;
} }
} }
@ -134,9 +134,8 @@ function poller_too_much_workers($stage) {
$active = poller_active_workers(); $active = poller_active_workers();
// Decrease the number of workers at higher load // Decrease the number of workers at higher load
if(function_exists('sys_getloadavg')) { $load = current_load();
$load = max(sys_getloadavg()); if($load) {
$maxsysload = intval(get_config('system','maxloadavg')); $maxsysload = intval(get_config('system','maxloadavg'));
if($maxsysload < 1) if($maxsysload < 1)
$maxsysload = 50; $maxsysload = 50;

View file

@ -56,10 +56,11 @@ if(!$install) {
$maxsysload_frontend = intval(get_config('system','maxloadavg_frontend')); $maxsysload_frontend = intval(get_config('system','maxloadavg_frontend'));
if($maxsysload_frontend < 1) if($maxsysload_frontend < 1)
$maxsysload_frontend = 50; $maxsysload_frontend = 50;
if(function_exists('sys_getloadavg')) {
$load = sys_getloadavg(); $load = current_load();
if(intval($load[0]) > $maxsysload_frontend) { if($load) {
logger('system: load ' . $load[0] . ' too high. Service Temporarily Unavailable.'); if($load > $maxsysload_frontend) {
logger('system: load ' . $load . ' too high. Service Temporarily Unavailable.');
header($_SERVER["SERVER_PROTOCOL"].' 503 Service Temporarily Unavailable'); header($_SERVER["SERVER_PROTOCOL"].' 503 Service Temporarily Unavailable');
header('Retry-After: 300'); header('Retry-After: 300');
die("System is currently unavailable. Please try again later"); die("System is currently unavailable. Please try again later");