]> git.mxchange.org Git - friendica.git/commitdiff
Load depending number of worker queues.
authorMichael Vogel <icarus@dabo.de>
Mon, 28 Sep 2015 05:54:28 +0000 (07:54 +0200)
committerMichael Vogel <icarus@dabo.de>
Mon, 28 Sep 2015 05:54:28 +0000 (07:54 +0200)
include/poller.php

index e33167c5b14667eba38e01b18a38e5da755ccbe5..fc592d2066c35a72e382bf21e05cb842d31e0c4c 100644 (file)
@@ -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() {