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
cloudyplain
V2EX  ›  Python

gunicorn 部署问题

  •  
  •   cloudyplain · 2017-04-25 11:24:55 +08:00 · 2878 次点击
    这是一个创建于 2556 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近做 python server 的选型, gunicorn+meinheld/gevent 都不错,但在 nginx 下性能、错误率掉得有点厉害,远不如 nginx+uWSGI+gevent 稳定,请教下如何部署?

    gunicorn -b :18003 -k egg:meinheld#gunicorn_worker  -w 9 mybottle:app 
    
    #or
    
    gunicorn -b :18003 -k gevent_pywsgi  -w 9    mybottle:app
    
    

    nginx.conf

        server {
            listen 8003;
            location / {
                proxy_pass http://127.0.0.1:18003;
            }
        }
    

    谢谢!

    9 条回复    2017-04-26 11:01:04 +08:00
    ryd994
        1
    ryd994  
       2017-04-25 21:53:53 +08:00 via Android
    Nginx 后面挂普通 gunicorn 呢?
    gunicorn 最初的设计就是这样
    junnplus
        2
    junnplus  
       2017-04-25 22:20:19 +08:00
    没有说明机子配置就直接 -w 9 合适么
    junnplus
        3
    junnplus  
       2017-04-25 22:41:49 +08:00   ❤️ 1
    另外 meinheld 在请求高的时候错误率确实会飙高,可以看看这个测评 https://blog.appdynamics.com/engineering/a-performance-analysis-of-python-wsgi-servers-part-2/
    cloudyplain
        4
    cloudyplain  
    OP
       2017-04-25 23:38:23 +08:00
    @junnplus 4 核,因为和问题无关就没有说明,另外 它这个评测 meinheld 是不开 keep-alive 的,我自己测试时没有这么多错误。
    cloudyplain
        5
    cloudyplain  
    OP
       2017-04-25 23:40:09 +08:00
    @ryd994 默认工作模式是阻塞调用,性能不成吧。
    ryd994
        6
    ryd994  
       2017-04-26 00:29:41 +08:00 via Android
    @cloudyplain 默认设计是 Nginx 在前面 buffer
    gunicorn 只需要以最快速度和 Nginx 交换数据并处理请求就行,所以阻塞不会影响性能,这是 gunicorn 官方的说法
    cloudyplain
        7
    cloudyplain  
    OP
       2017-04-26 09:13:23 +08:00
    @ryd994 并不是,一旦 app 中有 block io 这个进程就阻塞了。
    tanywei
        8
    tanywei  
       2017-04-26 10:26:49 +08:00
    回复 mark 一下
    PythonAnswer
        9
    PythonAnswer  
       2017-04-26 11:01:04 +08:00
    digitalocean 有相关部署文章

    nginx+gunicorn+gevent 是最稳定高效的组合
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3324 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:43 · PVG 19:43 · LAX 04:43 · JFK 07:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.