1
1
Fork 0

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

@ -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');

View file

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

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