diff --git a/boot.php b/boot.php index 0e56e74400..679116212c 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_UNDEFINED', 0); +define('PRIORITY_SYSTEM', 10); +define('PRIORITY_HIGH', 20); +define('PRIORITY_MEDIUM', 30); +define('PRIORITY_LOW', 40); /* @}*/ @@ -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..ecdb9eb0d3 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`, `parameter` 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 => 10, 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"]." (".$pid["parameter"].") 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; }