]> git.mxchange.org Git - friendica.git/commitdiff
Fix logic errors in tooMuchWorkers()
authormiqrogroove <miqrogroove@gmail.com>
Tue, 19 Jun 2018 22:53:02 +0000 (18:53 -0400)
committerGitHub <noreply@github.com>
Tue, 19 Jun 2018 22:53:02 +0000 (18:53 -0400)
There are probably a dozen different ways to do this, so this is not necessarily the "right" way.

src/Core/Worker.php

index 8960780e55618bfa6b9b0472c1ebf1eeb8f208a7..f835660920241a8e4744e101799f157a52879468 100644 (file)
@@ -624,12 +624,19 @@ class Worker
                $load = current_load();
                if ($load) {
                        $maxsysload = intval(Config::get("system", "maxloadavg", 50));
-
-                       $maxworkers = $queues;
-
-                       // Some magical mathemathics to reduce the workers
+                       $tinyload = 1;
+
+                       if ($load > $maxsysload) {
+                               $queues = 0;
+                       } elseif ($load > $tinyload) {
+                               //Provide $queues number between 1 (below max load) and $maxqueues - 1 (above tiny load).
+                               $range = $maxsysload - $tinyload;
+                               $slope = 1.00 - (($load - $tinyload) / $range);
+                               $target = $slope * ($maxqueues - 1);
+                               $queues = intval(ceil($target));
+                       }
                        $exponent = 3;
-                       $slope = $maxworkers / pow($maxsysload, $exponent);
+                       $slope = $maxqueues / pow($maxsysload, $exponent);
                        $queues = ceil($slope * pow(max(0, $maxsysload - $load), $exponent));
                        $processlist = '';
 
@@ -698,12 +705,12 @@ class Worker
                        }
                }
 
-               // if there are too much worker, we down't spawn a new one.
-               if (Config::get('system', 'worker_daemon_mode', false) && ($active >= $queues)) {
+               // if there are too much worker, we don't spawn a new one.
+               if (Config::get('system', 'worker_daemon_mode', false) && ($active > $queues)) {
                        self::IPCSetJobState(false);
                }
 
-               return $active >= $queues;
+               return $active > $queues;
        }
 
        /**