From 00061a484d633335e00d262c661af22e14524cf3 Mon Sep 17 00:00:00 2001 From: Arjan Date: Wed, 10 Feb 2021 16:30:34 +0100 Subject: [PATCH] Show workload also per queue when balancing is disabled --- resources/js/screens/dashboard.vue | 29 ++++++++++++----- resources/sass/base.scss | 4 +++ src/Repositories/RedisWorkloadRepository.php | 20 +++++++++--- src/WaitTimeCalculator.php | 33 ++++++++++++++------ 4 files changed, 63 insertions(+), 23 deletions(-) diff --git a/resources/js/screens/dashboard.vue b/resources/js/screens/dashboard.vue index 01e7f303..a4805ea4 100644 --- a/resources/js/screens/dashboard.vue +++ b/resources/js/screens/dashboard.vue @@ -278,14 +278,27 @@ - - - {{ queue.name.replace(/,/g, ', ') }} - - {{ queue.processes ? queue.processes.toLocaleString() : 0 }} - {{ queue.length ? queue.length.toLocaleString() : 0 }} - {{ humanTime(queue.wait) }} - + diff --git a/resources/sass/base.scss b/resources/sass/base.scss index 62fa8146..8c62005a 100644 --- a/resources/sass/base.scss +++ b/resources/sass/base.scss @@ -172,6 +172,10 @@ button:hover { } } +.info-icon { + fill: $control-action-icon-color; +} + .paginator { .btn { text-decoration: none; diff --git a/src/Repositories/RedisWorkloadRepository.php b/src/Repositories/RedisWorkloadRepository.php index 23585e68..c3388b0e 100644 --- a/src/Repositories/RedisWorkloadRepository.php +++ b/src/Repositories/RedisWorkloadRepository.php @@ -69,18 +69,28 @@ public function get() return collect($this->waitTime->calculate()) ->map(function ($waitTime, $queue) use ($processes) { [$connection, $queueName] = explode(':', $queue, 2); + $totalProcesses = $processes[$queue] ?? 0; $length = ! Str::contains($queue, ',') - ? $this->queue->connection($connection)->readyNow($queueName) - : collect(explode(',', $queueName))->sum(function ($queueName) use ($connection) { - return $this->queue->connection($connection)->readyNow($queueName); + ? collect($this->queue->connection($connection)->readyNow($queueName)) + : collect(explode(',', $queueName))->mapWithKeys(function ($queueName) use ($connection) { + return [$queueName => $this->queue->connection($connection)->readyNow($queueName)]; }); + $splitQueues = Str::contains($queue, ',') ? $length->map(function($length, $queueName) use ($connection, $totalProcesses) { + return [ + 'name' => $queueName, + 'length' => $length, + 'wait' => $this->waitTime->calculateTimeToClear($connection, $queueName, $totalProcesses), + ]; + }) : null; + return [ 'name' => $queueName, - 'length' => $length, + 'length' => $length->sum(), 'wait' => $waitTime, - 'processes' => $processes[$queue] ?? 0, + 'processes' => $totalProcesses, + 'split_queues' => $splitQueues, ]; })->values()->toArray(); } diff --git a/src/WaitTimeCalculator.php b/src/WaitTimeCalculator.php index fc113fee..991b8aa2 100644 --- a/src/WaitTimeCalculator.php +++ b/src/WaitTimeCalculator.php @@ -75,18 +75,31 @@ public function calculate($queue = null) [$connection, $queueName] = explode(':', $queue, 2); - $timeToClear = ! Str::contains($queueName, ',') - ? $this->timeToClearFor($connection, $queueName) - : collect(explode(',', $queueName))->sum(function ($queueName) use ($connection) { - return $this->timeToClearFor($connection, $queueName); - }); - - return $totalProcesses === 0 - ? [$queue => round($timeToClear / 1000)] - : [$queue => round(($timeToClear / $totalProcesses) / 1000)]; + return [$queue => $this->calculateTimeToClear($connection, $queueName, $totalProcesses)]; })->sort()->reverse()->all(); } + /** + * Calculate the time to clear for the given in queue in seconds distributed over the given amount of processes. + * + * @param string $connection + * @param string $queue + * @param int $totalProcesses + * @return int + */ + public function calculateTimeToClear($connection, $queue, $totalProcesses) + { + $timeToClear = ! Str::contains($queue, ',') + ? $this->timeToClearFor($connection, $queue) + : collect(explode(',', $queue))->sum(function ($queueName) use ($connection) { + return $this->timeToClearFor($connection, $queueName); + }); + + return $totalProcesses === 0 + ? round($timeToClear / 1000) + : round(($timeToClear / $totalProcesses) / 1000); + } + /** * Get all of the queue names. * @@ -110,7 +123,7 @@ protected function queueNames($supervisors, $queue = null) * @param string $queue * @return float */ - protected function timeToClearFor($connection, $queue) + public function timeToClearFor($connection, $queue) { $size = $this->queue->connection($connection)->readyNow($queue);