]> git.mxchange.org Git - friendica.git/commitdiff
The setting "worker_fetch_limit" now only has an impact on high priority processes
authorMichael <heluecht@pirati.ca>
Thu, 14 Feb 2019 06:53:04 +0000 (06:53 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 14 Feb 2019 06:53:04 +0000 (06:53 +0000)
src/Core/Worker.php

index a6fee3bb6b1ba9d6d42341a1dfda6eb14ec1efa9..8b1509041687cf4d1e5ca2211b0156995dcd95eb 100644 (file)
@@ -448,7 +448,7 @@ class Worker
                        Logger::log("Prio ".$queue["priority"].": ".$queue["parameter"]." - longer than 2 minutes (".round($duration/60, 3).")", Logger::DEBUG);
                }
 
-               Logger::log("Process ".$mypid." - Prio ".$queue["priority"]." - ID ".$queue["id"].": ".$funcname." - done in ".$duration." seconds. Process PID: ".$new_process_id);
+               Logger::log("Process ".$mypid." - Prio ".$queue["priority"]." - ID ".$queue["id"].": ".$funcname." - done in ".number_format($duration, 4)." seconds. Process PID: ".$new_process_id);
 
                // Write down the performance values into the log
                if (Config::get("system", "profiler")) {
@@ -930,7 +930,7 @@ class Worker
                                ['id'],
                                ["`pid` = 0 AND `priority` < ? AND NOT `done` AND `next_try` < ?",
                                $highest_priority, DateTimeFormat::utcNow()],
-                               ['limit' => $limit, 'order' => ['priority', 'created']]
+                               ['limit' => 1, 'order' => ['priority', 'created']]
                        );
                        self::$db_duration += (microtime(true) - $stamp);
 
@@ -949,7 +949,7 @@ class Worker
                                        ['id'],
                                        ["`pid` = 0 AND `priority` > ? AND NOT `done` AND `next_try` < ?",
                                        $highest_priority, DateTimeFormat::utcNow()],
-                                       ['limit' => $limit, 'order' => ['priority', 'created']]
+                                       ['limit' => 1, 'order' => ['priority', 'created']]
                                );
                                self::$db_duration += (microtime(true) - $stamp);
 
@@ -963,6 +963,26 @@ class Worker
                        }
                }
 
+               // At first try to fetch a bunch of high or medium tasks
+               if (!$found && ($limit > 1)) {
+                       $stamp = (float)microtime(true);
+                       $result = DBA::select(
+                               'workerqueue',
+                               ['id'],
+                               ["`pid` = 0 AND NOT `done` AND `priority` <= ? AND `next_try` < ? AND `retrial` = 0",
+                               PRIORITY_MEDIUM, DateTimeFormat::utcNow()],
+                               ['limit' => $limit, 'order' => ['created']]
+                       );
+                       self::$db_duration += (microtime(true) - $stamp);
+
+                       while ($id = DBA::fetch($result)) {
+                               $ids[] = $id["id"];
+                       }
+                       DBA::close($result);
+
+                       $found = (count($ids) > 0);
+               }
+
                // If there is no result (or we shouldn't pass lower processes) we check without priority limit
                if (!$found) {
                        $stamp = (float)microtime(true);
@@ -971,7 +991,7 @@ class Worker
                                ['id'],
                                ["`pid` = 0 AND NOT `done` AND `next_try` < ?",
                                DateTimeFormat::utcNow()],
-                               ['limit' => $limit, 'order' => ['priority', 'created']]
+                               ['limit' => 1, 'order' => ['priority', 'created']]
                        );
                        self::$db_duration += (microtime(true) - $stamp);