Optimize gunicorn worker configuration#7935
Conversation
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughGunicorn startup flags in the Dockerfile are changed to a single gthread worker with 5 threads and max-requests recycling; Celery is configured to recycle child workers after 100 tasks; tests were added to validate both Dockerfile Gunicorn flags and the Celery setting. ChangesDeployment configuration
🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
specifyweb/celery_tasks.py (1)
13-13: Add regression coverage for the Celery recycle limit.This is part of the rollout, but it is currently untested in the provided changes. A small test that asserts
app.conf.worker_max_tasks_per_child == 100would keep the Celery half from regressing while the Dockerfile checks still pass.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@specifyweb/celery_tasks.py` at line 13, Add a regression unit test that asserts the Celery recycle limit remains set to 100 by checking app.conf.worker_max_tasks_per_child equals 100; implement this in the test suite (e.g., create a new test function like test_celery_worker_max_tasks_per_child) import or fixture the same Celery `app` used in specifyweb/celery_tasks.py, and assert app.conf.worker_max_tasks_per_child == 100 so changes to that value will fail the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/test_deployment_config.py`:
- Around line 53-65: The tests test_max_requests_present and
test_threads_configured are too permissive; change them to assert the exact
tuned values: verify that "--max-requests" exists and that the parsed value
equals 500, verify that "--threads" exists and that the parsed value equals 50,
and add a new assertion to check that "--max-requests-jitter" exists and its
parsed value equals 5 (all using the same pattern of finding the flag in
self.args and reading the next element). Use the existing parsing pattern (idx =
self.args.index(...); value = int(self.args[idx + 1])) and update the assertion
messages to reflect the expected exact values.
---
Nitpick comments:
In `@specifyweb/celery_tasks.py`:
- Line 13: Add a regression unit test that asserts the Celery recycle limit
remains set to 100 by checking app.conf.worker_max_tasks_per_child equals 100;
implement this in the test suite (e.g., create a new test function like
test_celery_worker_max_tasks_per_child) import or fixture the same Celery `app`
used in specifyweb/celery_tasks.py, and assert
app.conf.worker_max_tasks_per_child == 100 so changes to that value will fail
the test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 6b977e44-70d2-4f56-8c82-23276698e998
📒 Files selected for processing (3)
Dockerfilespecifyweb/celery_tasks.pytests/test_deployment_config.py
Tighten --max-requests (500), --threads (5) assertions, add coverage for --max-requests-jitter (50) and celery worker_max_tasks_per_child (100). Addresses review feedback on specify#7935.
Fixes #7880
Contributed by @foozleface
The default gunicorn configuration uses 3 sync workers, each a separate forked process holding its own copy of the Django app in memory. For a memory-constrained container, switching to gthread (1 worker with 5 threads) reduces RSS by ~60% while maintaining concurrency. Periodic worker restart via
--max-requestsprevents memory leaks from accumulating. Celery workers also getworker_max_tasks_per_child=100for the same reason.Implementation
gunicorn -w 3(sync) togunicorn --worker-class gthread -w 1 --threads 5 --max-requests 500 --max-requests-jitter 50app.conf.worker_max_tasks_per_child = 100tocelery_tasks.pyso Celery workers restart after 100 tasksTesting instructions
docker logs <container> | grep gthreadpytest tests/test_deployment_config.py -vSummary by CodeRabbit
Tests
Chores