Some more improvements

This commit is contained in:
Michael 2017-11-05 15:28:55 +00:00
parent 9039e60a06
commit 70c08dee1d
3 changed files with 31 additions and 19 deletions

View file

@ -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;
}