]> git.mxchange.org Git - friendica.git/commitdiff
New priority level for stale processes.
authorMichael Vogel <icarus@dabo.de>
Thu, 18 Aug 2016 10:33:17 +0000 (12:33 +0200)
committerMichael Vogel <icarus@dabo.de>
Thu, 18 Aug 2016 10:33:17 +0000 (12:33 +0200)
boot.php
include/poller.php

index ecaa73e6a3fe8cba02d6635990f420009c35ab5f..dea9b8e8cd955ed361473fd83ce961f91020336e 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -392,11 +392,12 @@ define ( 'GRAVITY_COMMENT',      6);
  * Process priority for the worker
  * @{
  */
-define('PRIORITY_UNDEFINED', 0);
-define('PRIORITY_SYSTEM',   10);
-define('PRIORITY_HIGH',     20);
-define('PRIORITY_MEDIUM',   30);
-define('PRIORITY_LOW',      40);
+define('PRIORITY_UNDEFINED',  0);
+define('PRIORITY_CRITICAL',  10);
+define('PRIORITY_HIGH',      20);
+define('PRIORITY_MEDIUM',    30);
+define('PRIORITY_LOW',       40);
+define('PRIORITY_NEGLIGIBLE',50);
 /* @}*/
 
 
@@ -1410,7 +1411,7 @@ function check_db() {
                $build = DB_UPDATE_VERSION;
        }
        if($build != DB_UPDATE_VERSION)
-               proc_run(PRIORITY_SYSTEM, 'include/dbupdate.php');
+               proc_run(PRIORITY_CRITICAL, 'include/dbupdate.php');
 
 }
 
index 1f4d25732e576584fe375a73a3553731e5b4d9fa..0835528717cbe81ab56b26d599e410a6f5a4756b 100644 (file)
@@ -232,11 +232,11 @@ function poller_kill_stale_workers() {
                        // 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)))
+                       if (!in_array($pid["priority"], array(PRIORITY_CRITICAL, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW, PRIORITY_NEGLIGIBLE)))
                                $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_defaults = array(PRIORITY_CRITICAL => 360, PRIORITY_HIGH => 10, PRIORITY_MEDIUM => 60, PRIORITY_LOW => 180, PRIORITY_NEGLIGIBLE => 360);
                        $max_duration = $max_duration_defaults[$pid["priority"]];
 
                        $argv = json_decode($pid["parameter"]);
@@ -254,7 +254,7 @@ function poller_kill_stale_workers() {
                                q("UPDATE `workerqueue` SET `executed` = '0000-00-00 00:00:00', `created` = '%s',
                                                        `priority` = %d, `pid` = 0 WHERE `pid` = %d",
                                        dbesc(datetime_convert()),
-                                       intval(PRIORITY_LOW),
+                                       intval(PRIORITY_NEGLIGIBLE),
                                        intval($pid["pid"]));
                        } else
                                logger("Worker process ".$pid["pid"]." (".implode(" ", $argv).") now runs for ".round($duration)." of ".$max_duration." allowed minutes. That's okay.", LOGGER_DEBUG);
@@ -294,12 +294,11 @@ function poller_too_much_workers() {
                        $s = q("SELECT `priority` FROM `workerqueue` WHERE `executed` = '0000-00-00 00:00:00' ORDER BY `priority` LIMIT 1");
                        $top_priority = $s[0]["priority"];
 
-                       $s = q("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE `priority` <= %d AND `executed` != '0000-00-00 00:00:00'",
+                       $s = q("SELECT `id` FROM `workerqueue` WHERE `priority` <= %d AND `executed` != '0000-00-00 00:00:00' LIMIT 1",
                                intval($top_priority));
-                       $high_running = $s[0]["total"];
+                       $high_running = dbm::is_result($s);
 
-                       /// @todo define maximum number of fastlanes
-                       if (($high_running == 0) AND ($top_priority != PRIORITY_UNDEFINED) AND ($top_priority < PRIORITY_LOW)) {
+                       if (!$high_running AND ($top_priority > PRIORITY_UNDEFINED) AND ($top_priority < PRIORITY_NEGLIGIBLE)) {
                                logger("There are jobs with priority ".$top_priority." waiting but none is executed. Open a fastlane.", LOGGER_DEBUG);
                                $queues = $active + 1;
                        }