From f8b7e460f550d47d6434f94080ae4fdb96b07bd4 Mon Sep 17 00:00:00 2001 From: Asem Alalami Date: Thu, 26 Sep 2024 15:11:13 +0300 Subject: [PATCH] an option to split queues for auto balancing --- config/horizon.php | 14 ++++++++++++++ src/Repositories/RedisWorkloadRepository.php | 4 ++-- src/Supervisor.php | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/config/horizon.php b/config/horizon.php index 5101f6f0..6f3baaf3 100644 --- a/config/horizon.php +++ b/config/horizon.php @@ -168,6 +168,20 @@ 'memory_limit' => 64, + /* + |-------------------------------------------------------------------------- + | Process Per Queue + |-------------------------------------------------------------------------- + | + | This option allows you to execute separate processes for every + | supervisor's queue if the balancing strategy is "auto". + | Disabling it will stop splitting queues so the worker will + | will handle many queues + | + */ + + 'process_per_queue' => true, + /* |-------------------------------------------------------------------------- | Queue Worker Configuration diff --git a/src/Repositories/RedisWorkloadRepository.php b/src/Repositories/RedisWorkloadRepository.php index a476e176..f0ca22cb 100644 --- a/src/Repositories/RedisWorkloadRepository.php +++ b/src/Repositories/RedisWorkloadRepository.php @@ -80,9 +80,9 @@ public function get() $splitQueues = Str::contains($queue, ',') ? $length->map(function ($length, $queueName) use ($connection, $totalProcesses, &$wait) { return [ - 'name' => $queueName, + 'name' => "$queueName", 'length' => $length, - 'wait' => $wait += $this->waitTime->calculateTimeToClear($connection, $queueName, $totalProcesses), + 'wait' => $wait += $this->waitTime->calculateTimeToClear($connection, "$queueName", $totalProcesses), ]; }) : null; diff --git a/src/Supervisor.php b/src/Supervisor.php index 03864611..4dd12de4 100644 --- a/src/Supervisor.php +++ b/src/Supervisor.php @@ -87,7 +87,7 @@ public function __construct(SupervisorOptions $options) */ public function createProcessPools() { - return $this->options->balancing() + return $this->options->balancing() && config('horizon.process_per_queue', true) ? $this->createProcessPoolPerQueue() : $this->createSingleProcessPool(); }