delete expired results in batches to avoid running OOM - #483
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR modifies the deletion of expired results to process records in batches, thereby reducing the likelihood of running out of memory. It also updates a benchmark test threshold to reflect the changes in deletion performance.
- Adjust benchmark test assertion to allow higher timing.
- Implement batched deletion in the manager to mitigate OOM issues.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| t/integration/benchmark_models.py | Updated test assertion threshold from 1 to 5 |
| django_celery_results/managers.py | Introduced batched deletion with a configurable batch_size |
Comments suppressed due to low confidence (2)
t/integration/benchmark_models.py:70
- [nitpick] Consider adding a comment to explain why the threshold was increased from 1 to 5, clarifying the trade-off in benchmark performance due to the batched deletion implementation.
assert self.benchmark.stats.stats.max < 5
django_celery_results/managers.py:87
- [nitpick] Review the default batch_size value of 100000 to ensure that it is appropriate for production workloads; consider making this parameter externally configurable if necessary.
def delete_expired(self, expires, batch_size=100000):
auvipy
requested changes
Jun 25, 2025
| return self.filter(date_done__lt=now() - maybe_timedelta(expires)) | ||
|
|
||
| def delete_expired(self, expires): | ||
| def delete_expired(self, expires, batch_size=100000): |
Member
There was a problem hiding this comment.
can we also add some unit test for this?
auvipy
approved these changes
Jul 2, 2025
Contributor
Author
|
@auvipy is there a chance to get a new release with this fix included? |
Member
|
yes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #430