V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Jan 18, 2023 · 2526 views
    This topic created in 1201 days ago, the information mentioned may be changed or developed.
    • 起先是线上把 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 replies    2023-05-06 04:45:50 +08:00
    simple2025
        1
    simple2025  
       Jan 18, 2023
    gevent 是为了应对高并发吧, 一般没有高并发肯定是把进程当线程用最爽
    mayli
        2
    mayli  
       May 6, 2023 via Android
    你的 mysql 部分会不会跟 Gevent 不兼容?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2345 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 15:38 · PVG 23:38 · LAX 08:38 · JFK 11:38
    ♥ Do have faith in what you're doing.