]> git.mxchange.org Git - friendica.git/commitdiff
Process timeouts are now priority depending
authorMichael Vogel <icarus@dabo.de>
Mon, 8 Aug 2016 17:20:40 +0000 (19:20 +0200)
committerMichael Vogel <icarus@dabo.de>
Mon, 8 Aug 2016 17:20:40 +0000 (19:20 +0200)
boot.php
include/poller.php

index 0e56e74400ce189bbe1a98ec98bd8f2956da88ae..9d63ebed77d8b7cf466f1fcc4ae0048babc0bba9 100644 (file)
--- 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');
 
 }
 
index 73950e35b20f72a56238672f8ecace3e7bef130e..d838df77973e55819f2c4459ced8df6794ca4816 100644 (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;
                        }