Fix logic errors in tooMuchWorkers()

There are probably a dozen different ways to do this, so this is not necessarily the "right" way.
This commit is contained in:
miqrogroove 2018-06-19 18:53:02 -04:00 committed by GitHub
parent 43ab1b2cf2
commit 7e4d7b9aac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -624,12 +624,19 @@ class Worker
$load = current_load(); $load = current_load();
if ($load) { if ($load) {
$maxsysload = intval(Config::get("system", "maxloadavg", 50)); $maxsysload = intval(Config::get("system", "maxloadavg", 50));
$tinyload = 1;
$maxworkers = $queues; if ($load > $maxsysload) {
$queues = 0;
// Some magical mathemathics to reduce the workers } 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; $exponent = 3;
$slope = $maxworkers / pow($maxsysload, $exponent); $slope = $maxqueues / pow($maxsysload, $exponent);
$queues = ceil($slope * pow(max(0, $maxsysload - $load), $exponent)); $queues = ceil($slope * pow(max(0, $maxsysload - $load), $exponent));
$processlist = ''; $processlist = '';
@ -698,12 +705,12 @@ class Worker
} }
} }
// if there are too much worker, we down't spawn a new one. // if there are too much worker, we don't spawn a new one.
if (Config::get('system', 'worker_daemon_mode', false) && ($active >= $queues)) { if (Config::get('system', 'worker_daemon_mode', false) && ($active > $queues)) {
self::IPCSetJobState(false); self::IPCSetJobState(false);
} }
return $active >= $queues; return $active > $queues;
} }
/** /**