From: Michael Vogel Date: Mon, 28 Sep 2015 05:54:28 +0000 (+0200) Subject: Load depending number of worker queues. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9767801be4bfff53afd60b09dd310bbefeb3a3d1;p=friendica.git Load depending number of worker queues. --- diff --git a/include/poller.php b/include/poller.php index e33167c5b1..fc592d2066 100644 --- a/include/poller.php +++ b/include/poller.php @@ -26,10 +26,11 @@ function poller_run(&$argv, &$argc){ unset($db_host, $db_user, $db_pass, $db_data); }; - $maxsysload = intval(get_config('system','maxloadavg')); - if($maxsysload < 1) - $maxsysload = 50; if(function_exists('sys_getloadavg')) { + $maxsysload = intval(get_config('system','maxloadavg')); + if($maxsysload < 1) + $maxsysload = 50; + $load = sys_getloadavg(); if(intval($load[0]) > $maxsysload) { logger('system: load ' . $load[0] . ' too high. poller deferred to next scheduled run.'); @@ -63,18 +64,11 @@ function poller_run(&$argv, &$argc){ while ($r = q("SELECT * FROM `workerqueue` WHERE `executed` = '0000-00-00 00:00:00' ORDER BY `created` LIMIT 1")) { - if(function_exists('sys_getloadavg')) { - $load = sys_getloadavg(); - if(intval($load[0]) > $maxsysload) { - logger('system: load ' . $load[0] . ' too high. poller deferred to next scheduled run.'); - return; - } - } - // Quit the poller once every hour if (time() > ($starttime + 3600)) return; + // Count active workers and compare them with a maximum value that depends on the load if (poller_too_much_workers()) return; @@ -115,28 +109,28 @@ function poller_run(&$argv, &$argc){ function poller_too_much_workers() { + $queues = get_config("system", "worker_queues"); + + if ($queues == 0) + $queues = 4; + + $active = poller_active_workers(); + + // Decrease the number of workers at higher load if(function_exists('sys_getloadavg')) { - $load = sys_getloadavg(); + $load = max(sys_getloadavg()); + + $maxsysload = intval(get_config('system','maxloadavg')); + if($maxsysload < 1) + $maxsysload = 50; + + $queues = max(0, ceil($queues * (($maxsysload - $load) / $maxsysload))); + + logger("Current load: ".$load." - maximum: ".$maxsysload." - current queues: ".$active." - maximum: ".$queues, LOGGER_DEBUG); - // To-Do - if ($load < 1) - $queues = 10; - elseif ($load < 5) - $queues = 4; - elseif ($load < 10) - $queues = 2; - else - $queues = 1; - - } else { - $queues = intval(get_config("system", "worker_queues")); - - if ($queues == 0) - $queues = 4; } - if (poller_active_workers() >= $queues) - return; + return($active >= $queues); } function poller_active_workers() {