From 98a4c7a56c8b15f604885ebc6d08f375490d6f97 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 24 Sep 2022 10:00:41 +0200 Subject: [PATCH 1/2] We can now configure the worker runtime limits --- src/Core/Worker/Cron.php | 8 ++++++-- static/defaults.config.php | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Core/Worker/Cron.php b/src/Core/Worker/Cron.php index 9db954298..2accbea1c 100644 --- a/src/Core/Worker/Cron.php +++ b/src/Core/Worker/Cron.php @@ -77,6 +77,8 @@ class Cron ['order' => ['priority', 'retrial', 'created']] ); + $max_duration_defaults = DI::config()->get('system', 'worker_max_duration'); + while ($entry = DBA::fetch($entries)) { if (!posix_kill($entry["pid"], 0)) { DBA::update('workerqueue', ['executed' => DBA::NULL_DATETIME, 'pid' => 0], ['id' => $entry["id"]]); @@ -84,8 +86,10 @@ class Cron // Kill long running processes // Define the maximum durations - $max_duration_defaults = [PRIORITY_CRITICAL => 720, PRIORITY_HIGH => 10, PRIORITY_MEDIUM => 60, PRIORITY_LOW => 180, PRIORITY_NEGLIGIBLE => 720]; - $max_duration = $max_duration_defaults[$entry['priority']]; + $max_duration = $max_duration_defaults[$entry['priority']] ?? 0; + if (empty($max_duration)) { + continue; + } $argv = json_decode($entry['parameter'], true); if (!empty($entry['command'])) { diff --git a/static/defaults.config.php b/static/defaults.config.php index b02f53774..b199b055b 100644 --- a/static/defaults.config.php +++ b/static/defaults.config.php @@ -552,7 +552,7 @@ return [ // runtime_loglimit (Integer) // The runtime is logged, When the program execution time is higher than this value. 'runtime_loglimit' => 0, - + // sendmail_params (Boolean) // Normal sendmail command parameters will be added when the PHP mail() function is called for sending e-mails. // This ensures the Sender Email address setting is applied to the message envelope rather than the host's default address. @@ -650,6 +650,16 @@ return [ // Setting 0 would allow maximum worker queues at all times, which is not recommended. 'worker_load_exponent' => 3, + // worker_max_duration (Array) + // Maximum runtime per priority. Worker processes that exceed this runtime will be terminated. + 'worker_max_duration' => [ + PRIORITY_CRITICAL => 720, + PRIORITY_HIGH => 10, + PRIORITY_MEDIUM => 60, + PRIORITY_LOW => 180, + PRIORITY_NEGLIGIBLE => 720 + ], + // worker_processes_cooldown (Integer) // Maximum number per processes that causes a cooldown before each worker function call. 'worker_processes_cooldown' => 0, @@ -659,7 +669,7 @@ return [ // This is an experimental setting without knowing the performance impact. // Does not work when "worker_fork" is enabled (Needs more testing) 'worker_multiple_fetch' => false, - + // worker_defer_limit (Integer) // Per default the systems tries delivering for 15 times before dropping it. 'worker_defer_limit' => 15, From 4c52772d84eaf96d18e68ec0e546b648105221aa Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 26 Sep 2022 13:33:31 +0000 Subject: [PATCH 2/2] Use class constant --- src/Core/Worker.php | 7 +++++++ static/defaults.config.php | 10 +++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 036f065d4..69ca6004c 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -31,6 +31,13 @@ use Friendica\Util\DateTimeFormat; */ class Worker { + const PRIORITY_UNDEFINED = PRIORITY_UNDEFINED; + const PRIORITY_CRITICAL = PRIORITY_CRITICAL; + const PRIORITY_HIGH = PRIORITY_HIGH; + const PRIORITY_MEDIUM = PRIORITY_MEDIUM; + const PRIORITY_LOW = PRIORITY_LOW; + const PRIORITY_NEGLIGIBLE = PRIORITY_NEGLIGIBLE; + const STATE_STARTUP = 1; // Worker is in startup. This takes most time. const STATE_LONG_LOOP = 2; // Worker is processing the whole - long - loop. const STATE_REFETCH = 3; // Worker had refetched jobs in the execution loop. diff --git a/static/defaults.config.php b/static/defaults.config.php index b199b055b..f20b333dd 100644 --- a/static/defaults.config.php +++ b/static/defaults.config.php @@ -653,11 +653,11 @@ return [ // worker_max_duration (Array) // Maximum runtime per priority. Worker processes that exceed this runtime will be terminated. 'worker_max_duration' => [ - PRIORITY_CRITICAL => 720, - PRIORITY_HIGH => 10, - PRIORITY_MEDIUM => 60, - PRIORITY_LOW => 180, - PRIORITY_NEGLIGIBLE => 720 + Friendica\Core\Worker::PRIORITY_CRITICAL => 720, + Friendica\Core\Worker::PRIORITY_HIGH => 10, + Friendica\Core\Worker::PRIORITY_MEDIUM => 60, + Friendica\Core\Worker::PRIORITY_LOW => 180, + Friendica\Core\Worker::PRIORITY_NEGLIGIBLE => 720 ], // worker_processes_cooldown (Integer)