-
Notifications
You must be signed in to change notification settings - Fork 658
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
'Memory Exhausted' when removing monitored tag #625
Comments
I reported the same some time ago: #271 Apparently some fix was applied related to expiration, but to me it was clear the overhead is too risky for production when you suddenly get an influx o jobs. Which is kind of a paradox if you consider the purpose of a queue system: it shouldn't matter whether you have 100 or 100.000.000 jobs, regardless of the monitoring tag or not. |
I really have no clue on how to even begin approaching this tbh. @mfn to me it seems this is just out of Horizon's scope to handle? |
Maybe it's a documentation/warning issue: if you use tags, meta data gets written to redis which increases the size drastically. I think it's easy to reproduce, one just has to compare redis DB size locally / RAM :
Versus:
|
the |
@guntherdebrauwer maybe yeah. I'm not sure what the impact of that would be? Ping @themsaid |
Please note that this and my issue is about Redis memory exhaustion, not PHP; it's a problem with the amount of data stored within redis with tagging and large amount of jobs. |
@mfn why is this a Redis memory exhaustian? It's true that monitoring causes a lot of data storage within redis, but that didn't cause the exhaustion error (my server memory usage was only 65-70%). The problem was removing my monitored tag did not deleted all jobs of that tag. It tried to load all jobs into php memory, to then delete them one by one. And loading couple of 100 000 jobs from redis-server caused the memory exhaustion. That's what I think happens. Correct me if I'm wrong class StopMonitoringTag
{
public function handle(JobRepository $jobs, TagRepository $tags)
{
// Remove tag from monitoring
$tags->stopMonitoring($this->tag);
// Load all tags
// This causes memory exhaustion, as it tries to load couple of 100 000 jobs into php memory
$tagJobs = $tags->jobs($this->tag);
// Delete all loaded tag jobs one by one
$jobs->deleteMonitored($tagJobs);
$tags->forget($this->tag);
}
} |
@guntherdebrauwer apologies, I think I must have misread some parts and thought it was exactly the issue I once experienced => in this case, please disregard my comments 🙇 |
@mfn No problem 🙂 I do agree that the documentation maybe should include a warning regarding the increased memory usage / saved data in redis when monitoring a tag. |
Checking in on this again. I agree that we should maybe batch the deletions somehow. Not sure atm how that would be done. |
the $tagJobs = $tags->paginate($this->tag);
while (count($tagJogs) !== 0) {
$jobs->deleteMonitored($tagJobs);
$tagJobs = $tags->paginate($this->tag);
} |
Description:
I was monitoring a tag on my production server. That tag was linked to a couple of 100 000 jobs.
I suddenly noticed that my redis-server was using a lot of memory (almost 10GB) and I discovered that it was caused by the monitoring.
When I removed the monitoring, the issue persisted and the RAM usage did not chage.
After further investigation, I saw that the
StopMonitoringTag
job class failed because the memory was exhausted. That's because all the jobs (couple of 100 000 jobs) are all fetched/loaded in php and then deleted.Should this not be done paginated?
I suspect this may be an issue in other places as well, if Horizon fetches a huge amount of jobs (e.g. trimming recent/failed/monitored jobs)
(The only way I could fix this issue, was
redis-cli flushdb
, which is normally not ideal on a production server 😅)Steps To Reproduce:
StopMonitoringTag
job class manually via tinker. This will throw a 'memory exhausted' error.The text was updated successfully, but these errors were encountered: