diff --git a/include/delivery.php b/include/delivery.php index 794b8f27a3..28d81226a4 100644 --- a/include/delivery.php +++ b/include/delivery.php @@ -51,6 +51,17 @@ function delivery_run($argv, $argc){ return; } + $maxsysload = intval(get_config('system','maxloadavg')); + if($maxsysload < 1) + $maxsysload = 50; + if(function_exists('sys_getloadavg')) { + $load = sys_getloadavg(); + if(intval($load[0]) > $maxsysload) { + logger('system: load ' . $load . ' too high. Delivery deferred to next queue run.'); + return; + } + } + // It's ours to deliver. Remove it from the queue. q("delete from deliverq where cmd = '%s' and item = %d and contact = %d limit 1", diff --git a/include/poller.php b/include/poller.php index 0a0e66b865..f6553c8460 100644 --- a/include/poller.php +++ b/include/poller.php @@ -30,6 +30,17 @@ function poller_run($argv, $argc){ load_config('config'); load_config('system'); + $maxsysload = intval(get_config('system','maxloadavg')); + if($maxsysload < 1) + $maxsysload = 50; + if(function_exists('sys_getloadavg')) { + $load = sys_getloadavg(); + if(intval($load[0]) > $maxsysload) { + logger('system: load ' . $load . ' too high. Poller deferred to next scheduled run.'); + return; + } + } + $lockpath = get_config('system','lockpath'); if ($lockpath != '') { $pidfile = new pidfile($lockpath, 'poller.lck'); @@ -39,6 +50,8 @@ function poller_run($argv, $argc){ } } + + $a->set_baseurl(get_config('system','url')); load_hooks(); diff --git a/mod/admin.php b/mod/admin.php index b07ef851a1..cfe5a2dd2c 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -243,6 +243,7 @@ function admin_page_site_post(&$a){ $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : ''); $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60); $delivery_interval = ((x($_POST,'delivery_interval'))? intval(trim($_POST['delivery_interval'])) : 0); + $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50); $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False); $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False); $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False); @@ -290,6 +291,7 @@ function admin_page_site_post(&$a){ } set_config('system','ssl_policy',$ssl_policy); set_config('system','delivery_interval',$delivery_interval); + set_config('system','maxloadavg',$maxloadavg); set_config('config','sitename',$sitename); if ($banner==""){ // don't know why, but del_config doesn't work... @@ -434,7 +436,7 @@ function admin_page_site(&$a) { '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""), '$timeout' => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), t("Value is in seconds. Set to 0 for unlimited (not recommended).")), '$delivery_interval' => array('delivery_interval', t("Delivery interval"), (x(get_config('system','delivery_interval'))?get_config('system','delivery_interval'):2), t("Delay background delivery processes by this many seconds to reduce system load. Recommend: 4-5 for shared hosts, 2-3 for virtual private servers. 0-1 for large dedicated servers.")), - + '$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")), '$form_security_token' => get_form_security_token("admin_site"), )); diff --git a/view/admin_site.tpl b/view/admin_site.tpl index 852a2c0bf2..265f2724df 100644 --- a/view/admin_site.tpl +++ b/view/admin_site.tpl @@ -81,6 +81,7 @@ {{ inc field_input.tpl with $field=$proxyuser }}{{ endinc }} {{ inc field_input.tpl with $field=$timeout }}{{ endinc }} {{ inc field_input.tpl with $field=$delivery_interval }}{{ endinc }} + {{ inc field_input.tpl with $field=$maxloadavg }}{{ endinc }} {{ inc field_input.tpl with $field=$abandon_days }}{{ endinc }}