- 起先是线上把 gevent 改成 sync 性能提高了 60%,线上任务主要是 数据库查询和接口请求 io 任务
- 所有数据库查询是 django ORM 和 python-elasticsearch
- 启动方式:
celery -A app worker -Q xxx -P gevent -c 30
celery -A app worker -Q xxx -c 8
celery -A app worker -Q xxx -c 30 -P threads
gunicorn app -k gevent -w 8 --worker-connections=200
gunicorn app -k gthread -w 4 --threads=20
gunicorn app -k sync -w 8
比较纳闷常识是 io 任务用 gevent
处于好奇,本地模拟了下简单的 celery io 任务
celery 任务里,本地模拟了个 task ,锁 id mysql 查询一条数据
分别用 gevent ,sync ,threads
结果是 sync > threads > gevent
sync 和 threads 性能差别不大,gevent 只有前两个的 60%不到
- gunicorn 也是,简单的锁 id 接口,sync > threads > gevent