From 38f70cc55ad1d99b011fa92b42361c39ecceb2e3 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 24 Oct 2021 20:43:59 +0200 Subject: [PATCH 01/14] Refactor Process for new paradigm --- bin/daemon.php | 2 +- bin/worker.php | 8 +- src/App.php | 12 +- src/Core/Process.php | 274 ------------------ src/Core/System.php | 193 +++++++++++- src/Core/Worker.php | 48 +-- src/Core/Worker/Entity/Process.php | 46 +++ .../Exception/ProcessPersistenceException.php | 13 + src/Core/Worker/Factory/Process.php | 38 +++ src/Core/Worker/Repository/Process.php | 118 ++++++++ src/DI.php | 16 +- src/Model/Process.php | 91 ------ static/dependencies.config.php | 3 +- tests/src/Model/ProcessTest.php | 85 ------ 14 files changed, 456 insertions(+), 491 deletions(-) delete mode 100644 src/Core/Process.php create mode 100644 src/Core/Worker/Entity/Process.php create mode 100644 src/Core/Worker/Exception/ProcessPersistenceException.php create mode 100644 src/Core/Worker/Factory/Process.php create mode 100644 src/Core/Worker/Repository/Process.php delete mode 100644 src/Model/Process.php delete mode 100644 tests/src/Model/ProcessTest.php diff --git a/bin/daemon.php b/bin/daemon.php index 7d4945fe0..490a92ab8 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -196,7 +196,7 @@ while (true) { $do_cron = true; } - if ($do_cron || (!DI::process()->isMaxLoadReached() && Worker::entriesExists() && Worker::isReady())) { + if ($do_cron || (!DI::system()->isMaxLoadReached() && Worker::entriesExists() && Worker::isReady())) { Worker::spawnWorker($do_cron); } else { Logger::info('Cool down for 5 seconds', ['pid' => $pid]); diff --git a/bin/worker.php b/bin/worker.php index 2fe03cb4b..13018b49d 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -81,8 +81,10 @@ if ($spawn) { $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options); -Worker::processQueue($run_cron); +$process = DI::process()->create(getmypid()); -Worker::unclaimProcess(); +Worker::processQueue($run_cron, $process); -DI::process()->end(); +Worker::unclaimProcess($process); + +DI::process()->delete($process); diff --git a/src/App.php b/src/App.php index dd8488388..41ca22229 100644 --- a/src/App.php +++ b/src/App.php @@ -118,9 +118,9 @@ class App private $args; /** - * @var Core\Process The process methods + * @var Core\System The system methods */ - private $process; + private $system; /** * @var IManagePersonalConfigValues @@ -327,10 +327,10 @@ class App * @param Profiler $profiler The profiler of this application * @param L10n $l10n The translator instance * @param App\Arguments $args The Friendica Arguments of the call - * @param Core\Process $process The process methods + * @param Core\System $system The system methods * @param IManagePersonalConfigValues $pConfig Personal configuration */ - public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, Core\Process $process, IManagePersonalConfigValues $pConfig) + public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, Core\System $system, IManagePersonalConfigValues $pConfig) { $this->database = $database; $this->config = $config; @@ -340,7 +340,7 @@ class App $this->logger = $logger; $this->l10n = $l10n; $this->args = $args; - $this->process = $process; + $this->system = $system; $this->pConfig = $pConfig; $this->load(); @@ -589,7 +589,7 @@ class App } // Max Load Average reached: ERROR - if ($this->process->isMaxProcessesReached() || $this->process->isMaxLoadReached()) { + if ($this->system->isMaxProcessesReached() || $this->system->isMaxLoadReached()) { header('Retry-After: 120'); header('Refresh: 120; url=' . $this->baseURL->get() . "/" . $this->args->getQueryString()); diff --git a/src/Core/Process.php b/src/Core/Process.php deleted file mode 100644 index 8bde3cc3d..000000000 --- a/src/Core/Process.php +++ /dev/null @@ -1,274 +0,0 @@ -. - * - */ - -namespace Friendica\Core; - -use Friendica\App; -use Friendica\Core\Config\Capability\IManageConfigValues; -use Friendica\Model; -use Psr\Log\LoggerInterface; - -/** - * Methods for interacting with the current process or create new process - * - * @todo 2019.12 Next release, this class holds all process relevant methods based on the big Worker class - * - Starting new processes (including checks) - * - Enabling multi-node processing (e.g. for docker service) - * - Using an process-id per node - * - Using memory locks for multi-node locking (redis, memcached, ..) - */ -class Process -{ - /** - * @var LoggerInterface - */ - private $logger; - - /** - * @var App\Mode - */ - private $mode; - - /** - * @var IManageConfigValues - */ - private $config; - - /** - * @var string - */ - private $basePath; - - /** @var Model\Process */ - private $processModel; - - /** - * The Process ID of this process - * - * @var int - */ - private $pid; - - public function __construct(LoggerInterface $logger, App\Mode $mode, IManageConfigValues $config, Model\Process $processModel, string $basepath, int $pid) - { - $this->logger = $logger; - $this->mode = $mode; - $this->config = $config; - $this->basePath = $basepath; - $this->processModel = $processModel; - $this->pid = $pid; - } - - /** - * Set the process id - * - * @param integer $pid - * @return void - */ - public function setPid(int $pid) - { - $this->pid = $pid; - } - - /** - * Log active processes into the "process" table - */ - public function start() - { - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); - - $command = basename($trace[0]['file']); - - $this->processModel->deleteInactive(); - $this->processModel->insert($command, $this->pid); - } - - /** - * Remove the active process from the "process" table - * - * @return bool - * @throws \Exception - */ - public function end() - { - return $this->processModel->deleteByPid($this->pid); - } - - /** - * Checks if the maximum number of database processes is reached - * - * @return bool Is the limit reached? - */ - public function isMaxProcessesReached() - { - // Deactivated, needs more investigating if this check really makes sense - return false; - - /* - * Commented out to suppress static analyzer issues - * - if ($this->mode->isBackend()) { - $process = 'backend'; - $max_processes = $this->config->get('system', 'max_processes_backend'); - if (intval($max_processes) == 0) { - $max_processes = 5; - } - } else { - $process = 'frontend'; - $max_processes = $this->config->get('system', 'max_processes_frontend'); - if (intval($max_processes) == 0) { - $max_processes = 20; - } - } - - $processlist = DBA::processlist(); - if ($processlist['list'] != '') { - $this->logger->debug('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list']); - - if ($processlist['amount'] > $max_processes) { - $this->logger->debug('Processcheck: Maximum number of processes for ' . $process . ' tasks (' . $max_processes . ') reached.'); - return true; - } - } - return false; - */ - } - - /** - * Checks if the minimal memory is reached - * - * @return bool Is the memory limit reached? - */ - public function isMinMemoryReached() - { - $min_memory = $this->config->get('system', 'min_memory', 0); - if ($min_memory == 0) { - return false; - } - - if (!is_readable('/proc/meminfo')) { - return false; - } - - $memdata = explode("\n", file_get_contents('/proc/meminfo')); - - $meminfo = []; - foreach ($memdata as $line) { - $data = explode(':', $line); - if (count($data) != 2) { - continue; - } - [$key, $val] = $data; - $meminfo[$key] = (int)trim(str_replace('kB', '', $val)); - $meminfo[$key] = (int)($meminfo[$key] / 1024); - } - - if (!isset($meminfo['MemFree'])) { - return false; - } - - $free = $meminfo['MemFree']; - - $reached = ($free < $min_memory); - - if ($reached) { - $this->logger->warning('Minimal memory reached.', ['free' => $free, 'memtotal' => $meminfo['MemTotal'], 'limit' => $min_memory]); - } - - return $reached; - } - - /** - * Checks if the maximum load is reached - * - * @return bool Is the load reached? - */ - public function isMaxLoadReached() - { - if ($this->mode->isBackend()) { - $process = 'backend'; - $maxsysload = intval($this->config->get('system', 'maxloadavg')); - if ($maxsysload < 1) { - $maxsysload = 50; - } - } else { - $process = 'frontend'; - $maxsysload = intval($this->config->get('system', 'maxloadavg_frontend')); - if ($maxsysload < 1) { - $maxsysload = 50; - } - } - - $load = System::currentLoad(); - if ($load) { - if (intval($load) > $maxsysload) { - $this->logger->warning('system load for process too high.', ['load' => $load, 'process' => $process, 'maxsysload' => $maxsysload]); - return true; - } - } - return false; - } - - /** - * Executes a child process with 'proc_open' - * - * @param string $command The command to execute - * @param array $args Arguments to pass to the command ( [ 'key' => value, 'key2' => value2, ... ] - */ - public function run($command, $args) - { - if (!function_exists('proc_open')) { - $this->logger->warning('"proc_open" not available - quitting'); - return; - } - - $cmdline = $this->config->get('config', 'php_path', 'php') . ' ' . escapeshellarg($command); - - foreach ($args as $key => $value) { - if (!is_null($value) && is_bool($value) && !$value) { - continue; - } - - $cmdline .= ' --' . $key; - if (!is_null($value) && !is_bool($value)) { - $cmdline .= ' ' . $value; - } - } - - if ($this->isMinMemoryReached()) { - $this->logger->warning('Memory limit reached - quitting'); - return; - } - - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { - $resource = proc_open('cmd /c start /b ' . $cmdline, [], $foo, $this->basePath); - } else { - $resource = proc_open($cmdline . ' &', [], $foo, $this->basePath); - } - if (!is_resource($resource)) { - $this->logger->warning('We got no resource for command.', ['command' => $cmdline]); - return; - } - proc_close($resource); - - $this->logger->info('Executed "proc_open"', ['command' => $cmdline, 'callstack' => System::callstack(10)]); - } -} diff --git a/src/Core/System.php b/src/Core/System.php index 2cc9a48bc..321fb3d6f 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -22,18 +22,209 @@ namespace Friendica\Core; use Exception; +use Friendica\App; +use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\DI; use Friendica\Network\HTTPException\FoundException; use Friendica\Network\HTTPException\MovedPermanentlyException; use Friendica\Network\HTTPException\TemporaryRedirectException; use Friendica\Util\BasePath; use Friendica\Util\XML; +use Psr\Log\LoggerInterface; /** * Contains the class with system relevant stuff */ class System { + /** + * @var LoggerInterface + */ + private $logger; + + /** + * @var App\Mode + */ + private $mode; + + /** + * @var IManageConfigValues + */ + private $config; + + /** + * @var string + */ + private $basePath; + + public function __construct(LoggerInterface $logger, App\Mode $mode, IManageConfigValues $config, string $basepath) + { + $this->logger = $logger; + $this->mode = $mode; + $this->config = $config; + $this->basePath = $basepath; + } + + /** + * Checks if the maximum number of database processes is reached + * + * @return bool Is the limit reached? + */ + public function isMaxProcessesReached(): bool + { + // Deactivated, needs more investigating if this check really makes sense + return false; + + /* + * Commented out to suppress static analyzer issues + * + if ($this->mode->isBackend()) { + $process = 'backend'; + $max_processes = $this->config->get('system', 'max_processes_backend'); + if (intval($max_processes) == 0) { + $max_processes = 5; + } + } else { + $process = 'frontend'; + $max_processes = $this->config->get('system', 'max_processes_frontend'); + if (intval($max_processes) == 0) { + $max_processes = 20; + } + } + + $processlist = DBA::processlist(); + if ($processlist['list'] != '') { + $this->logger->debug('Processcheck: Processes: ' . $processlist['amount'] . ' - Processlist: ' . $processlist['list']); + + if ($processlist['amount'] > $max_processes) { + $this->logger->debug('Processcheck: Maximum number of processes for ' . $process . ' tasks (' . $max_processes . ') reached.'); + return true; + } + } + return false; + */ + } + + /** + * Checks if the minimal memory is reached + * + * @return bool Is the memory limit reached? + */ + public function isMinMemoryReached(): bool + { + $min_memory = $this->config->get('system', 'min_memory', 0); + if ($min_memory == 0) { + return false; + } + + if (!is_readable('/proc/meminfo')) { + return false; + } + + $memdata = explode("\n", file_get_contents('/proc/meminfo')); + + $meminfo = []; + foreach ($memdata as $line) { + $data = explode(':', $line); + if (count($data) != 2) { + continue; + } + [$key, $val] = $data; + $meminfo[$key] = (int)trim(str_replace('kB', '', $val)); + $meminfo[$key] = (int)($meminfo[$key] / 1024); + } + + if (!isset($meminfo['MemFree'])) { + return false; + } + + $free = $meminfo['MemFree']; + + $reached = ($free < $min_memory); + + if ($reached) { + $this->logger->warning('Minimal memory reached.', ['free' => $free, 'memtotal' => $meminfo['MemTotal'], 'limit' => $min_memory]); + } + + return $reached; + } + + /** + * Checks if the maximum load is reached + * + * @return bool Is the load reached? + */ + public function isMaxLoadReached(): bool + { + if ($this->mode->isBackend()) { + $process = 'backend'; + $maxsysload = intval($this->config->get('system', 'maxloadavg')); + if ($maxsysload < 1) { + $maxsysload = 50; + } + } else { + $process = 'frontend'; + $maxsysload = intval($this->config->get('system', 'maxloadavg_frontend')); + if ($maxsysload < 1) { + $maxsysload = 50; + } + } + + $load = System::currentLoad(); + if ($load) { + if (intval($load) > $maxsysload) { + $this->logger->warning('system load for process too high.', ['load' => $load, 'process' => $process, 'maxsysload' => $maxsysload]); + return true; + } + } + return false; + } + + /** + * Executes a child process with 'proc_open' + * + * @param string $command The command to execute + * @param array $args Arguments to pass to the command ( [ 'key' => value, 'key2' => value2, ... ] + */ + public function run(string $command, array $args) + { + if (!function_exists('proc_open')) { + $this->logger->warning('"proc_open" not available - quitting'); + return; + } + + $cmdline = $this->config->get('config', 'php_path', 'php') . ' ' . escapeshellarg($command); + + foreach ($args as $key => $value) { + if (!is_null($value) && is_bool($value) && !$value) { + continue; + } + + $cmdline .= ' --' . $key; + if (!is_null($value) && !is_bool($value)) { + $cmdline .= ' ' . $value; + } + } + + if ($this->isMinMemoryReached()) { + $this->logger->warning('Memory limit reached - quitting'); + return; + } + + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + $resource = proc_open('cmd /c start /b ' . $cmdline, [], $foo, $this->basePath); + } else { + $resource = proc_open($cmdline . ' &', [], $foo, $this->basePath); + } + if (!is_resource($resource)) { + $this->logger->warning('We got no resource for command.', ['command' => $cmdline]); + return; + } + proc_close($resource); + + $this->logger->info('Executed "proc_open"', ['command' => $cmdline, 'callstack' => System::callstack(10)]); + } + /** * Returns a string with a callstack. Can be used for logging. * @@ -42,7 +233,7 @@ class System * this is called from a centralized method that isn't relevant to the callstack * @return string */ - public static function callstack(int $depth = 4, int $offset = 0) + public static function callstack(int $depth = 4, int $offset = 0): string { $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 3d1648ea4..cee1c6552 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -23,6 +23,7 @@ namespace Friendica\Core; use Friendica\App\Mode; use Friendica\Core; +use Friendica\Core\Worker\Entity\Process; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Util\DateTimeFormat; @@ -51,26 +52,29 @@ class Worker private static $last_update; private static $state; private static $daemon_mode = null; + /** @var Worker\Entity\Process */ + private static $process; /** * Processes the tasks that are in the workerqueue table * * @param boolean $run_cron Should the cron processes be executed? + * @param Process $process The current running process * @return void * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function processQueue($run_cron = true) + public static function processQueue($run_cron, Process $process) { self::$up_start = microtime(true); // At first check the maximum load. We shouldn't continue with a high load - if (DI::process()->isMaxLoadReached()) { + if (DI::system()->isMaxLoadReached()) { Logger::notice('Pre check: maximum load reached, quitting.'); return; } // We now start the process. This is done after the load check since this could increase the load. - DI::process()->start(); + self::$process = $process; // Kill stale processes every 5 minutes $last_cleanup = DI::config()->get('system', 'worker_last_cleaned', 0); @@ -134,7 +138,7 @@ class Worker } // Check free memory - if (DI::process()->isMinMemoryReached()) { + if (DI::system()->isMinMemoryReached()) { Logger::warning('Memory limit reached, quitting.'); DI::lock()->release(self::LOCK_WORKER); return; @@ -147,7 +151,7 @@ class Worker // Quit the worker once every cron interval if (time() > ($starttime + (DI::config()->get('system', 'cron_interval') * 60))) { Logger::info('Process lifetime reached, respawning.'); - self::unclaimProcess(); + self::unclaimProcess($process); if (self::isDaemonMode()) { self::IPCSetJobState(true); } else { @@ -180,7 +184,7 @@ class Worker } // Do we have too few memory? - if (DI::process()->isMinMemoryReached()) { + if (DI::system()->isMinMemoryReached()) { Logger::warning('Memory limit reached, quitting.'); return false; } @@ -192,7 +196,7 @@ class Worker } // Possibly there are too much database processes that block the system - if (DI::process()->isMaxProcessesReached()) { + if (DI::system()->isMaxProcessesReached()) { Logger::warning('Maximum processes reached, quitting.'); return false; } @@ -334,7 +338,7 @@ class Worker } // Constantly check the number of parallel database processes - if (DI::process()->isMaxProcessesReached()) { + if (DI::system()->isMaxProcessesReached()) { Logger::warning("Max processes reached for process", ['pid' => $mypid]); return false; } @@ -1105,15 +1109,15 @@ class Worker /** * Removes a workerqueue entry from the current process * + * @param Process $process the process behind the workerqueue + * * @return void * @throws \Exception */ - public static function unclaimProcess() + public static function unclaimProcess(Process $process) { - $mypid = getmypid(); - $stamp = (float)microtime(true); - DBA::update('workerqueue', ['executed' => DBA::NULL_DATETIME, 'pid' => 0], ['pid' => $mypid, 'done' => false]); + DBA::update('workerqueue', ['executed' => DBA::NULL_DATETIME, 'pid' => 0], ['pid' => $process->pid, 'done' => false]); self::$db_duration += (microtime(true) - $stamp); self::$db_duration_write += (microtime(true) - $stamp); } @@ -1146,7 +1150,7 @@ class Worker */ private static function forkProcess(bool $do_cron) { - if (DI::process()->isMinMemoryReached()) { + if (DI::system()->isMinMemoryReached()) { Logger::warning('Memory limit reached - quitting'); return; } @@ -1176,11 +1180,10 @@ class Worker } // We now are in the new worker - $pid = getmypid(); - DBA::connect(); + /// @todo Reinitialize the logger to set a new process_id and uid - DI::process()->setPid($pid); + $process = DI::process()->create($pid); $cycles = 0; while (!self::IPCJobsExists($pid) && (++$cycles < 100)) { @@ -1189,12 +1192,12 @@ class Worker Logger::info('Worker spawned', ['pid' => $pid, 'wait_cycles' => $cycles]); - self::processQueue($do_cron); + self::processQueue($do_cron, $process); - self::unclaimProcess(); + self::unclaimProcess($process); self::IPCSetJobState(false, $pid); - DI::process()->end(); + DI::process()->delete($process); Logger::info('Worker ended', ['pid' => $pid]); exit(); } @@ -1211,9 +1214,7 @@ class Worker if (self::isDaemonMode() && DI::config()->get('system', 'worker_fork')) { self::forkProcess($do_cron); } else { - $process = new Core\Process(DI::logger(), DI::mode(), DI::config(), - DI::modelProcess(), DI::app()->getBasePath(), getmypid()); - $process->run('bin/worker.php', ['no_cron' => !$do_cron]); + DI::system()->run('bin/worker.php', ['no_cron' => !$do_cron]); } if (self::isDaemonMode()) { self::IPCSetJobState(false); @@ -1571,8 +1572,7 @@ class Worker Logger::notice('Starting new daemon process'); $command = 'bin/daemon.php'; $a = DI::app(); - $process = new Core\Process(DI::logger(), DI::mode(), DI::config(), DI::modelProcess(), $a->getBasePath(), getmypid()); - $process->run($command, ['start']); + DI::system()->run($command, ['start']); Logger::notice('New daemon process started'); } diff --git a/src/Core/Worker/Entity/Process.php b/src/Core/Worker/Entity/Process.php new file mode 100644 index 000000000..57e385338 --- /dev/null +++ b/src/Core/Worker/Entity/Process.php @@ -0,0 +1,46 @@ +pid = $pid; + $this->command = $command; + $this->created = $created; + } + + /** + * Returns a new Process with the given PID + * + * @param int $pid + * + * @return $this + * @throws \Exception + */ + public function withPid(int $pid): Process + { + return new static($pid, $this->command, new DateTime('now', new \DateTimeZone('URC'))); + } +} diff --git a/src/Core/Worker/Exception/ProcessPersistenceException.php b/src/Core/Worker/Exception/ProcessPersistenceException.php new file mode 100644 index 000000000..c1c34453a --- /dev/null +++ b/src/Core/Worker/Exception/ProcessPersistenceException.php @@ -0,0 +1,13 @@ +createFromTableRow([ + 'pid' => $pid, + 'command' => $command, + ]); + } +} diff --git a/src/Core/Worker/Repository/Process.php b/src/Core/Worker/Repository/Process.php new file mode 100644 index 000000000..8fe1d709b --- /dev/null +++ b/src/Core/Worker/Repository/Process.php @@ -0,0 +1,118 @@ +. + * + */ + +namespace Friendica\Core\Worker\Repository; + +use Friendica\BaseRepository; +use Friendica\Core\Worker\Exception\ProcessPersistenceException; +use Friendica\Database\Database; +use Friendica\Util\DateTimeFormat; +use Friendica\Core\Worker\Factory; +use Friendica\Core\Worker\Entity; +use Psr\Log\LoggerInterface; + +/** + * functions for interacting with a process + */ +class Process extends BaseRepository +{ + protected static $table_name = 'process'; + + /** @var Factory\Process */ + protected $factory; + + public function __construct(Database $database, LoggerInterface $logger, Factory\Process $factory) + { + parent::__construct($database, $logger, $factory); + } + + /** + * Starts and Returns the process for a given PID + * + * @param int $pid + * + * @return Entity\Process + */ + public function create(int $pid): Entity\Process + { + // Cleanup inactive process + $this->deleteInactive(); + + try { + $this->db->transaction(); + + $newProcess = $this->factory->create($pid); + + if (!$this->db->exists('process', ['pid' => $pid])) { + if (!$this->db->insert(static::$table_name, [ + 'pid' => $newProcess->pid, + 'command' => $newProcess->command, + 'created' => $newProcess->created->format(DateTimeFormat::MYSQL) + ])) { + throw new ProcessPersistenceException(sprintf('The process with PID %s already exists.', $pid)); + } + } + + $result = $this->_selectOne(['pid' => $pid]); + + $this->db->commit(); + + return $result; + } catch (\Exception $exception) { + throw new ProcessPersistenceException(sprintf('Cannot save process with PID %s.', $pid), $exception); + } + } + + public function delete(Entity\Process $process) + { + try { + if (!$this->db->delete(static::$table_name, [ + 'pid' => $process->pid + ])) { + throw new ProcessPersistenceException(sprintf('The process with PID %s doesn\'t exists.', $process->pi)); + } + } catch (\Exception $exception) { + throw new ProcessPersistenceException(sprintf('Cannot delete process with PID %s.', $process->pid), $exception); + } + } + + /** + * Clean the process table of inactive physical processes + */ + private function deleteInactive() + { + $this->db->transaction(); + + try { + $processes = $this->db->select('process', ['pid']); + while ($process = $this->db->fetch($processes)) { + if (!posix_kill($process['pid'], 0)) { + $this->db->delete('process', ['pid' => $process['pid']]); + } + } + $this->db->close($processes); + } catch (\Exception $exception) { + throw new ProcessPersistenceException('Cannot delete inactive process', $exception); + } finally { + $this->db->commit(); + } + } +} diff --git a/src/DI.php b/src/DI.php index 823644784..b758ddab0 100644 --- a/src/DI.php +++ b/src/DI.php @@ -195,11 +195,11 @@ abstract class DI } /** - * @return Core\Process + * @return Core\Worker\Repository\Process */ public static function process() { - return self::$dice->create(Core\Process::class); + return self::$dice->create(Core\Worker\Repository\Process::class); } /** @@ -218,6 +218,14 @@ abstract class DI return self::$dice->create(Core\Storage\Repository\StorageManager::class); } + /** + * @return \Friendica\Core\System + */ + public static function system() + { + return self::$dice->create(Core\System::class); + } + // // "LoggerInterface" instances // @@ -379,11 +387,11 @@ abstract class DI // "Model" namespace instances // /** - * @return Model\Process + * @return \Friendica\Core\Worker\Repository\Process */ public static function modelProcess() { - return self::$dice->create(Model\Process::class); + return self::$dice->create(Core\Worker\Repository\Process::class); } /** diff --git a/src/Model/Process.php b/src/Model/Process.php deleted file mode 100644 index 94699d6ac..000000000 --- a/src/Model/Process.php +++ /dev/null @@ -1,91 +0,0 @@ -. - * - */ - -namespace Friendica\Model; - -use Friendica\Database\Database; -use Friendica\Util\DateTimeFormat; - -/** - * functions for interacting with a process - */ -class Process -{ - /** @var Database */ - private $dba; - - public function __construct(Database $dba) - { - $this->dba = $dba; - } - - /** - * Insert a new process row. If the pid parameter is omitted, we use the current pid - * - * @param string $command - * @param int $pid The process id to insert - * @return bool - * @throws \Exception - */ - public function insert(string $command, int $pid) - { - $return = true; - - $this->dba->transaction(); - - if (!$this->dba->exists('process', ['pid' => $pid])) { - $return = $this->dba->insert('process', ['pid' => $pid, 'command' => $command, 'created' => DateTimeFormat::utcNow()]); - } - - $this->dba->commit(); - - return $return; - } - - /** - * Remove a process row by pid. If the pid parameter is omitted, we use the current pid - * - * @param int $pid The pid to delete - * @return bool - * @throws \Exception - */ - public function deleteByPid(int $pid) - { - return $this->dba->delete('process', ['pid' => $pid]); - } - - /** - * Clean the process table of inactive physical processes - */ - public function deleteInactive() - { - $this->dba->transaction(); - - $processes = $this->dba->select('process', ['pid']); - while($process = $this->dba->fetch($processes)) { - if (!posix_kill($process['pid'], 0)) { - $this->deleteByPid($process['pid']); - } - } - $this->dba->close($processes); - $this->dba->commit(); - } -} diff --git a/static/dependencies.config.php b/static/dependencies.config.php index a43fb368a..46463de61 100644 --- a/static/dependencies.config.php +++ b/static/dependencies.config.php @@ -188,10 +188,9 @@ return [ ['determineModule', [], Dice::CHAIN_CALL], ], ], - Process::class => [ + \Friendica\Core\System::class => [ 'constructParams' => [ [Dice::INSTANCE => '$basepath'], - getmypid(), ], ], App\Router::class => [ diff --git a/tests/src/Model/ProcessTest.php b/tests/src/Model/ProcessTest.php deleted file mode 100644 index d3ef38df9..000000000 --- a/tests/src/Model/ProcessTest.php +++ /dev/null @@ -1,85 +0,0 @@ -setUpVfsDir(); - - $logger = new NullLogger(); - - $profiler = \Mockery::mock(Profiler::class); - $profiler->shouldReceive('startRecording'); - $profiler->shouldReceive('stopRecording'); - $profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true); - - // load real config to avoid mocking every config-entry which is related to the Database class - $configFactory = new Config(); - $loader = (new Config())->createConfigFileLoader($this->root->url(), []); - $configCache = $configFactory->createCache($loader); - - $this->dba = new StaticDatabase($configCache, $profiler, $logger); - } - - public function testInsertDelete() - { - $process = new Process($this->dba); - - self::assertEquals(0, $this->dba->count('process')); - $process->insert('test', 1); - $process->insert('test2', 2); - $process->insert('test3', 3); - - self::assertEquals(3, $this->dba->count('process')); - - self::assertEquals([ - ['command' => 'test'] - ], $this->dba->selectToArray('process', ['command'], ['pid' => 1])); - - $process->deleteByPid(1); - - self::assertEmpty($this->dba->selectToArray('process', ['command'], ['pid' => 1])); - - self::assertEquals(2, $this->dba->count('process')); - } - - public function testDoubleInsert() - { - $process = new Process($this->dba); - - $process->insert('test', 1); - - // double insert doesn't work - $process->insert('test23', 1); - - self::assertEquals([['command' => 'test']], $this->dba->selectToArray('process', ['command'], ['pid' => 1])); - } - - /** - * @doesNotPerformAssertions - */ - public function testWrongDelete() - { - $process = new Process($this->dba); - - // Just ignore wrong deletes, no execution is thrown - $process->deleteByPid(-1); - } -} From 7637ae1dcc7a1341a95a62a883f3b2e51b8c388b Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 31 Oct 2021 14:31:02 +0100 Subject: [PATCH 02/14] Fixup command argument --- src/Core/Worker.php | 2 +- src/Core/Worker/Entity/Process.php | 13 ------------- src/Core/Worker/Factory/Process.php | 9 +++------ src/Core/Worker/Repository/Process.php | 27 ++++++++++++++++++++++++-- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/Core/Worker.php b/src/Core/Worker.php index cee1c6552..d7133c0b7 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -846,7 +846,7 @@ class Worker private static function activeWorkers() { $stamp = (float)microtime(true); - $count = DBA::count('process', ['command' => 'Worker.php']); + $count = DI::process()->countCommand('Worker.php'); self::$db_duration += (microtime(true) - $stamp); self::$db_duration_count += (microtime(true) - $stamp); return $count; diff --git a/src/Core/Worker/Entity/Process.php b/src/Core/Worker/Entity/Process.php index 57e385338..7161f9ca4 100644 --- a/src/Core/Worker/Entity/Process.php +++ b/src/Core/Worker/Entity/Process.php @@ -30,17 +30,4 @@ class Process extends BaseEntity $this->command = $command; $this->created = $created; } - - /** - * Returns a new Process with the given PID - * - * @param int $pid - * - * @return $this - * @throws \Exception - */ - public function withPid(int $pid): Process - { - return new static($pid, $this->command, new DateTime('now', new \DateTimeZone('URC'))); - } } diff --git a/src/Core/Worker/Factory/Process.php b/src/Core/Worker/Factory/Process.php index 38985983b..1b6690689 100644 --- a/src/Core/Worker/Factory/Process.php +++ b/src/Core/Worker/Factory/Process.php @@ -20,16 +20,13 @@ class Process extends BaseFactory implements ICanCreateFromTableRow /** * Creates a new process entry for a given PID * - * @param int $pid + * @param int $pid + * @param string $command * * @return Entity\Process */ - public function create(int $pid): Entity\Process + public function create(int $pid, string $command): Entity\Process { - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1); - - $command = basename($trace[0]['file']); - return $this->createFromTableRow([ 'pid' => $pid, 'command' => $command, diff --git a/src/Core/Worker/Repository/Process.php b/src/Core/Worker/Repository/Process.php index 8fe1d709b..d14121b97 100644 --- a/src/Core/Worker/Repository/Process.php +++ b/src/Core/Worker/Repository/Process.php @@ -59,11 +59,16 @@ class Process extends BaseRepository try { $this->db->transaction(); - $newProcess = $this->factory->create($pid); + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + $last = $trace[count($trace) - 1]; + + $command = strtolower(basename($last['file'])); + + $newProcess = $this->factory->create($pid, $command); if (!$this->db->exists('process', ['pid' => $pid])) { if (!$this->db->insert(static::$table_name, [ - 'pid' => $newProcess->pid, + 'pid' => $newProcess->pid, 'command' => $newProcess->command, 'created' => $newProcess->created->format(DateTimeFormat::MYSQL) ])) { @@ -115,4 +120,22 @@ class Process extends BaseRepository $this->db->commit(); } } + + /** + * Returns the number of processes with a given command + * + * @param string $command + * + * @return int Number of processes + * + * @throws ProcessPersistenceException + */ + public function countCommand(string $command): int + { + try { + return $this->count(['command' => strtolower($command)]); + } catch (\Exception $exception) { + throw new ProcessPersistenceException('Cannot count ', $exception); + } + } } From 32f0c3fb9cab86e91d531ed52589a60796ca6eba Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 31 Oct 2021 20:15:57 +0100 Subject: [PATCH 03/14] Adds DI::flushLogger() to renew Logger instances --- src/Core/Worker.php | 2 +- src/DI.php | 12 ++++++++++++ static/dependencies.config.php | 1 - 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Core/Worker.php b/src/Core/Worker.php index d7133c0b7..faa29717c 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -1182,7 +1182,7 @@ class Worker // We now are in the new worker DBA::connect(); - /// @todo Reinitialize the logger to set a new process_id and uid + DI::flushLogger(); $process = DI::process()->create($pid); $cycles = 0; diff --git a/src/DI.php b/src/DI.php index b758ddab0..692d87870 100644 --- a/src/DI.php +++ b/src/DI.php @@ -230,6 +230,18 @@ abstract class DI // "LoggerInterface" instances // + /** + * Flushes the Logger instance, so the factory is called again + * (creates a new id and retrieves the current PID) + */ + public static function flushLogger() + { + $flushDice = self::$dice + ->addRule(LoggerInterface::class, self::$dice->getRule(LoggerInterface::class)) + ->addRule('$devLogger', self::$dice->getRule('$devLogger')); + static::init($flushDice); + } + /** * @return LoggerInterface */ diff --git a/static/dependencies.config.php b/static/dependencies.config.php index 46463de61..d3034a2ba 100644 --- a/static/dependencies.config.php +++ b/static/dependencies.config.php @@ -40,7 +40,6 @@ use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\L10n; use Friendica\Core\Lock; -use Friendica\Core\Process; use Friendica\Core\Session\Capability\IHandleSessions; use Friendica\Core\Storage\Repository\StorageManager; use Friendica\Database\Database; From a7487ee50da6c469130afdfbb2321c5bf38f0e48 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sun, 31 Oct 2021 20:23:23 +0100 Subject: [PATCH 04/14] Fix PID at forking --- src/Core/Worker.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Core/Worker.php b/src/Core/Worker.php index faa29717c..a4f14a48c 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -1183,22 +1183,22 @@ class Worker DBA::connect(); DI::flushLogger(); - $process = DI::process()->create($pid); + $process = DI::process()->create(getmypid()); $cycles = 0; - while (!self::IPCJobsExists($pid) && (++$cycles < 100)) { + while (!self::IPCJobsExists($process->pid) && (++$cycles < 100)) { usleep(10000); } - Logger::info('Worker spawned', ['pid' => $pid, 'wait_cycles' => $cycles]); + Logger::info('Worker spawned', ['pid' => $process->pid, 'wait_cycles' => $cycles]); self::processQueue($do_cron, $process); self::unclaimProcess($process); - self::IPCSetJobState(false, $pid); + self::IPCSetJobState(false, $process->pid); DI::process()->delete($process); - Logger::info('Worker ended', ['pid' => $pid]); + Logger::info('Worker ended', ['pid' => $process->pid]); exit(); } From 388f9d5a5be7e1999e4983df79e18582b03b8a1f Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 1 Nov 2021 07:53:07 +0100 Subject: [PATCH 05/14] Update src/App.php Co-authored-by: Hypolite Petovan --- src/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.php b/src/App.php index 41ca22229..f30c673ff 100644 --- a/src/App.php +++ b/src/App.php @@ -327,7 +327,7 @@ class App * @param Profiler $profiler The profiler of this application * @param L10n $l10n The translator instance * @param App\Arguments $args The Friendica Arguments of the call - * @param Core\System $system The system methods + * @param Core\System $system The system methods * @param IManagePersonalConfigValues $pConfig Personal configuration */ public function __construct(Database $database, IManageConfigValues $config, App\Mode $mode, BaseURL $baseURL, LoggerInterface $logger, Profiler $profiler, L10n $l10n, Arguments $args, Core\System $system, IManagePersonalConfigValues $pConfig) From 807c95b314fe5837e81dd8a618f23a63a6217676 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 1 Nov 2021 07:53:26 +0100 Subject: [PATCH 06/14] Update src/Core/System.php Co-authored-by: Hypolite Petovan --- src/Core/System.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Core/System.php b/src/Core/System.php index 321fb3d6f..d41180294 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -216,6 +216,7 @@ class System } else { $resource = proc_open($cmdline . ' &', [], $foo, $this->basePath); } + if (!is_resource($resource)) { $this->logger->warning('We got no resource for command.', ['command' => $cmdline]); return; From 63960bca05721179de50fe8ad8b21d34763f1c0d Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 1 Nov 2021 07:53:34 +0100 Subject: [PATCH 07/14] Update src/Core/Worker.php Co-authored-by: Hypolite Petovan --- src/Core/Worker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Worker.php b/src/Core/Worker.php index a4f14a48c..bdc184d2f 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -52,7 +52,7 @@ class Worker private static $last_update; private static $state; private static $daemon_mode = null; - /** @var Worker\Entity\Process */ + /** @var Process */ private static $process; /** From 7c6554451e921e500ac503383945acc6d3a2ba2c Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 1 Nov 2021 07:53:47 +0100 Subject: [PATCH 08/14] Update src/Core/System.php Co-authored-by: Hypolite Petovan --- src/Core/System.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Core/System.php b/src/Core/System.php index d41180294..44249175a 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -221,6 +221,7 @@ class System $this->logger->warning('We got no resource for command.', ['command' => $cmdline]); return; } + proc_close($resource); $this->logger->info('Executed "proc_open"', ['command' => $cmdline, 'callstack' => System::callstack(10)]); From c2b5eb2838df2d420bb59041fbc9497186e0de4f Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 1 Nov 2021 13:54:18 +0100 Subject: [PATCH 09/14] Improve repository usage --- bin/worker.php | 2 +- src/Core/Worker.php | 2 +- src/Core/Worker/Repository/Process.php | 16 ++++++---------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/bin/worker.php b/bin/worker.php index 13018b49d..877f1333e 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -81,7 +81,7 @@ if ($spawn) { $run_cron = !array_key_exists('n', $options) && !array_key_exists('no_cron', $options); -$process = DI::process()->create(getmypid()); +$process = DI::process()->create(getmypid(), basename(__FILE__)); Worker::processQueue($run_cron, $process); diff --git a/src/Core/Worker.php b/src/Core/Worker.php index bdc184d2f..8dd1ece8e 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -1183,7 +1183,7 @@ class Worker DBA::connect(); DI::flushLogger(); - $process = DI::process()->create(getmypid()); + $process = DI::process()->create(getmypid(), basename(__FILE__)); $cycles = 0; while (!self::IPCJobsExists($process->pid) && (++$cycles < 100)) { diff --git a/src/Core/Worker/Repository/Process.php b/src/Core/Worker/Repository/Process.php index d14121b97..1e91d867f 100644 --- a/src/Core/Worker/Repository/Process.php +++ b/src/Core/Worker/Repository/Process.php @@ -47,11 +47,12 @@ class Process extends BaseRepository /** * Starts and Returns the process for a given PID * - * @param int $pid + * @param int $pid + * @param string $command * * @return Entity\Process */ - public function create(int $pid): Entity\Process + public function create(int $pid, string $command): Entity\Process { // Cleanup inactive process $this->deleteInactive(); @@ -59,11 +60,6 @@ class Process extends BaseRepository try { $this->db->transaction(); - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - $last = $trace[count($trace) - 1]; - - $command = strtolower(basename($last['file'])); - $newProcess = $this->factory->create($pid, $command); if (!$this->db->exists('process', ['pid' => $pid])) { @@ -114,10 +110,10 @@ class Process extends BaseRepository } } $this->db->close($processes); - } catch (\Exception $exception) { - throw new ProcessPersistenceException('Cannot delete inactive process', $exception); - } finally { $this->db->commit(); + } catch (\Exception $exception) { + $this->db->rollback(); + throw new ProcessPersistenceException('Cannot delete inactive process', $exception); } } From 62bacbb833c5a8847dff5fc9db232638440f6f38 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 1 Nov 2021 13:54:54 +0100 Subject: [PATCH 10/14] Remove 'maxloadavg_frontend' restriction in Friendica --- src/App.php | 8 -------- src/Core/System.php | 25 +++++------------------- src/Module/Admin/Site.php | 3 --- static/settings.config.php | 4 ---- view/templates/admin/site.tpl | 1 - view/theme/frio/templates/admin/site.tpl | 1 - 6 files changed, 5 insertions(+), 37 deletions(-) diff --git a/src/App.php b/src/App.php index f30c673ff..75f5314af 100644 --- a/src/App.php +++ b/src/App.php @@ -588,14 +588,6 @@ class App throw new HTTPException\InternalServerErrorException('Apologies but the website is unavailable at the moment.'); } - // Max Load Average reached: ERROR - if ($this->system->isMaxProcessesReached() || $this->system->isMaxLoadReached()) { - header('Retry-After: 120'); - header('Refresh: 120; url=' . $this->baseURL->get() . "/" . $this->args->getQueryString()); - - throw new HTTPException\ServiceUnavailableException('The node is currently overloaded. Please try again later.'); - } - if (!$this->mode->isInstall()) { // Force SSL redirection if ($this->baseURL->checkRedirectHttps()) { diff --git a/src/Core/System.php b/src/Core/System.php index 44249175a..9002c5a7b 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -42,11 +42,6 @@ class System */ private $logger; - /** - * @var App\Mode - */ - private $mode; - /** * @var IManageConfigValues */ @@ -57,10 +52,9 @@ class System */ private $basePath; - public function __construct(LoggerInterface $logger, App\Mode $mode, IManageConfigValues $config, string $basepath) + public function __construct(LoggerInterface $logger, IManageConfigValues $config, string $basepath) { $this->logger = $logger; - $this->mode = $mode; $this->config = $config; $this->basePath = $basepath; } @@ -156,24 +150,15 @@ class System */ public function isMaxLoadReached(): bool { - if ($this->mode->isBackend()) { - $process = 'backend'; - $maxsysload = intval($this->config->get('system', 'maxloadavg')); - if ($maxsysload < 1) { - $maxsysload = 50; - } - } else { - $process = 'frontend'; - $maxsysload = intval($this->config->get('system', 'maxloadavg_frontend')); - if ($maxsysload < 1) { - $maxsysload = 50; - } + $maxsysload = intval($this->config->get('system', 'maxloadavg')); + if ($maxsysload < 1) { + $maxsysload = 50; } $load = System::currentLoad(); if ($load) { if (intval($load) > $maxsysload) { - $this->logger->warning('system load for process too high.', ['load' => $load, 'process' => $process, 'maxsysload' => $maxsysload]); + $this->logger->warning('system load for process too high.', ['load' => $load, 'process' => 'backend', 'maxsysload' => $maxsysload]); return true; } } diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php index 2cc4ac23a..9d769cba7 100644 --- a/src/Module/Admin/Site.php +++ b/src/Module/Admin/Site.php @@ -177,7 +177,6 @@ class Site extends BaseAdmin $proxy = (!empty($_POST['proxy']) ? Strings::escapeTags(trim($_POST['proxy'])) : ''); $timeout = (!empty($_POST['timeout']) ? intval(trim($_POST['timeout'])) : 60); $maxloadavg = (!empty($_POST['maxloadavg']) ? intval(trim($_POST['maxloadavg'])) : 20); - $maxloadavg_frontend = (!empty($_POST['maxloadavg_frontend']) ? intval(trim($_POST['maxloadavg_frontend'])) : 50); $min_memory = (!empty($_POST['min_memory']) ? intval(trim($_POST['min_memory'])) : 0); $optimize_tables = (!empty($_POST['optimize_tables']) ? intval(trim($_POST['optimize_tables'])) : false); $contact_discovery = (!empty($_POST['contact_discovery']) ? intval(trim($_POST['contact_discovery'])) : Contact\Relation::DISCOVERY_NONE); @@ -264,7 +263,6 @@ class Site extends BaseAdmin } DI::config()->set('system', 'ssl_policy' , $ssl_policy); DI::config()->set('system', 'maxloadavg' , $maxloadavg); - DI::config()->set('system', 'maxloadavg_frontend' , $maxloadavg_frontend); DI::config()->set('system', 'min_memory' , $min_memory); DI::config()->set('system', 'optimize_tables' , $optimize_tables); DI::config()->set('system', 'contact_discovery' , $contact_discovery); @@ -576,7 +574,6 @@ class Site extends BaseAdmin '$proxy' => ['proxy', DI::l10n()->t('Proxy URL'), DI::config()->get('system', 'proxy'), ''], '$timeout' => ['timeout', DI::l10n()->t('Network timeout'), DI::config()->get('system', 'curl_timeout'), DI::l10n()->t('Value is in seconds. Set to 0 for unlimited (not recommended).')], '$maxloadavg' => ['maxloadavg', DI::l10n()->t('Maximum Load Average'), DI::config()->get('system', 'maxloadavg'), DI::l10n()->t('Maximum system load before delivery and poll processes are deferred - default %d.', 20)], - '$maxloadavg_frontend' => ['maxloadavg_frontend', DI::l10n()->t('Maximum Load Average (Frontend)'), DI::config()->get('system', 'maxloadavg_frontend'), DI::l10n()->t('Maximum system load before the frontend quits service - default 50.')], '$min_memory' => ['min_memory', DI::l10n()->t('Minimal Memory'), DI::config()->get('system', 'min_memory'), DI::l10n()->t('Minimal free memory in MB for the worker. Needs access to /proc/meminfo - default 0 (deactivated).')], '$optimize_tables' => ['optimize_tables', DI::l10n()->t('Periodically optimize tables'), DI::config()->get('system', 'optimize_tables'), DI::l10n()->t('Periodically optimize tables like the cache and the workerqueue')], diff --git a/static/settings.config.php b/static/settings.config.php index e3a7a10a2..fd07c5d26 100644 --- a/static/settings.config.php +++ b/static/settings.config.php @@ -148,10 +148,6 @@ return [ // Maximum system load before delivery and poll processes are deferred. 'maxloadavg' => 20, - // maxloadavg_frontend (Integer) - // Maximum system load before the frontend quits service - default 50. - 'maxloadavg_frontend' => 50, - // min_memory (Integer) // Minimal free memory in MB for the worker. Needs access to /proc/meminfo - default 0 (deactivated). 'min_memory' => 0, diff --git a/view/templates/admin/site.tpl b/view/templates/admin/site.tpl index 985fa0222..6e2958b97 100644 --- a/view/templates/admin/site.tpl +++ b/view/templates/admin/site.tpl @@ -91,7 +91,6 @@ {{include file="field_input.tpl" field=$proxy}} {{include file="field_input.tpl" field=$proxyuser}} {{include file="field_input.tpl" field=$timeout}} - {{include file="field_input.tpl" field=$maxloadavg_frontend}} {{include file="field_input.tpl" field=$abandon_days}} {{include file="field_input.tpl" field=$temppath}} {{include file="field_checkbox.tpl" field=$suppress_tags}} diff --git a/view/theme/frio/templates/admin/site.tpl b/view/theme/frio/templates/admin/site.tpl index a6eb1d670..e17dd57ac 100644 --- a/view/theme/frio/templates/admin/site.tpl +++ b/view/theme/frio/templates/admin/site.tpl @@ -190,7 +190,6 @@ {{include file="field_input.tpl" field=$proxy}} {{include file="field_input.tpl" field=$proxyuser}} {{include file="field_input.tpl" field=$timeout}} - {{include file="field_input.tpl" field=$maxloadavg_frontend}} {{include file="field_input.tpl" field=$abandon_days}} {{include file="field_input.tpl" field=$temppath}} {{include file="field_checkbox.tpl" field=$suppress_tags}} From da86581bf22dfe1770ca8c4912777a1cf03caff0 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 1 Nov 2021 13:58:36 +0100 Subject: [PATCH 11/14] Deactivating isMinMemoryReached() --- src/Core/System.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Core/System.php b/src/Core/System.php index 9002c5a7b..445123906 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -106,6 +106,12 @@ class System */ public function isMinMemoryReached(): bool { + // Deactivated, needs more investigating if this check really makes sense + return false; + + /* + * Commented out to suppress static analyzer issues + * $min_memory = $this->config->get('system', 'min_memory', 0); if ($min_memory == 0) { return false; @@ -141,6 +147,7 @@ class System } return $reached; + */ } /** From ec25fd2b6397fc9704a040fc9176e5f2eca9a141 Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 3 Nov 2021 01:02:15 +0100 Subject: [PATCH 12/14] Update messages.po --- view/lang/C/messages.po | 400 ++++++++++++++++++++-------------------- 1 file changed, 196 insertions(+), 204 deletions(-) diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index 0508a99e4..68d78161a 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2021.12-dev\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-10-31 05:26+0000\n" +"POT-Creation-Date: 2021-11-03 01:01+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -406,7 +406,7 @@ msgstr "" msgid "Basic" msgstr "" -#: mod/events.php:521 src/Module/Admin/Site.php:507 src/Module/Contact.php:863 +#: mod/events.php:521 src/Module/Admin/Site.php:505 src/Module/Contact.php:863 #: src/Module/Profile/Profile.php:249 msgid "Advanced" msgstr "" @@ -1263,7 +1263,7 @@ msgstr "" #: mod/settings.php:474 mod/settings.php:565 mod/settings.php:702 #: src/Module/Admin/Addons/Index.php:69 src/Module/Admin/Features.php:87 -#: src/Module/Admin/Logs/Settings.php:82 src/Module/Admin/Site.php:502 +#: src/Module/Admin/Logs/Settings.php:82 src/Module/Admin/Site.php:500 #: src/Module/Admin/Themes/Index.php:113 src/Module/Admin/Tos.php:66 #: src/Module/Settings/Delegation.php:170 src/Module/Settings/Display.php:194 msgid "Save Settings" @@ -4708,7 +4708,7 @@ msgstr "" #: src/Module/Admin/Blocklist/Server.php:88 src/Module/Admin/Federation.php:159 #: src/Module/Admin/Item/Delete.php:65 src/Module/Admin/Logs/Settings.php:80 #: src/Module/Admin/Logs/View.php:83 src/Module/Admin/Queue.php:72 -#: src/Module/Admin/Site.php:499 src/Module/Admin/Storage.php:138 +#: src/Module/Admin/Site.php:497 src/Module/Admin/Storage.php:138 #: src/Module/Admin/Summary.php:232 src/Module/Admin/Themes/Details.php:90 #: src/Module/Admin/Themes/Index.php:111 src/Module/Admin/Tos.php:58 #: src/Module/Admin/Users/Active.php:136 src/Module/Admin/Users/Blocked.php:137 @@ -5337,464 +5337,464 @@ msgstr "" msgid "Relocation started. Could take a while to complete." msgstr "" -#: src/Module/Admin/Site.php:404 src/Module/Settings/Display.php:139 +#: src/Module/Admin/Site.php:402 src/Module/Settings/Display.php:139 msgid "No special theme for mobile devices" msgstr "" -#: src/Module/Admin/Site.php:421 src/Module/Settings/Display.php:149 +#: src/Module/Admin/Site.php:419 src/Module/Settings/Display.php:149 #, php-format msgid "%s - (Experimental)" msgstr "" -#: src/Module/Admin/Site.php:433 +#: src/Module/Admin/Site.php:431 msgid "No community page for local users" msgstr "" -#: src/Module/Admin/Site.php:434 +#: src/Module/Admin/Site.php:432 msgid "No community page" msgstr "" -#: src/Module/Admin/Site.php:435 +#: src/Module/Admin/Site.php:433 msgid "Public postings from users of this site" msgstr "" -#: src/Module/Admin/Site.php:436 +#: src/Module/Admin/Site.php:434 msgid "Public postings from the federated network" msgstr "" -#: src/Module/Admin/Site.php:437 +#: src/Module/Admin/Site.php:435 msgid "Public postings from local users and the federated network" msgstr "" -#: src/Module/Admin/Site.php:443 +#: src/Module/Admin/Site.php:441 msgid "Multi user instance" msgstr "" -#: src/Module/Admin/Site.php:470 +#: src/Module/Admin/Site.php:468 msgid "Closed" msgstr "" -#: src/Module/Admin/Site.php:471 +#: src/Module/Admin/Site.php:469 msgid "Requires approval" msgstr "" -#: src/Module/Admin/Site.php:472 +#: src/Module/Admin/Site.php:470 msgid "Open" msgstr "" -#: src/Module/Admin/Site.php:476 src/Module/Install.php:215 +#: src/Module/Admin/Site.php:474 src/Module/Install.php:215 msgid "No SSL policy, links will track page SSL state" msgstr "" -#: src/Module/Admin/Site.php:477 src/Module/Install.php:216 +#: src/Module/Admin/Site.php:475 src/Module/Install.php:216 msgid "Force all links to use SSL" msgstr "" -#: src/Module/Admin/Site.php:478 src/Module/Install.php:217 +#: src/Module/Admin/Site.php:476 src/Module/Install.php:217 msgid "Self-signed certificate, use SSL for local links only (discouraged)" msgstr "" -#: src/Module/Admin/Site.php:482 +#: src/Module/Admin/Site.php:480 msgid "Don't check" msgstr "" -#: src/Module/Admin/Site.php:483 +#: src/Module/Admin/Site.php:481 msgid "check the stable version" msgstr "" -#: src/Module/Admin/Site.php:484 +#: src/Module/Admin/Site.php:482 msgid "check the development version" msgstr "" -#: src/Module/Admin/Site.php:488 +#: src/Module/Admin/Site.php:486 msgid "none" msgstr "" -#: src/Module/Admin/Site.php:489 +#: src/Module/Admin/Site.php:487 msgid "Local contacts" msgstr "" -#: src/Module/Admin/Site.php:490 +#: src/Module/Admin/Site.php:488 msgid "Interactors" msgstr "" -#: src/Module/Admin/Site.php:500 src/Module/BaseAdmin.php:90 +#: src/Module/Admin/Site.php:498 src/Module/BaseAdmin.php:90 msgid "Site" msgstr "" -#: src/Module/Admin/Site.php:501 +#: src/Module/Admin/Site.php:499 msgid "General Information" msgstr "" -#: src/Module/Admin/Site.php:503 +#: src/Module/Admin/Site.php:501 msgid "Republish users to directory" msgstr "" -#: src/Module/Admin/Site.php:504 src/Module/Register.php:141 +#: src/Module/Admin/Site.php:502 src/Module/Register.php:141 msgid "Registration" msgstr "" -#: src/Module/Admin/Site.php:505 +#: src/Module/Admin/Site.php:503 msgid "File upload" msgstr "" -#: src/Module/Admin/Site.php:506 +#: src/Module/Admin/Site.php:504 msgid "Policies" msgstr "" -#: src/Module/Admin/Site.php:508 +#: src/Module/Admin/Site.php:506 msgid "Auto Discovered Contact Directory" msgstr "" -#: src/Module/Admin/Site.php:509 +#: src/Module/Admin/Site.php:507 msgid "Performance" msgstr "" -#: src/Module/Admin/Site.php:510 +#: src/Module/Admin/Site.php:508 msgid "Worker" msgstr "" -#: src/Module/Admin/Site.php:511 +#: src/Module/Admin/Site.php:509 msgid "Message Relay" msgstr "" -#: src/Module/Admin/Site.php:512 +#: src/Module/Admin/Site.php:510 msgid "" "Use the command \"console relay\" in the command line to add or remove " "relays." msgstr "" -#: src/Module/Admin/Site.php:513 +#: src/Module/Admin/Site.php:511 msgid "The system is not subscribed to any relays at the moment." msgstr "" -#: src/Module/Admin/Site.php:514 +#: src/Module/Admin/Site.php:512 msgid "The system is currently subscribed to the following relays:" msgstr "" -#: src/Module/Admin/Site.php:516 +#: src/Module/Admin/Site.php:514 msgid "Relocate Instance" msgstr "" -#: src/Module/Admin/Site.php:517 +#: src/Module/Admin/Site.php:515 msgid "" "Warning! Advanced function. Could make this server " "unreachable." msgstr "" -#: src/Module/Admin/Site.php:521 +#: src/Module/Admin/Site.php:519 msgid "Site name" msgstr "" -#: src/Module/Admin/Site.php:522 +#: src/Module/Admin/Site.php:520 msgid "Sender Email" msgstr "" -#: src/Module/Admin/Site.php:522 +#: src/Module/Admin/Site.php:520 msgid "" "The email address your server shall use to send notification emails from." msgstr "" -#: src/Module/Admin/Site.php:523 +#: src/Module/Admin/Site.php:521 msgid "Name of the system actor" msgstr "" -#: src/Module/Admin/Site.php:523 +#: src/Module/Admin/Site.php:521 msgid "" "Name of the internal system account that is used to perform ActivityPub " "requests. This must be an unused username. If set, this can't be changed " "again." msgstr "" -#: src/Module/Admin/Site.php:524 +#: src/Module/Admin/Site.php:522 msgid "Banner/Logo" msgstr "" -#: src/Module/Admin/Site.php:525 +#: src/Module/Admin/Site.php:523 msgid "Email Banner/Logo" msgstr "" -#: src/Module/Admin/Site.php:526 +#: src/Module/Admin/Site.php:524 msgid "Shortcut icon" msgstr "" -#: src/Module/Admin/Site.php:526 +#: src/Module/Admin/Site.php:524 msgid "Link to an icon that will be used for browsers." msgstr "" -#: src/Module/Admin/Site.php:527 +#: src/Module/Admin/Site.php:525 msgid "Touch icon" msgstr "" -#: src/Module/Admin/Site.php:527 +#: src/Module/Admin/Site.php:525 msgid "Link to an icon that will be used for tablets and mobiles." msgstr "" -#: src/Module/Admin/Site.php:528 +#: src/Module/Admin/Site.php:526 msgid "Additional Info" msgstr "" -#: src/Module/Admin/Site.php:528 +#: src/Module/Admin/Site.php:526 #, php-format msgid "" "For public servers: you can add additional information here that will be " "listed at %s/servers." msgstr "" -#: src/Module/Admin/Site.php:529 +#: src/Module/Admin/Site.php:527 msgid "System language" msgstr "" -#: src/Module/Admin/Site.php:530 +#: src/Module/Admin/Site.php:528 msgid "System theme" msgstr "" -#: src/Module/Admin/Site.php:530 +#: src/Module/Admin/Site.php:528 msgid "" "Default system theme - may be over-ridden by user profiles - Change default theme settings" msgstr "" -#: src/Module/Admin/Site.php:531 +#: src/Module/Admin/Site.php:529 msgid "Mobile system theme" msgstr "" -#: src/Module/Admin/Site.php:531 +#: src/Module/Admin/Site.php:529 msgid "Theme for mobile devices" msgstr "" -#: src/Module/Admin/Site.php:532 src/Module/Install.php:225 +#: src/Module/Admin/Site.php:530 src/Module/Install.php:225 msgid "SSL link policy" msgstr "" -#: src/Module/Admin/Site.php:532 src/Module/Install.php:227 +#: src/Module/Admin/Site.php:530 src/Module/Install.php:227 msgid "Determines whether generated links should be forced to use SSL" msgstr "" -#: src/Module/Admin/Site.php:533 +#: src/Module/Admin/Site.php:531 msgid "Force SSL" msgstr "" -#: src/Module/Admin/Site.php:533 +#: src/Module/Admin/Site.php:531 msgid "" "Force all Non-SSL requests to SSL - Attention: on some systems it could lead " "to endless loops." msgstr "" -#: src/Module/Admin/Site.php:534 +#: src/Module/Admin/Site.php:532 msgid "Show help entry from navigation menu" msgstr "" -#: src/Module/Admin/Site.php:534 +#: src/Module/Admin/Site.php:532 msgid "" "Displays the menu entry for the Help pages from the navigation menu. It is " "always accessible by calling /help directly." msgstr "" -#: src/Module/Admin/Site.php:535 +#: src/Module/Admin/Site.php:533 msgid "Single user instance" msgstr "" -#: src/Module/Admin/Site.php:535 +#: src/Module/Admin/Site.php:533 msgid "Make this instance multi-user or single-user for the named user" msgstr "" -#: src/Module/Admin/Site.php:537 +#: src/Module/Admin/Site.php:535 msgid "Maximum image size" msgstr "" -#: src/Module/Admin/Site.php:537 +#: src/Module/Admin/Site.php:535 msgid "" "Maximum size in bytes of uploaded images. Default is 0, which means no " "limits." msgstr "" -#: src/Module/Admin/Site.php:538 +#: src/Module/Admin/Site.php:536 msgid "Maximum image length" msgstr "" -#: src/Module/Admin/Site.php:538 +#: src/Module/Admin/Site.php:536 msgid "" "Maximum length in pixels of the longest side of uploaded images. Default is " "-1, which means no limits." msgstr "" -#: src/Module/Admin/Site.php:539 +#: src/Module/Admin/Site.php:537 msgid "JPEG image quality" msgstr "" -#: src/Module/Admin/Site.php:539 +#: src/Module/Admin/Site.php:537 msgid "" "Uploaded JPEGS will be saved at this quality setting [0-100]. Default is " "100, which is full quality." msgstr "" -#: src/Module/Admin/Site.php:541 +#: src/Module/Admin/Site.php:539 msgid "Register policy" msgstr "" -#: src/Module/Admin/Site.php:542 +#: src/Module/Admin/Site.php:540 msgid "Maximum Daily Registrations" msgstr "" -#: src/Module/Admin/Site.php:542 +#: src/Module/Admin/Site.php:540 msgid "" "If registration is permitted above, this sets the maximum number of new user " "registrations to accept per day. If register is set to closed, this setting " "has no effect." msgstr "" -#: src/Module/Admin/Site.php:543 +#: src/Module/Admin/Site.php:541 msgid "Register text" msgstr "" -#: src/Module/Admin/Site.php:543 +#: src/Module/Admin/Site.php:541 msgid "" "Will be displayed prominently on the registration page. You can use BBCode " "here." msgstr "" -#: src/Module/Admin/Site.php:544 +#: src/Module/Admin/Site.php:542 msgid "Forbidden Nicknames" msgstr "" -#: src/Module/Admin/Site.php:544 +#: src/Module/Admin/Site.php:542 msgid "" "Comma separated list of nicknames that are forbidden from registration. " "Preset is a list of role names according RFC 2142." msgstr "" -#: src/Module/Admin/Site.php:545 +#: src/Module/Admin/Site.php:543 msgid "Accounts abandoned after x days" msgstr "" -#: src/Module/Admin/Site.php:545 +#: src/Module/Admin/Site.php:543 msgid "" "Will not waste system resources polling external sites for abandonded " "accounts. Enter 0 for no time limit." msgstr "" -#: src/Module/Admin/Site.php:546 +#: src/Module/Admin/Site.php:544 msgid "Allowed friend domains" msgstr "" -#: src/Module/Admin/Site.php:546 +#: src/Module/Admin/Site.php:544 msgid "" "Comma separated list of domains which are allowed to establish friendships " "with this site. Wildcards are accepted. Empty to allow any domains" msgstr "" -#: src/Module/Admin/Site.php:547 +#: src/Module/Admin/Site.php:545 msgid "Allowed email domains" msgstr "" -#: src/Module/Admin/Site.php:547 +#: src/Module/Admin/Site.php:545 msgid "" "Comma separated list of domains which are allowed in email addresses for " "registrations to this site. Wildcards are accepted. Empty to allow any " "domains" msgstr "" -#: src/Module/Admin/Site.php:548 +#: src/Module/Admin/Site.php:546 msgid "No OEmbed rich content" msgstr "" -#: src/Module/Admin/Site.php:548 +#: src/Module/Admin/Site.php:546 msgid "" "Don't show the rich content (e.g. embedded PDF), except from the domains " "listed below." msgstr "" -#: src/Module/Admin/Site.php:549 +#: src/Module/Admin/Site.php:547 msgid "Trusted third-party domains" msgstr "" -#: src/Module/Admin/Site.php:549 +#: src/Module/Admin/Site.php:547 msgid "" "Comma separated list of domains from which content is allowed to be embedded " "in posts like with OEmbed. All sub-domains of the listed domains are allowed " "as well." msgstr "" -#: src/Module/Admin/Site.php:550 +#: src/Module/Admin/Site.php:548 msgid "Block public" msgstr "" -#: src/Module/Admin/Site.php:550 +#: src/Module/Admin/Site.php:548 msgid "" "Check to block public access to all otherwise public personal pages on this " "site unless you are currently logged in." msgstr "" -#: src/Module/Admin/Site.php:551 +#: src/Module/Admin/Site.php:549 msgid "Force publish" msgstr "" -#: src/Module/Admin/Site.php:551 +#: src/Module/Admin/Site.php:549 msgid "" "Check to force all profiles on this site to be listed in the site directory." msgstr "" -#: src/Module/Admin/Site.php:551 +#: src/Module/Admin/Site.php:549 msgid "Enabling this may violate privacy laws like the GDPR" msgstr "" -#: src/Module/Admin/Site.php:552 +#: src/Module/Admin/Site.php:550 msgid "Global directory URL" msgstr "" -#: src/Module/Admin/Site.php:552 +#: src/Module/Admin/Site.php:550 msgid "" "URL to the global directory. If this is not set, the global directory is " "completely unavailable to the application." msgstr "" -#: src/Module/Admin/Site.php:553 +#: src/Module/Admin/Site.php:551 msgid "Private posts by default for new users" msgstr "" -#: src/Module/Admin/Site.php:553 +#: src/Module/Admin/Site.php:551 msgid "" "Set default post permissions for all new members to the default privacy " "group rather than public." msgstr "" -#: src/Module/Admin/Site.php:554 +#: src/Module/Admin/Site.php:552 msgid "Don't include post content in email notifications" msgstr "" -#: src/Module/Admin/Site.php:554 +#: src/Module/Admin/Site.php:552 msgid "" "Don't include the content of a post/comment/private message/etc. in the " "email notifications that are sent out from this site, as a privacy measure." msgstr "" -#: src/Module/Admin/Site.php:555 +#: src/Module/Admin/Site.php:553 msgid "Disallow public access to addons listed in the apps menu." msgstr "" -#: src/Module/Admin/Site.php:555 +#: src/Module/Admin/Site.php:553 msgid "" "Checking this box will restrict addons listed in the apps menu to members " "only." msgstr "" -#: src/Module/Admin/Site.php:556 +#: src/Module/Admin/Site.php:554 msgid "Don't embed private images in posts" msgstr "" -#: src/Module/Admin/Site.php:556 +#: src/Module/Admin/Site.php:554 msgid "" "Don't replace locally-hosted private photos in posts with an embedded copy " "of the image. This means that contacts who receive posts containing private " "photos will have to authenticate and load each image, which may take a while." msgstr "" -#: src/Module/Admin/Site.php:557 +#: src/Module/Admin/Site.php:555 msgid "Explicit Content" msgstr "" -#: src/Module/Admin/Site.php:557 +#: src/Module/Admin/Site.php:555 msgid "" "Set this to announce that your node is used mostly for explicit content that " "might not be suited for minors. This information will be published in the " @@ -5803,255 +5803,247 @@ msgid "" "will be shown at the user registration page." msgstr "" -#: src/Module/Admin/Site.php:558 +#: src/Module/Admin/Site.php:556 msgid "Proxify external content" msgstr "" -#: src/Module/Admin/Site.php:558 +#: src/Module/Admin/Site.php:556 msgid "" "Route external content via the proxy functionality. This is used for example " "for some OEmbed accesses and in some other rare cases." msgstr "" -#: src/Module/Admin/Site.php:559 +#: src/Module/Admin/Site.php:557 msgid "Cache contact avatars" msgstr "" -#: src/Module/Admin/Site.php:559 +#: src/Module/Admin/Site.php:557 msgid "" "Locally store the avatar pictures of the contacts. This uses a lot of " "storage space but it increases the performance." msgstr "" -#: src/Module/Admin/Site.php:560 +#: src/Module/Admin/Site.php:558 msgid "Allow Users to set remote_self" msgstr "" -#: src/Module/Admin/Site.php:560 +#: src/Module/Admin/Site.php:558 msgid "" "With checking this, every user is allowed to mark every contact as a " "remote_self in the repair contact dialog. Setting this flag on a contact " "causes mirroring every posting of that contact in the users stream." msgstr "" -#: src/Module/Admin/Site.php:561 +#: src/Module/Admin/Site.php:559 msgid "Enable multiple registrations" msgstr "" -#: src/Module/Admin/Site.php:561 +#: src/Module/Admin/Site.php:559 msgid "Enable users to register additional accounts for use as pages." msgstr "" -#: src/Module/Admin/Site.php:562 +#: src/Module/Admin/Site.php:560 msgid "Enable OpenID" msgstr "" -#: src/Module/Admin/Site.php:562 +#: src/Module/Admin/Site.php:560 msgid "Enable OpenID support for registration and logins." msgstr "" -#: src/Module/Admin/Site.php:563 +#: src/Module/Admin/Site.php:561 msgid "Enable Fullname check" msgstr "" -#: src/Module/Admin/Site.php:563 +#: src/Module/Admin/Site.php:561 msgid "" "Enable check to only allow users to register with a space between the first " "name and the last name in their full name." msgstr "" -#: src/Module/Admin/Site.php:564 +#: src/Module/Admin/Site.php:562 msgid "Community pages for visitors" msgstr "" -#: src/Module/Admin/Site.php:564 +#: src/Module/Admin/Site.php:562 msgid "" "Which community pages should be available for visitors. Local users always " "see both pages." msgstr "" -#: src/Module/Admin/Site.php:565 +#: src/Module/Admin/Site.php:563 msgid "Posts per user on community page" msgstr "" -#: src/Module/Admin/Site.php:565 +#: src/Module/Admin/Site.php:563 msgid "" "The maximum number of posts per user on the community page. (Not valid for " "\"Global Community\")" msgstr "" -#: src/Module/Admin/Site.php:567 +#: src/Module/Admin/Site.php:565 msgid "Enable Mail support" msgstr "" -#: src/Module/Admin/Site.php:567 +#: src/Module/Admin/Site.php:565 msgid "" "Enable built-in mail support to poll IMAP folders and to reply via mail." msgstr "" -#: src/Module/Admin/Site.php:568 +#: src/Module/Admin/Site.php:566 msgid "" "Mail support can't be enabled because the PHP IMAP module is not installed." msgstr "" -#: src/Module/Admin/Site.php:569 +#: src/Module/Admin/Site.php:567 msgid "Enable OStatus support" msgstr "" -#: src/Module/Admin/Site.php:569 +#: src/Module/Admin/Site.php:567 msgid "" "Enable built-in OStatus (StatusNet, GNU Social etc.) compatibility. All " "communications in OStatus are public." msgstr "" -#: src/Module/Admin/Site.php:571 +#: src/Module/Admin/Site.php:569 msgid "" "Diaspora support can't be enabled because Friendica was installed into a sub " "directory." msgstr "" -#: src/Module/Admin/Site.php:572 +#: src/Module/Admin/Site.php:570 msgid "Enable Diaspora support" msgstr "" -#: src/Module/Admin/Site.php:572 +#: src/Module/Admin/Site.php:570 msgid "" "Enable built-in Diaspora network compatibility for communicating with " "diaspora servers." msgstr "" -#: src/Module/Admin/Site.php:573 +#: src/Module/Admin/Site.php:571 msgid "Verify SSL" msgstr "" -#: src/Module/Admin/Site.php:573 +#: src/Module/Admin/Site.php:571 msgid "" "If you wish, you can turn on strict certificate checking. This will mean you " "cannot connect (at all) to self-signed SSL sites." msgstr "" -#: src/Module/Admin/Site.php:574 +#: src/Module/Admin/Site.php:572 msgid "Proxy user" msgstr "" -#: src/Module/Admin/Site.php:575 +#: src/Module/Admin/Site.php:573 msgid "Proxy URL" msgstr "" -#: src/Module/Admin/Site.php:576 +#: src/Module/Admin/Site.php:574 msgid "Network timeout" msgstr "" -#: src/Module/Admin/Site.php:576 +#: src/Module/Admin/Site.php:574 msgid "Value is in seconds. Set to 0 for unlimited (not recommended)." msgstr "" -#: src/Module/Admin/Site.php:577 +#: src/Module/Admin/Site.php:575 msgid "Maximum Load Average" msgstr "" -#: src/Module/Admin/Site.php:577 +#: src/Module/Admin/Site.php:575 #, php-format msgid "" "Maximum system load before delivery and poll processes are deferred - " "default %d." msgstr "" -#: src/Module/Admin/Site.php:578 -msgid "Maximum Load Average (Frontend)" -msgstr "" - -#: src/Module/Admin/Site.php:578 -msgid "Maximum system load before the frontend quits service - default 50." -msgstr "" - -#: src/Module/Admin/Site.php:579 +#: src/Module/Admin/Site.php:576 msgid "Minimal Memory" msgstr "" -#: src/Module/Admin/Site.php:579 +#: src/Module/Admin/Site.php:576 msgid "" "Minimal free memory in MB for the worker. Needs access to /proc/meminfo - " "default 0 (deactivated)." msgstr "" -#: src/Module/Admin/Site.php:580 +#: src/Module/Admin/Site.php:577 msgid "Periodically optimize tables" msgstr "" -#: src/Module/Admin/Site.php:580 +#: src/Module/Admin/Site.php:577 msgid "Periodically optimize tables like the cache and the workerqueue" msgstr "" -#: src/Module/Admin/Site.php:582 +#: src/Module/Admin/Site.php:579 msgid "Discover followers/followings from contacts" msgstr "" -#: src/Module/Admin/Site.php:582 +#: src/Module/Admin/Site.php:579 msgid "" "If enabled, contacts are checked for their followers and following contacts." msgstr "" -#: src/Module/Admin/Site.php:583 +#: src/Module/Admin/Site.php:580 msgid "None - deactivated" msgstr "" -#: src/Module/Admin/Site.php:584 +#: src/Module/Admin/Site.php:581 msgid "" "Local contacts - contacts of our local contacts are discovered for their " "followers/followings." msgstr "" -#: src/Module/Admin/Site.php:585 +#: src/Module/Admin/Site.php:582 msgid "" "Interactors - contacts of our local contacts and contacts who interacted on " "locally visible postings are discovered for their followers/followings." msgstr "" -#: src/Module/Admin/Site.php:587 +#: src/Module/Admin/Site.php:584 msgid "Synchronize the contacts with the directory server" msgstr "" -#: src/Module/Admin/Site.php:587 +#: src/Module/Admin/Site.php:584 msgid "" "if enabled, the system will check periodically for new contacts on the " "defined directory server." msgstr "" -#: src/Module/Admin/Site.php:589 +#: src/Module/Admin/Site.php:586 msgid "Days between requery" msgstr "" -#: src/Module/Admin/Site.php:589 +#: src/Module/Admin/Site.php:586 msgid "Number of days after which a server is requeried for his contacts." msgstr "" -#: src/Module/Admin/Site.php:590 +#: src/Module/Admin/Site.php:587 msgid "Discover contacts from other servers" msgstr "" -#: src/Module/Admin/Site.php:590 +#: src/Module/Admin/Site.php:587 msgid "" "Periodically query other servers for contacts. The system queries Friendica, " "Mastodon and Hubzilla servers." msgstr "" -#: src/Module/Admin/Site.php:591 +#: src/Module/Admin/Site.php:588 msgid "Search the local directory" msgstr "" -#: src/Module/Admin/Site.php:591 +#: src/Module/Admin/Site.php:588 msgid "" "Search the local directory instead of the global directory. When searching " "locally, every search will be executed on the global directory in the " "background. This improves the search results when the search is repeated." msgstr "" -#: src/Module/Admin/Site.php:593 +#: src/Module/Admin/Site.php:590 msgid "Publish server information" msgstr "" -#: src/Module/Admin/Site.php:593 +#: src/Module/Admin/Site.php:590 msgid "" "If enabled, general server and usage data will be published. The data " "contains the name and version of the server, number of users with public " @@ -6059,50 +6051,50 @@ msgid "" "href=\"http://the-federation.info/\">the-federation.info for details." msgstr "" -#: src/Module/Admin/Site.php:595 +#: src/Module/Admin/Site.php:592 msgid "Check upstream version" msgstr "" -#: src/Module/Admin/Site.php:595 +#: src/Module/Admin/Site.php:592 msgid "" "Enables checking for new Friendica versions at github. If there is a new " "version, you will be informed in the admin panel overview." msgstr "" -#: src/Module/Admin/Site.php:596 +#: src/Module/Admin/Site.php:593 msgid "Suppress Tags" msgstr "" -#: src/Module/Admin/Site.php:596 +#: src/Module/Admin/Site.php:593 msgid "Suppress showing a list of hashtags at the end of the posting." msgstr "" -#: src/Module/Admin/Site.php:597 +#: src/Module/Admin/Site.php:594 msgid "Clean database" msgstr "" -#: src/Module/Admin/Site.php:597 +#: src/Module/Admin/Site.php:594 msgid "" "Remove old remote items, orphaned database records and old content from some " "other helper tables." msgstr "" -#: src/Module/Admin/Site.php:598 +#: src/Module/Admin/Site.php:595 msgid "Lifespan of remote items" msgstr "" -#: src/Module/Admin/Site.php:598 +#: src/Module/Admin/Site.php:595 msgid "" "When the database cleanup is enabled, this defines the days after which " "remote items will be deleted. Own items, and marked or filed items are " "always kept. 0 disables this behaviour." msgstr "" -#: src/Module/Admin/Site.php:599 +#: src/Module/Admin/Site.php:596 msgid "Lifespan of unclaimed items" msgstr "" -#: src/Module/Admin/Site.php:599 +#: src/Module/Admin/Site.php:596 msgid "" "When the database cleanup is enabled, this defines the days after which " "unclaimed remote items (mostly content from the relay) will be deleted. " @@ -6110,144 +6102,144 @@ msgid "" "items if set to 0." msgstr "" -#: src/Module/Admin/Site.php:600 +#: src/Module/Admin/Site.php:597 msgid "Lifespan of raw conversation data" msgstr "" -#: src/Module/Admin/Site.php:600 +#: src/Module/Admin/Site.php:597 msgid "" "The conversation data is used for ActivityPub and OStatus, as well as for " "debug purposes. It should be safe to remove it after 14 days, default is 90 " "days." msgstr "" -#: src/Module/Admin/Site.php:601 +#: src/Module/Admin/Site.php:598 msgid "Maximum numbers of comments per post" msgstr "" -#: src/Module/Admin/Site.php:601 +#: src/Module/Admin/Site.php:598 msgid "How much comments should be shown for each post? Default value is 100." msgstr "" -#: src/Module/Admin/Site.php:602 +#: src/Module/Admin/Site.php:599 msgid "Maximum numbers of comments per post on the display page" msgstr "" -#: src/Module/Admin/Site.php:602 +#: src/Module/Admin/Site.php:599 msgid "" "How many comments should be shown on the single view for each post? Default " "value is 1000." msgstr "" -#: src/Module/Admin/Site.php:603 +#: src/Module/Admin/Site.php:600 msgid "Temp path" msgstr "" -#: src/Module/Admin/Site.php:603 +#: src/Module/Admin/Site.php:600 msgid "" "If you have a restricted system where the webserver can't access the system " "temp path, enter another path here." msgstr "" -#: src/Module/Admin/Site.php:604 +#: src/Module/Admin/Site.php:601 msgid "Only search in tags" msgstr "" -#: src/Module/Admin/Site.php:604 +#: src/Module/Admin/Site.php:601 msgid "On large systems the text search can slow down the system extremely." msgstr "" -#: src/Module/Admin/Site.php:606 +#: src/Module/Admin/Site.php:603 msgid "New base url" msgstr "" -#: src/Module/Admin/Site.php:606 +#: src/Module/Admin/Site.php:603 msgid "" "Change base url for this server. Sends relocate message to all Friendica and " "Diaspora* contacts of all users." msgstr "" -#: src/Module/Admin/Site.php:608 +#: src/Module/Admin/Site.php:605 msgid "Maximum number of parallel workers" msgstr "" -#: src/Module/Admin/Site.php:608 +#: src/Module/Admin/Site.php:605 #, php-format msgid "" "On shared hosters set this to %d. On larger systems, values of %d are great. " "Default value is %d." msgstr "" -#: src/Module/Admin/Site.php:609 +#: src/Module/Admin/Site.php:606 msgid "Enable fastlane" msgstr "" -#: src/Module/Admin/Site.php:609 +#: src/Module/Admin/Site.php:606 msgid "" "When enabed, the fastlane mechanism starts an additional worker if processes " "with higher priority are blocked by processes of lower priority." msgstr "" -#: src/Module/Admin/Site.php:611 +#: src/Module/Admin/Site.php:608 msgid "Direct relay transfer" msgstr "" -#: src/Module/Admin/Site.php:611 +#: src/Module/Admin/Site.php:608 msgid "" "Enables the direct transfer to other servers without using the relay servers" msgstr "" -#: src/Module/Admin/Site.php:612 +#: src/Module/Admin/Site.php:609 msgid "Relay scope" msgstr "" -#: src/Module/Admin/Site.php:612 +#: src/Module/Admin/Site.php:609 msgid "" "Can be \"all\" or \"tags\". \"all\" means that every public post should be " "received. \"tags\" means that only posts with selected tags should be " "received." msgstr "" -#: src/Module/Admin/Site.php:612 src/Module/Contact.php:473 +#: src/Module/Admin/Site.php:609 src/Module/Contact.php:473 #: src/Module/Settings/TwoFactor/Index.php:118 msgid "Disabled" msgstr "" -#: src/Module/Admin/Site.php:612 +#: src/Module/Admin/Site.php:609 msgid "all" msgstr "" -#: src/Module/Admin/Site.php:612 +#: src/Module/Admin/Site.php:609 msgid "tags" msgstr "" -#: src/Module/Admin/Site.php:613 +#: src/Module/Admin/Site.php:610 msgid "Server tags" msgstr "" -#: src/Module/Admin/Site.php:613 +#: src/Module/Admin/Site.php:610 msgid "Comma separated list of tags for the \"tags\" subscription." msgstr "" -#: src/Module/Admin/Site.php:614 +#: src/Module/Admin/Site.php:611 msgid "Deny Server tags" msgstr "" -#: src/Module/Admin/Site.php:614 +#: src/Module/Admin/Site.php:611 msgid "Comma separated list of tags that are rejected." msgstr "" -#: src/Module/Admin/Site.php:615 +#: src/Module/Admin/Site.php:612 msgid "Allow user tags" msgstr "" -#: src/Module/Admin/Site.php:615 +#: src/Module/Admin/Site.php:612 msgid "" "If enabled, the tags from the saved searches will used for the \"tags\" " "subscription in addition to the \"relay_server_tags\"." msgstr "" -#: src/Module/Admin/Site.php:618 +#: src/Module/Admin/Site.php:615 msgid "Start Relocation" msgstr "" From 9a5e6642b64f9fafe0afbbcf061cf626f57be3a4 Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 5 Nov 2021 21:07:14 +0100 Subject: [PATCH 13/14] Add Unique-Id for each worker execution --- src/Core/Logger/Type/WorkerLogger.php | 19 ++-- tests/src/Core/Logger/WorkerLoggerTest.php | 110 +++++++++++---------- 2 files changed, 72 insertions(+), 57 deletions(-) diff --git a/src/Core/Logger/Type/WorkerLogger.php b/src/Core/Logger/Type/WorkerLogger.php index fcbe12801..caae45bca 100644 --- a/src/Core/Logger/Type/WorkerLogger.php +++ b/src/Core/Logger/Type/WorkerLogger.php @@ -31,6 +31,9 @@ use Psr\Log\LoggerInterface; */ class WorkerLogger implements LoggerInterface { + /** @var int Length of the unique worker id */ + const WORKER_ID_LENGTH = 7; + /** * @var LoggerInterface The original Logger instance */ @@ -48,17 +51,14 @@ class WorkerLogger implements LoggerInterface /** * @param LoggerInterface $logger The logger for worker entries - * @param string $functionName The current function name of the worker - * @param int $idLength The length of the generated worker ID * * @throws LoggerException */ - public function __construct(LoggerInterface $logger, string $functionName = '', int $idLength = 7) + public function __construct(LoggerInterface $logger) { - $this->logger = $logger; - $this->functionName = $functionName; + $this->logger = $logger; try { - $this->workerId = Strings::getRandomHex($idLength); + $this->workerId = Strings::getRandomHex(self::WORKER_ID_LENGTH); } catch (\Exception $exception) { throw new LoggerException('Cannot generate random Hex.', $exception); } @@ -68,10 +68,17 @@ class WorkerLogger implements LoggerInterface * Sets the function name for additional logging * * @param string $functionName + * + * @throws LoggerException */ public function setFunctionName(string $functionName) { $this->functionName = $functionName; + try { + $this->workerId = Strings::getRandomHex(self::WORKER_ID_LENGTH); + } catch (\Exception $exception) { + throw new LoggerException('Cannot generate random Hex.', $exception); + } } /** diff --git a/tests/src/Core/Logger/WorkerLoggerTest.php b/tests/src/Core/Logger/WorkerLoggerTest.php index 0f751f2e4..39b217552 100644 --- a/tests/src/Core/Logger/WorkerLoggerTest.php +++ b/tests/src/Core/Logger/WorkerLoggerTest.php @@ -27,72 +27,47 @@ use Psr\Log\LoggerInterface; class WorkerLoggerTest extends MockedTest { - private function assertUid($uid, $length = 7) + private function assertUid($uid) { - self::assertRegExp('/^[a-zA-Z0-9]{' . $length . '}+$/', $uid); - } - - /** - * Test the a id with length zero - * - */ - public function testGetWorkerIdZero() - { - $this->expectException(\Error::class); - - $logger = \Mockery::mock(LoggerInterface::class); - new WorkerLogger($logger, 'test', 0); - } - - /** - * Test the generated Uid - */ - public function testGetWorkerId() - { - $logger = \Mockery::mock(LoggerInterface::class); - for ($i = 1; $i < 14; $i++) { - $workLogger = new WorkerLogger($logger, 'test', $i); - $uid = $workLogger->getWorkerId(); - self::assertUid($uid, $i); - } + self::assertRegExp('/^[a-zA-Z0-9]{' . WorkerLogger::WORKER_ID_LENGTH . '}+$/', $uid); } public function dataTest() { return [ 'info' => [ - 'func' => 'info', - 'msg' => 'the alert', + 'func' => 'info', + 'msg' => 'the alert', 'context' => [], ], 'alert' => [ - 'func' => 'alert', - 'msg' => 'another alert', + 'func' => 'alert', + 'msg' => 'another alert', 'context' => ['test' => 'it'], ], 'critical' => [ - 'func' => 'critical', - 'msg' => 'Critical msg used', + 'func' => 'critical', + 'msg' => 'Critical msg used', 'context' => ['test' => 'it', 'more' => 0.24545], ], 'error' => [ - 'func' => 'error', - 'msg' => 21345623, + 'func' => 'error', + 'msg' => 21345623, 'context' => ['test' => 'it', 'yet' => true], ], 'warning' => [ - 'func' => 'warning', - 'msg' => 'another alert' . 123523 . 324.54534 . 'test', + 'func' => 'warning', + 'msg' => 'another alert' . 123523 . 324.54534 . 'test', 'context' => ['test' => 'it', 2 => 'nope'], ], 'notice' => [ - 'func' => 'notice', - 'msg' => 'Notice' . ' alert' . true . 'with' . '\'strange\'' . 1.24. 'behavior', + 'func' => 'notice', + 'msg' => 'Notice' . ' alert' . true . 'with' . '\'strange\'' . 1.24. 'behavior', 'context' => ['test' => 'it'], ], 'debug' => [ - 'func' => 'debug', - 'msg' => 'at last a debug', + 'func' => 'debug', + 'msg' => 'at last a debug', 'context' => ['test' => 'it'], ], ]; @@ -104,11 +79,11 @@ class WorkerLoggerTest extends MockedTest */ public function testEmergency($func, $msg, $context = []) { - $logger = \Mockery::mock(LoggerInterface::class); - $workLogger = new WorkerLogger($logger, 'test'); - $testContext = $context; - $testContext['worker_id'] = $workLogger->getWorkerId(); - $testContext['worker_cmd'] = 'test'; + $logger = \Mockery::mock(LoggerInterface::class); + $workLogger = new WorkerLogger($logger); + $testContext = $context; + $testContext['worker_id'] = $workLogger->getWorkerId(); + $testContext['worker_cmd'] = ''; self::assertUid($testContext['worker_id']); $logger ->shouldReceive($func) @@ -122,11 +97,44 @@ class WorkerLoggerTest extends MockedTest */ public function testLog() { - $logger = \Mockery::mock(LoggerInterface::class); - $workLogger = new WorkerLogger($logger, 'test'); - $context = $testContext = ['test' => 'it']; - $testContext['worker_id'] = $workLogger->getWorkerId(); - $testContext['worker_cmd'] = 'test'; + $logger = \Mockery::mock(LoggerInterface::class); + $workLogger = new WorkerLogger($logger); + $context = $testContext = ['test' => 'it']; + $testContext['worker_id'] = $workLogger->getWorkerId(); + $testContext['worker_cmd'] = ''; + self::assertUid($testContext['worker_id']); + $logger + ->shouldReceive('log') + ->with('debug', 'a test', $testContext) + ->once(); + $workLogger->log('debug', 'a test', $context); + } + + + /** + * Test the WorkerLogger after setting a worker function + */ + public function testChangedId() + { + $logger = \Mockery::mock(LoggerInterface::class); + $workLogger = new WorkerLogger($logger); + $context = $testContext = ['test' => 'it']; + $testContext['worker_id'] = $workLogger->getWorkerId(); + $testContext['worker_cmd'] = ''; + self::assertUid($testContext['worker_id']); + $logger + ->shouldReceive('log') + ->with('debug', 'a test', $testContext) + ->once(); + $workLogger->log('debug', 'a test', $context); + + $workLogger->setFunctionName('testFunc'); + + self::assertNotEquals($testContext['worker_id'], $workLogger->getWorkerId()); + + $context = $testContext = ['test' => 'it']; + $testContext['worker_id'] = $workLogger->getWorkerId(); + $testContext['worker_cmd'] = 'testFunc'; self::assertUid($testContext['worker_id']); $logger ->shouldReceive('log') From ccc4e5e40cc626ce9cdaed837d0a7f997984b49d Mon Sep 17 00:00:00 2001 From: Philipp Date: Fri, 5 Nov 2021 21:13:27 +0100 Subject: [PATCH 14/14] Fixed `MovedPermanently` exception name --- .../{MovedPermanently.php => MovedPermanentlyException.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/Network/HTTPException/{MovedPermanently.php => MovedPermanentlyException.php} (100%) diff --git a/src/Network/HTTPException/MovedPermanently.php b/src/Network/HTTPException/MovedPermanentlyException.php similarity index 100% rename from src/Network/HTTPException/MovedPermanently.php rename to src/Network/HTTPException/MovedPermanentlyException.php