Ensure that the daemon is called faster and more reliably

This commit is contained in:
Michael 2020-11-18 13:29:10 +00:00
parent 46ea5dc4a5
commit 0edc058a17
2 changed files with 12 additions and 6 deletions

View file

@ -33,6 +33,7 @@ use Friendica\Core\Logger;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Util\DateTimeFormat;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
// Get options // Get options
@ -193,8 +194,8 @@ while (true) {
if ($do_cron || (!DI::process()->isMaxLoadReached() && Worker::entriesExists() && Worker::isReady())) { if ($do_cron || (!DI::process()->isMaxLoadReached() && Worker::entriesExists() && Worker::isReady())) {
Worker::spawnWorker($do_cron); Worker::spawnWorker($do_cron);
} else { } else {
Logger::info('Cool down', ['pid' => $pid]); Logger::info('Cool down for 5 seconds', ['pid' => $pid]);
sleep(10); sleep(5);
} }
if ($do_cron) { if ($do_cron) {
@ -205,8 +206,9 @@ while (true) {
$last_cron = time(); $last_cron = time();
} }
Logger::info("Sleeping", ["pid" => $pid]);
$start = time(); $start = time();
Logger::info("Sleeping", ["pid" => $pid, 'until' => gmdate(DateTimeFormat::MYSQL, $start + $wait_interval)]);
do { do {
$seconds = (time() - $start); $seconds = (time() - $start);
@ -214,7 +216,7 @@ while (true) {
// Background: After jobs had been started, they often fork many workers. // Background: After jobs had been started, they often fork many workers.
// To not waste too much time, the sleep period increases. // To not waste too much time, the sleep period increases.
$arg = (($seconds + 1) / ($wait_interval / 9)) + 1; $arg = (($seconds + 1) / ($wait_interval / 9)) + 1;
$sleep = round(log10($arg) * 1000000, 0); $sleep = min(1000000, round(log10($arg) * 1000000, 0));
usleep($sleep); usleep($sleep);
$timeout = ($seconds >= $wait_interval); $timeout = ($seconds >= $wait_interval);

View file

@ -1254,6 +1254,11 @@ class Worker
DBA::update('workerqueue', ['priority' => $priority], ['parameter' => $parameters, 'done' => false, 'pid' => 0]); DBA::update('workerqueue', ['priority' => $priority], ['parameter' => $parameters, 'done' => false, 'pid' => 0]);
} }
// Set the IPC flag to ensure an immediate process execution via daemon
if (DI::config()->get('system', 'worker_daemon_mode', false)) {
self::IPCSetJobState(true);
}
// Should we quit and wait for the worker to be called as a cronjob? // Should we quit and wait for the worker to be called as a cronjob?
if ($dont_fork) { if ($dont_fork) {
return $added; return $added;
@ -1272,9 +1277,8 @@ class Worker
return $added; return $added;
} }
// We tell the daemon that a new job entry exists // Quit on daemon mode
if (DI::config()->get('system', 'worker_daemon_mode', false)) { if (DI::config()->get('system', 'worker_daemon_mode', false)) {
// We don't have to set the IPC flag - this is done in "tooMuchWorkers"
return $added; return $added;
} }