1
1
Fork 0

Process timeouts are now priority depending

This commit is contained in:
Michael Vogel 2016-08-08 19:20:40 +02:00
parent cdc5b609ce
commit 29168de677
2 changed files with 21 additions and 9 deletions

View file

@ -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');
}

View file

@ -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;
}