Skip to content

Commit dc64e65

Browse files
authored
Improve queue stats (#56)
* increase productio worker count * Improve queue stats output * cs fix * further increase worker count (#55)
1 parent d1b1ff1 commit dc64e65

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

app/Health/QueueLengthCheck.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Health;
4+
5+
use Laravel\Horizon\Contracts\JobRepository;
6+
use Spatie\Health\Checks\Check;
7+
use Spatie\Health\Checks\Result;
8+
9+
class QueueLengthCheck extends Check
10+
{
11+
public function run(): Result
12+
{
13+
/** @var JobRepository $jobs */
14+
$jobs = app(JobRepository::class);
15+
16+
$result = Result::make()
17+
->appendMeta([
18+
'pending' => $jobs->countPending(),
19+
'failed' => $jobs->countFailed(),
20+
'completed' => $jobs->countCompleted()
21+
]);
22+
23+
if ($jobs->countPending() > 50000) {
24+
return $result
25+
->failed('Job queue larger than 50.000 items')
26+
->shortSummary('Excessive queue length');
27+
}
28+
29+
return $result->ok();
30+
}
31+
}

app/Providers/HealthCheckProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Providers;
44

5+
use App\Health\QueueLengthCheck;
56
use Illuminate\Support\ServiceProvider;
67
use Spatie\CpuLoadHealthCheck\CpuLoadCheck;
78
use Spatie\Health\Checks\Checks\DatabaseCheck;
@@ -29,6 +30,7 @@ public function boot(): void
2930
UsedDiskSpaceCheck::new(),
3031
DatabaseCheck::new(),
3132
HorizonCheck::new(),
33+
QueueLengthCheck::new(),
3234
RedisCheck::new(),
3335
CpuLoadCheck::new()
3436
]);

config/horizon.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,12 @@
211211
'environments' => [
212212
'production' => [
213213
'supervisor-default' => [
214-
'maxProcesses' => 15,
214+
'maxProcesses' => 20,
215215
'balanceMaxShift' => 1,
216216
'balanceCooldown' => 3,
217217
],
218218
'supervisor-updates' => [
219-
'maxProcesses' => 40,
219+
'maxProcesses' => 80,
220220
'balanceMaxShift' => 1,
221221
'balanceCooldown' => 3,
222222
],

routes/console.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
Schedule::command(CleanupSitesList::class)->everySixHours();
99
Schedule::command(PruneFailedJobsCommand::class)->daily();
1010
Schedule::command(QueueHealthChecks::class)->everyFifteenMinutes();
11+
Schedule::command('horizon:snapshot')->everyFiveMinutes();

0 commit comments

Comments
 (0)