]> git.mxchange.org Git - friendica.git/commitdiff
Magical mathematics to reduce the number of workers
authorMichael Vogel <icarus@dabo.de>
Mon, 28 Sep 2015 17:14:07 +0000 (19:14 +0200)
committerMichael Vogel <icarus@dabo.de>
Mon, 28 Sep 2015 17:14:07 +0000 (19:14 +0200)
include/poller.php

index fc592d2066c35a72e382bf21e05cb842d31e0c4c..4cb6eb8d584c4516482321d25f711cd56fcec936 100644 (file)
@@ -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);