V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
wuwukai007
V2EX  ›  Python

celery 和 gunicorn 的不同 pool 模式,我测下来 sync 性能最好😓

  •  
  •   wuwukai007 · 2023-01-18 15:24:12 +08:00 · 1951 次点击
    这是一个创建于 461 天前的主题,其中的信息可能已经有所发展或是发生改变。
    • 起先是线上把 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
    2 条回复    2023-05-06 04:45:50 +08:00
    chenqh
        1
    chenqh  
       2023-01-18 15:30:10 +08:00
    gevent 是为了应对高并发吧, 一般没有高并发肯定是把进程当线程用最爽
    mayli
        2
    mayli  
       354 天前 via Android
    你的 mysql 部分会不会跟 Gevent 不兼容?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5712 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 01:45 · PVG 09:45 · LAX 18:45 · JFK 21:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.