This project provides a production-quality comparison between Django's built-in Tasks and Celery.
- Python 3.12+
- Redis (installed and running on port 6379)
- Dependencies:
pip install django celery redis psutil django-tasks
tasks_demo/tasks.py: Implementation of workloads (Email, I/O, CPU, Batch, DB Contention, HTTP Fan-out, Throughput Burst).benchmark.py: Load testing script.demo_project/settings.py: Integrated configuration for both systems.SPIKE_REPORT.md: Comprehensive engineering analysis and final recommendation (Main Doc).Spike_Report_Django_Background_Tasks.docx: Professional documentation for stakeholders.
Start Redis (for Celery):
redis-server --port 6379Run each in a separate terminal:
# Celery (4 concurrent workers)
celery -A demo_project worker --loglevel=info --concurrency=4
# Django Tasks (Start 2-4 workers for concurrency)
python manage.py db_worker --worker-id w1
python manage.py db_worker --worker-id w2Execute the benchmark script with different load parameters:
# Standard Load
python benchmark.py --batch 10 --iter 2
# High Volume Throughput Test (Tests Redis vs DB Enqueue speed)
python benchmark.py --batch 50 --iter 5To view real-time metrics, start the Django dev server:
python manage.py runserverThen visit:
- Metrics API:
http://localhost:8000/metrics/(Aggregated JSON) - DB Inspection:
python manage.py dbshell->select * from tasks_demo_taskmetric;
- Exec Avg: Execution time inside the worker.
- Lat Avg: Queue latency (time spent waiting for a worker).
- Lat P95: Tail latency (helps identify "stuck" tasks or broker bottlenecks).
- Latency: Time from enqueue to execution start.
- Execution Time: Real-time taken by the worker.
- Success Rate: Count of tasks finishing without error.
- Queue Depth: Check
django_tasks_database_dbtaskresulttable for Django or RedisLLENfor Celery.