From 70c08dee1dfa6960a611961e8ff23fffb7e15177 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 5 Nov 2017 15:28:55 +0000 Subject: [PATCH] Some more improvements --- boot.php | 13 ++++++++++++- include/poller.php | 10 ---------- src/Core/Worker.php | 27 +++++++++++++++++++-------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/boot.php b/boot.php index d8659805dc..35c37d715e 100644 --- a/boot.php +++ b/boot.php @@ -22,7 +22,6 @@ require_once(__DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'a use Friendica\App; use Friendica\Core\System; -use Friendica\Core\Worker; use Friendica\Core\Config; use Friendica\Util\Lock; @@ -1030,6 +1029,18 @@ function get_max_import_size() { return ((x($a->config, 'max_import_size')) ? $a->config['max_import_size'] : 0 ); } +/** + * @brief compatibilty wrapper for Worker::add function + * + * @param (integer|array) priority or parameter array, $cmd atrings are deprecated and are ignored + * + * @return boolean "false" if proc_run couldn't be executed + */ +function proc_run() { + $proc_args = func_get_args(); + call_user_func_array('Friendica\Core\Worker::add', $proc_args); +} + function current_theme() { $app_base_themes = array('duepuntozero', 'dispy', 'quattro'); diff --git a/include/poller.php b/include/poller.php index 6eb04971c3..3f6290a98f 100644 --- a/include/poller.php +++ b/include/poller.php @@ -42,17 +42,7 @@ function poller_run($argv, $argc) { load_hooks(); - // At first check the maximum load. We shouldn't continue with a high load - if ($a->maxload_reached()) { - logger('Pre check: maximum load reached, quitting.', LOGGER_DEBUG); - return; - } - - // We now start the process. This is done after the load check since this could increase the load. - $a->start_process(); - $run_cron = (($argc <= 1) || ($argv[1] != "no_cron")); - Worker::processQueue($run_cron); return; } diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 5964f44046..ac5c04a271 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -4,6 +4,7 @@ namespace Friendica\Core; use Friendica\App; use Friendica\Core\System; use Friendica\Core\Config; +use Friendica\Core\Worker; use Friendica\Util\Lock; use dba; @@ -34,6 +35,15 @@ class Worker { self::$up_start = microtime(true); + // At first check the maximum load. We shouldn't continue with a high load + if ($a->maxload_reached()) { + logger('Pre check: maximum load reached, quitting.', LOGGER_DEBUG); + return; + } + + // We now start the process. This is done after the load check since this could increase the load. + $a->start_process(); + // Kill stale processes every 5 minutes $last_cleanup = Config::get('system', 'poller_last_cleaned', 0); if (time() > ($last_cleanup + 300)) { @@ -589,8 +599,7 @@ class Worker { // Are there fewer workers running as possible? Then fork a new one. if (!Config::get("system", "worker_dont_fork") && ($queues > ($active + 1)) && ($entries > 1)) { logger("Active workers: ".$active."/".$queues." Fork a new worker.", LOGGER_DEBUG); - $args = array("include/poller.php", "no_cron"); - get_app()->proc_run($args); + self::spawnWorker(); } } @@ -603,7 +612,7 @@ class Worker { * @return integer Number of active poller processes */ private static function activeWorkers() { - $workers = q("SELECT COUNT(*) AS `processes` FROM `process` WHERE `command` = 'poller.php'"); + $workers = q("SELECT COUNT(*) AS `processes` FROM `process` WHERE `command` = 'Worker.php'"); return $workers[0]["processes"]; } @@ -821,9 +830,7 @@ class Worker { self::runCron(); logger('Call poller', LOGGER_DEBUG); - - $args = array("include/poller.php", "no_cron"); - get_app()->proc_run($args); + self::spawnWorker(); return; } @@ -871,6 +878,11 @@ class Worker { self::killStaleWorkers(); } + public static function spawnWorker() { + $args = array("include/poller.php", "no_cron"); + get_app()->proc_run($args); + } + /** * @brief Adds tasks to the worker queue * @@ -973,8 +985,7 @@ class Worker { } // Now call the poller to execute the jobs that we just added to the queue - $args = array("include/poller.php", "no_cron"); - get_app()->proc_run($args); + self::spawnWorker(); return true; }