X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FWorker.php;h=1cde61351c0f2fc0ce9a30fdc1f2b694b3226b70;hb=98dd15ec9a79a59ea44520c9094de4ab2372e34e;hp=48984f6d82dfb8611028d6ea47d0f4ed82b40451;hpb=5e0b4b8a8f39f28fcfc2812e66223d95c92431a0;p=friendica.git diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 48984f6d82..1cde61351c 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -81,27 +81,8 @@ class Worker self::killStaleWorkers(); } - // Count active workers and compare them with a maximum value that depends on the load - if (self::tooMuchWorkers()) { - Logger::info('Pre check: Active worker limit reached, quitting.'); - return; - } - - // Do we have too few memory? - if (DI::process()->isMinMemoryReached()) { - Logger::info('Pre check: Memory limit reached, quitting.'); - return; - } - - // Possibly there are too much database connections - if (self::maxConnectionsReached()) { - Logger::info('Pre check: maximum connections reached, quitting.'); - return; - } - - // Possibly there are too much database processes that block the system - if (DI::process()->isMaxProcessesReached()) { - Logger::info('Pre check: maximum processes reached, quitting.'); + // Check if the system is ready + if (!self::isReady()) { return; } @@ -174,13 +155,49 @@ class Worker Logger::info("Couldn't select a workerqueue entry, quitting process", ['pid' => getmypid()]); } + /** + * Checks if the system is ready. + * + * Several system parameters like memory, connections and processes are checked. + * + * @return boolean + */ + public static function isReady() + { + // Count active workers and compare them with a maximum value that depends on the load + if (self::tooMuchWorkers()) { + Logger::info('Active worker limit reached, quitting.'); + return false; + } + + // Do we have too few memory? + if (DI::process()->isMinMemoryReached()) { + Logger::info('Memory limit reached, quitting.'); + return false; + } + + // Possibly there are too much database connections + if (self::maxConnectionsReached()) { + Logger::info('Maximum connections reached, quitting.'); + return false; + } + + // Possibly there are too much database processes that block the system + if (DI::process()->isMaxProcessesReached()) { + Logger::info('Maximum processes reached, quitting.'); + return false; + } + + return true; + } + /** * Check if non executed tasks do exist in the worker queue * * @return boolean Returns "true" if tasks are existing * @throws \Exception */ - private static function entriesExists() + public static function entriesExists() { $stamp = (float)microtime(true); $exists = DBA::exists('workerqueue', ["NOT `done` AND `pid` = 0 AND `next_try` < ?", DateTimeFormat::utcNow()]); @@ -733,7 +750,7 @@ class Worker } } - Logger::log("Load: " . $load ."/" . $maxsysload . " - processes: " . $deferred . "/" . $active . "/" . $waiting_processes . $processlist . " - maximum: " . $queues . "/" . $maxqueues, Logger::DEBUG); + Logger::notice("Load: " . $load ."/" . $maxsysload . " - processes: " . $deferred . "/" . $active . "/" . $waiting_processes . $processlist . " - maximum: " . $queues . "/" . $maxqueues); // Are there fewer workers running as possible? Then fork a new one. if (!DI::config()->get("system", "worker_dont_fork", false) && ($queues > ($active + 1)) && self::entriesExists()) {