-
Notifications
You must be signed in to change notification settings - Fork 663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
High memory usage in redis #715
Comments
I have the same issue, the jobs when finished appear to not be removed from the redis memory, resulting in high memory usage. Running about 500k jobs per day What are your trim values in |
'trim' => [
'recent' => 30,
'recent_failed' => 30,
'failed' => 60,
'monitored' => 0
], I can't find a trim option for completed jobs tho |
The problem seems to be that |
|
Thats our fix in a horizon fork with diff --git a/config/horizon.php b/config/horizon.php
index b9803a8..318a945 100644
--- a/config/horizon.php
+++ b/config/horizon.php
@@ -98,6 +98,7 @@ return [
'recent_failed' => 10080,
'failed' => 10080,
'monitored' => 10080,
+ 'completed' => 60,
],
/*
diff --git a/src/Repositories/RedisJobRepository.php b/src/Repositories/RedisJobRepository.php
index 171b040..dfb2cac 100644
--- a/src/Repositories/RedisJobRepository.php
+++ b/src/Repositories/RedisJobRepository.php
@@ -66,6 +66,7 @@ class RedisJobRepository implements JobRepository
{
$this->redis = $redis;
$this->recentJobExpires = config('horizon.trim.recent', 60);
+ $this->completedJobExpires = config('horizon.trim.completed', 60);
$this->failedJobExpires = config('horizon.trim.failed', 10080);
$this->recentFailedJobExpires = config('horizon.trim.recent_failed', $this->failedJobExpires);
$this->monitoredJobExpires = config('horizon.trim.monitored', 10080);
@@ -405,7 +406,7 @@ class RedisJobRepository implements JobRepository
? $pipe->hmset($id, ['status' => 'failed'])
: $pipe->hmset($id, ['status' => 'completed', 'completed_at' => str_replace(',', '.', microtime(true))]);
- $pipe->expireat($id, Chronos::now()->addMinutes($this->recentJobExpires)->getTimestamp());
+ $pipe->expireat($id, Chronos::now()->addMinutes($this->completedJobExpires)->getTimestamp());
}
/** |
I have similar issues. I was able to get the job to expire correctly by setting That said, I still have an issue of memory slowing filling up, and I think it's because keys are left behind in the |
Please see #625 Are you all monitoring tags? |
No, I’m not monitoring any tags at all.
|
Neither I. The problem is indeed Horizon not cleaning completed jobs until |
I think there are two issues here. First, as reported by @mauri870, is that completed jobs are retained for 1 week by default. This is easily solved by using the undocumented configuration option of Second is that all new job IDs are added to the key Edit: there are two places that fill up. Edit again: I just realized that the configuration option |
@travisaustin I think you are, at least reading the source code. That's why I added |
A solution is proposed in #720 |
I have the same issue, my config is
I'm using gdb to dump the memory of a horizon:work process and I see that many queue doesn't release from memory even it has been finished for hour. it seems an issue of JobMetrics feature. My horizon version: v3.4.3 |
I'm not understanding why #720 was closed? It seems to me the current situation with very high, possibly runaway resource utilization by Redis is a larger issue than possibly wonky pagination? Am I missing something here? @mauri870 it's been a couple of months since your forked solution. How is it holding up and are you experiencing issues with pagination as discused in #720? |
@TheOneDaveYoung IDK why Taylor closed that PR, he mentioned that something was not right with pagination but after we changed to my fork the OOM problems ceased and everything seems to be working great. More than 2 months now without problems. |
#720 was merged. This will unfortunately break pagination. We're currently considering separating the different types of jobs into separate screens to solve this problem. |
Still kind of experiencing this issue. I noticed Horizon uses zsets and hash sets. Maybe there are some sane tunings one can use to improve the memory consumption and performance since by default if you're running millions of jobs, using generic data types will have too much memory spill. |
I am also troubling with high memory usage and my system crashed. Laravel: v8.35.1. Horizon: v5.7 I have around 40k records. I made a chunk of 300 records and process each chunk via job. Users::chunk(300, function($users) {
//dispatch a job
MigrateUsers::dispatch($users->all());
}); My horizon config is: 'waits' => [
'redis:default' => 60,
],
'trim' => [
'recent' => 60,
'pending' => 2880,
'completed' => 60,
'recent_failed' => 1440,
'failed' => 2880,
'monitored' => 2880,
],
'memory_limit' => 128,
'defaults' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'auto',
'minProcesses' => 1,
'maxProcesses' => 2,
'memory' => 128,
'tries' => 2,
'nice' => 0,
],
],
'environments' => [
'local' => [
'supervisor-1' => [
'maxProcesses' => 2,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
'timeout' => 900 // Timeout after 15 minutes
],
],
] And in this process 7 to 8 GB of RAM is consumed and the system reboots in between. |
Description:
After we upgraded from Laravel 5.8 to 6.6 / Horizon 3.2.2 to 3.4.3 the resource consumption of our redis 4 server started to grow exponentially, sitting at around 5Gb.
Horizon Dashboard:
Redis instance dedicated to horizon:
Previous version vs new (the release was pushed Nov 25):
Steps To Reproduce:
We have no clue of what is causing this behavior, but our number of jobs is almost the same as before, the only difference is the framework and horizon versions.
The text was updated successfully, but these errors were encountered: