From 29168de677925941a87c907c18f6dac6fab772dd Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Mon, 8 Aug 2016 19:20:40 +0200 Subject: [PATCH] Process timeouts are now priority depending --- boot.php | 10 ++++++---- include/poller.php | 20 +++++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/boot.php b/boot.php index 0e56e74400..9d63ebed77 100644 --- a/boot.php +++ b/boot.php @@ -392,9 +392,11 @@ define ( 'GRAVITY_COMMENT', 6); * Process priority for the worker * @{ */ -define('PRIORITY_HIGH', 1); -define('PRIORITY_MEDIUM', 2); -define('PRIORITY_LOW', 3); +define('PRIORITY_SYSTEM', -1); +define('PRIORITY_UNDEFINED', 0); +define('PRIORITY_HIGH', 1); +define('PRIORITY_MEDIUM', 2); +define('PRIORITY_LOW', 3); /* @}*/ @@ -1396,7 +1398,7 @@ function check_db() { $build = DB_UPDATE_VERSION; } if($build != DB_UPDATE_VERSION) - proc_run(PRIORITY_HIGH, 'include/dbupdate.php'); + proc_run(PRIORITY_SYSTEM, 'include/dbupdate.php'); } diff --git a/include/poller.php b/include/poller.php index 73950e35b2..d838df7797 100644 --- a/include/poller.php +++ b/include/poller.php @@ -217,7 +217,7 @@ function poller_max_connections_reached() { * */ function poller_kill_stale_workers() { - $r = q("SELECT `pid`, `executed` FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'"); + $r = q("SELECT `pid`, `executed`, `priority` FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'"); if (!dbm::is_result($r)) { // No processing here needed @@ -230,9 +230,19 @@ function poller_kill_stale_workers() { intval($pid["pid"])); else { // Kill long running processes + + // Check if the priority is in a valid range + if (!in_array($pid["priority"], array(PRIORITY_SYSTEM, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW))) + $pid["priority"] = PRIORITY_MEDIUM; + + // Define the maximum durations + $max_duration_defaults = array(PRIORITY_SYSTEM => 360, PRIORITY_HIGH => 5, PRIORITY_MEDIUM => 60, PRIORITY_LOW => 180); + $max_duration = $max_duration_defaults[$pid["priority"]]; + + // How long is the process already running? $duration = (time() - strtotime($pid["executed"])) / 60; - if ($duration > 180) { - logger("Worker process ".$pid["pid"]." took more than 3 hours. It will be killed now."); + if ($duration > $max_duration) { + logger("Worker process ".$pid["pid"]." took more than ".$max_duration." minutes. It will be killed now."); posix_kill($pid["pid"], SIGTERM); // We killed the stale process. @@ -244,7 +254,7 @@ function poller_kill_stale_workers() { intval(PRIORITY_LOW), intval($pid["pid"])); } else - logger("Worker process ".$pid["pid"]." now runs for ".round($duration)." minutes. That's okay.", LOGGER_DEBUG); + logger("Worker process ".$pid["pid"]." now runs for ".round($duration)." of ".$max_duration." allowed minutes. That's okay.", LOGGER_DEBUG); } } @@ -286,7 +296,7 @@ function poller_too_much_workers() { $high_running = $s[0]["total"]; /// @todo define maximum number of fastlanes - if (($high_running == 0) AND ($top_priority >= PRIORITY_HIGH) AND ($top_priority < PRIORITY_LOW)) { + if (($high_running == 0) AND ($top_priority != PRIORITY_UNDEFINED) AND ($top_priority < PRIORITY_LOW)) { logger("There are jobs with priority ".$top_priority." waiting but none is executed. Open a fastlane.", LOGGER_DEBUG); $queues = $active + 1; }