aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/QueueWorker.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2022-12-10 17:03:57 +0000
committerMario <mario@mariovavti.com>2022-12-10 17:03:57 +0000
commite1c28351734d175476bc8f0d6cdf261dee3c07e0 (patch)
tree50b4659c904c0b2803d57d114a104ccd8655fd6c /Zotlabs/Lib/QueueWorker.php
parent4f9a933108eb0a41671ec9464f1d7fb90c2d2233 (diff)
downloadvolse-hubzilla-e1c28351734d175476bc8f0d6cdf261dee3c07e0.tar.gz
volse-hubzilla-e1c28351734d175476bc8f0d6cdf261dee3c07e0.tar.bz2
volse-hubzilla-e1c28351734d175476bc8f0d6cdf261dee3c07e0.zip
add option to set worker sleep based on load average, remove redundand code and add return to some daemons
Diffstat (limited to 'Zotlabs/Lib/QueueWorker.php')
-rw-r--r--Zotlabs/Lib/QueueWorker.php26
1 files changed, 19 insertions, 7 deletions
diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php
index 21983a4e2..48d5f5bb2 100644
--- a/Zotlabs/Lib/QueueWorker.php
+++ b/Zotlabs/Lib/QueueWorker.php
@@ -231,9 +231,6 @@ class QueueWorker {
}
public static function Process() {
- self::$workersleep = get_config('queueworker', 'queue_worker_sleep');
- self::$workersleep = intval(self::$workersleep) > 100 ? intval(self::$workersleep) : 100;
-
if (!self::GetWorkerID()) {
logger('Unable to get worker ID. Exiting.', LOGGER_DEBUG);
killme();
@@ -241,11 +238,26 @@ class QueueWorker {
$jobs = 0;
$workid = self::getWorkId();
+ $load_average_sleep = false;
+ self::$workersleep = get_config('queueworker', 'queue_worker_sleep');
+ self::$workersleep = ((intval(self::$workersleep) > 100) ? intval(self::$workersleep) : 100);
+
+ if (function_exists('sys_getloadavg') && get_config('queueworker', 'load_average_sleep')) {
+ $load_average_sleep = true;
+ }
+
while ($workid) {
+
+ if ($load_average_sleep) {
+ $load_average = sys_getloadavg();
+ self::$workersleep = intval($load_average[0]) * 100000;
+
+ if (!self::$workersleep) {
+ self::$workersleep = 100;
+ }
+ }
+
usleep(self::$workersleep);
- // @FIXME: Currently $workersleep is a fixed value. It may be a good idea
- // to implement a "backoff" instead - based on load average or some
- // other metric.
self::qbegin('workerq');
@@ -276,7 +288,7 @@ class QueueWorker {
$workinfo = json_decode($workitem[0]['workerq_data'], true);
$argv = $workinfo['argv'];
- logger('Master: process: ' . json_encode($argv), LOGGER_DEBUG);
+ hz_syslog('Master: process: ' . json_encode($argv), LOGGER_DEBUG);
$cls = '\\Zotlabs\\Daemon\\' . $argv[0];
$argv = flatten_array_recursive($argv);