From eb75d9532b008f832238ddeb693e65203032bde1 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 28 Sep 2015 19:14:07 +0200 Subject: [PATCH] Magical mathematics to reduce the number of workers --- include/poller.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/poller.php b/include/poller.php index fc592d2066..4cb6eb8d58 100644 --- a/include/poller.php +++ b/include/poller.php @@ -51,6 +51,10 @@ function poller_run(&$argv, &$argc){ if (!posix_kill($pid["pid"], 0)) q("UPDATE `workerqueue` SET `executed` = '0000-00-00 00:00:00', `pid` = 0 WHERE `pid` = %d", intval($pid["pid"])); + else { + // To-Do: Kill long running processes + // But: Update processes (like the database update) mustn't be killed + } } else // Sleep two seconds before checking for running processes to avoid having too many workers @@ -124,7 +128,12 @@ function poller_too_much_workers() { if($maxsysload < 1) $maxsysload = 50; - $queues = max(0, ceil($queues * (($maxsysload - $load) / $maxsysload))); + $maxworkers = $queues; + + // Some magical mathemathics to reduce the workers + $exponent = 3; + $slope = $maxworkers / pow($maxsysload, $exponent); + $queues = ceil($slope * pow(max(0, $maxsysload - $load), $exponent)); logger("Current load: ".$load." - maximum: ".$maxsysload." - current queues: ".$active." - maximum: ".$queues, LOGGER_DEBUG); -- 2.39.5