Merge pull request #11921 from annando/worker-timeout
We can now configure the worker runtime limits
This commit is contained in:
commit
57a98c45f1
3 changed files with 25 additions and 4 deletions
|
@ -31,6 +31,13 @@ use Friendica\Util\DateTimeFormat;
|
||||||
*/
|
*/
|
||||||
class Worker
|
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_STARTUP = 1; // Worker is in startup. This takes most time.
|
||||||
const STATE_LONG_LOOP = 2; // Worker is processing the whole - long - loop.
|
const STATE_LONG_LOOP = 2; // Worker is processing the whole - long - loop.
|
||||||
const STATE_REFETCH = 3; // Worker had refetched jobs in the execution loop.
|
const STATE_REFETCH = 3; // Worker had refetched jobs in the execution loop.
|
||||||
|
|
|
@ -77,6 +77,8 @@ class Cron
|
||||||
['order' => ['priority', 'retrial', 'created']]
|
['order' => ['priority', 'retrial', 'created']]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$max_duration_defaults = DI::config()->get('system', 'worker_max_duration');
|
||||||
|
|
||||||
while ($entry = DBA::fetch($entries)) {
|
while ($entry = DBA::fetch($entries)) {
|
||||||
if (!posix_kill($entry["pid"], 0)) {
|
if (!posix_kill($entry["pid"], 0)) {
|
||||||
DBA::update('workerqueue', ['executed' => DBA::NULL_DATETIME, 'pid' => 0], ['id' => $entry["id"]]);
|
DBA::update('workerqueue', ['executed' => DBA::NULL_DATETIME, 'pid' => 0], ['id' => $entry["id"]]);
|
||||||
|
@ -84,8 +86,10 @@ class Cron
|
||||||
// Kill long running processes
|
// Kill long running processes
|
||||||
|
|
||||||
// Define the maximum durations
|
// 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']] ?? 0;
|
||||||
$max_duration = $max_duration_defaults[$entry['priority']];
|
if (empty($max_duration)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$argv = json_decode($entry['parameter'], true);
|
$argv = json_decode($entry['parameter'], true);
|
||||||
if (!empty($entry['command'])) {
|
if (!empty($entry['command'])) {
|
||||||
|
|
|
@ -650,6 +650,16 @@ return [
|
||||||
// Setting 0 would allow maximum worker queues at all times, which is not recommended.
|
// Setting 0 would allow maximum worker queues at all times, which is not recommended.
|
||||||
'worker_load_exponent' => 3,
|
'worker_load_exponent' => 3,
|
||||||
|
|
||||||
|
// worker_max_duration (Array)
|
||||||
|
// Maximum runtime per priority. Worker processes that exceed this runtime will be terminated.
|
||||||
|
'worker_max_duration' => [
|
||||||
|
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)
|
// worker_processes_cooldown (Integer)
|
||||||
// Maximum number per processes that causes a cooldown before each worker function call.
|
// Maximum number per processes that causes a cooldown before each worker function call.
|
||||||
'worker_processes_cooldown' => 0,
|
'worker_processes_cooldown' => 0,
|
||||||
|
|
Loading…
Reference in a new issue