Merge remote-tracking branch 'upstream/2019.03-RC' into worker2
[friendica.git/.git] / src / Core / Worker.php
index 7b661d8..b0b9fc2 100644 (file)
@@ -29,6 +29,7 @@ class Worker
        private static $db_duration_stat = 0;
        private static $lock_duration = 0;
        private static $last_update;
+       private static $mode = 0;
 
        /**
         * @brief Processes the tasks that are in the workerqueue table
@@ -92,6 +93,7 @@ class Worker
                }
 
                $starttime = time();
+               self::$mode = 1;
 
                // We fetch the next queue entry that is about to be executed
                while ($r = self::workerProcess()) {
@@ -109,9 +111,18 @@ class Worker
                                if (!self::getWaitingJobForPID() && Lock::acquire('worker_process', 0)) {
                                        self::findWorkerProcesses();
                                        Lock::release('worker_process');
+                                       self::$mode = 3;
                                }
                        }
 
+                       self::$mode = 4;
+
+                       // Quit the worker once every cron interval
+                       if (time() > ($starttime + Config::get('system', 'cron_interval'))) {
+                               Logger::log('Process lifetime reached, quitting.', Logger::DEBUG);
+                               return;
+                       }
+
                        // To avoid the quitting of multiple workers only one worker at a time will execute the check
                        if (Lock::acquire('worker', 0)) {
                                // Count active workers and compare them with a maximum value that depends on the load
@@ -129,12 +140,6 @@ class Worker
                                }
                                Lock::release('worker');
                        }
-
-                       // Quit the worker once every 5 minutes
-                       if (time() > ($starttime + 300)) {
-                               Logger::log('Process lifetime reached, quitting.', Logger::DEBUG);
-                               return;
-                       }
                }
 
                // Cleaning up. Possibly not needed, but it doesn't harm anything.
@@ -394,15 +399,16 @@ class Worker
                 * The execution time is the productive time.
                 * By changing parameters like the maximum number of workers we can check the effectivness.
                */
-               $dbtotal = number_format(self::$db_duration - (self::$db_duration_count + self::$db_duration_write + self::$db_duration_stat), 4);
-               $dbcount = number_format(self::$db_duration_count, 4);
-               $dbstat  = number_format(self::$db_duration_stat, 4);
-               $dbwrite = number_format(self::$db_duration_write, 4);
-               $dblock  = number_format(self::$lock_duration, 4);
-               $rest    = number_format(max(0, $up_duration - (self::$db_duration + self::$lock_duration)), 4);
-               $exec    = number_format($duration, 4);
+               $dbtotal = round(self::$db_duration, 2);
+               $dbread  = round(self::$db_duration - (self::$db_duration_count + self::$db_duration_write + self::$db_duration_stat), 2);
+               $dbcount = round(self::$db_duration_count, 2);
+               $dbstat  = round(self::$db_duration_stat, 2);
+               $dbwrite = round(self::$db_duration_write, 2);
+               $dblock  = round(self::$lock_duration, 2);
+               $rest    = round(max(0, $up_duration - (self::$db_duration + self::$lock_duration)), 2);
+               $exec    = round($duration, 2);
 
-               $logger->info('Performance log.', ['total' => $dbtotal, 'count' => $dbcount, 'stat' => $dbstat, 'write' => $dbwrite, 'block' => $dblock, 'rest' => $rest, 'exec' => $exec]);
+               $logger->info('Performance log.', ['mode' => self::$mode, 'count' => $dbcount, 'stat' => $dbstat, 'write' => $dbwrite, 'lock' => $dblock, 'total' => $dbtotal, 'rest' => $rest, 'exec' => $exec]);
 
                self::$up_start = microtime(true);
                self::$db_duration = 0;
@@ -410,6 +416,7 @@ class Worker
                self::$db_duration_stat = 0;
                self::$db_duration_write = 0;
                self::$lock_duration = 0;
+               self::$mode = 2;
 
                if ($duration > 3600) {
                        $logger->info('Longer than 1 hour.', ['priority' => $queue["priority"], 'id' => $queue["id"], 'duration' =>   round($duration/60, 3)]);