]> git.mxchange.org Git - friendica.git/commitdiff
Makes the linear load calculation optional
authorMichael <heluecht@pirati.ca>
Wed, 20 Jun 2018 04:38:50 +0000 (04:38 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 20 Jun 2018 04:38:50 +0000 (04:38 +0000)
doc/htconfig.md
src/Core/Worker.php

index 15242e30775accea3f2a876e5fd62e2e7a7a1c6d..50fc4255fbc6d39df1dd62e0d00a7f9fd96c47a1 100644 (file)
@@ -94,6 +94,7 @@ Example: To set the automatic database cleanup process add this line to your .ht
 * **throttle_limit_month** - Maximum number of posts that a user can send per month with the API.
 * **wall-to-wall_share** (Boolean) - Displays forwarded posts like "wall-to-wall" posts.
 * **worker_cooldown** - Cooldown time after each worker function call. Default value is 0 seconds.
+* **worker_linear_load** (Boolean) - Enables the linear calculation of maximum queues.
 * **xrd_timeout** - Timeout for fetching the XRD links. Default value is 20 seconds.
 
 ## experimental ##
index d4257f1246a79ebc2c7527f09e6d94c38515f2ac..bc45be2d5b75da128966c7d98d56d0cb3dda2315 100644 (file)
@@ -624,16 +624,34 @@ class Worker
                $load = current_load();
                if ($load) {
                        $maxsysload = intval(Config::get("system", "maxloadavg", 50));
-                       $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));
+
+                       if (Config::get('system', 'worker_linear_load', false)) {
+                               /* The linear load calculation works fine if there is a low
+                                * number of maximum queues and a high load base level.
+                                * This can be present at shared hosters.
+                               */
+                               $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));
+                               }
+                       } else {
+                               /* The exponentional load calculation respects the load behaviour
+                                * of Linux systems with regular hardware that normally idles
+                                * with load values near 0.
+                               */
+                               $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));
                        }
 
                        $processlist = '';