*/
namespace Friendica\Core;
-use Friendica\Core\Addon;
-use Friendica\Core\Config;
-use Friendica\Core\System;
+use dba;
use Friendica\Database\DBM;
use Friendica\Model\Process;
use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Lock;
use Friendica\Util\Network;
-use dba;
require_once 'include/dba.php';
}
// If possible we will fetch new jobs for this worker
- if (!$refetched && Lock::set('worker_process', 0)) {
+ if (!$refetched && Lock::acquire('worker_process', 0)) {
$stamp = (float)microtime(true);
$refetched = self::findWorkerProcesses($passing_slow);
self::$db_duration += (microtime(true) - $stamp);
- Lock::remove('worker_process');
+ Lock::release('worker_process');
}
}
// To avoid the quitting of multiple workers only one worker at a time will execute the check
- if (Lock::set('worker', 0)) {
+ if (Lock::acquire('worker', 0)) {
$stamp = (float)microtime(true);
// Count active workers and compare them with a maximum value that depends on the load
if (self::tooMuchWorkers()) {
logger('Memory limit reached, quitting.', LOGGER_DEBUG);
return;
}
- Lock::remove('worker');
+ Lock::release('worker');
self::$db_duration += (microtime(true) - $stamp);
}
if (Config::get('system', 'worker_daemon_mode', false)) {
self::IPCSetJobState(false);
}
- logger("Couldn't select a workerqueue entry, quitting.", LOGGER_DEBUG);
+ logger("Couldn't select a workerqueue entry, quitting process " . getmypid() . ".", LOGGER_DEBUG);
}
/**
$argc = count($argv);
- $new_process_id = uniqid("wrk", true);
+ $new_process_id = System::processID("wrk");
logger("Process ".$mypid." - Prio ".$queue["priority"]." - ID ".$queue["id"].": ".$funcname." ".$queue["parameter"]." - Process PID: ".$new_process_id);
$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));
- }
- $exponent = 3;
- $slope = $maxqueues / pow($maxsysload, $exponent);
- $queues = ceil($slope * pow(max(0, $maxsysload - $load), $exponent));
+
+ /* Default exponent 3 causes queues to rapidly decrease as load increases.
+ * If you have 20 max queues at idle, then you get only 5 queues at 37.1% of $maxsysload.
+ * For some environments, this rapid decrease is not needed.
+ * With exponent 1, you could have 20 max queues at idle and 13 at 37% of $maxsysload.
+ */
+ $exponent = intval(Config::get('system', 'worker_load_exponent', 3));
+ $slope = pow(max(0, $maxsysload - $load) / $maxsysload, $exponent);
+ $queues = intval(ceil($slope * $maxqueues));
+
$processlist = '';
if (Config::get('system', 'worker_debug')) {
dba::close($r);
$stamp = (float)microtime(true);
- if (!Lock::set('worker_process')) {
+ if (!Lock::acquire('worker_process')) {
return false;
}
self::$lock_duration = (microtime(true) - $stamp);
$found = self::findWorkerProcesses($passing_slow);
self::$db_duration += (microtime(true) - $stamp);
- Lock::remove('worker_process');
+ Lock::release('worker_process');
if ($found) {
$r = dba::select('workerqueue', [], ['pid' => getmypid(), 'done' => false]);
}
// If there is a lock then we don't have to check for too much worker
- if (!Lock::set('worker', 0)) {
+ if (!Lock::acquire('worker', 0)) {
return true;
}
// If there are already enough workers running, don't fork another one
$quit = self::tooMuchWorkers();
- Lock::remove('worker');
+ Lock::release('worker');
if ($quit) {
return true;