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

用 tornado 的同学 你们用 Nginx 吗

  •  
  •   mulog · 2014-11-18 17:14:20 +08:00 · 5114 次点击
    这是一个创建于 3418 天前的主题,其中的信息可能已经有所发展或是发生改变。
    一直都是单进程裸跑tornado 前两天心血来潮测试了一下Nginx后面跑四个tornado
    跑hello world的话,Nginx 的 request per second 倒是可以达到单tornado的两倍多
    但是如果带上了后面的db查询 成绩基本就差不多啦 甚至还稍稍慢点

    想问问在生产环境到底要不要在tornado前面加上Nginx呢?
    如果加的话有哪些配置需要注意以提高性能?
    或者说有其他性能之外的好处?
    10 条回复    2017-02-16 21:42:24 +08:00
    shiny
        1
    shiny  
       2014-11-18 17:17:32 +08:00   ❤️ 1

    维护起来方便
    充分利用多核 CPU
    zeeler
        2
    zeeler  
       2014-11-18 17:28:30 +08:00   ❤️ 1
    必须加呀,tornado跑一个实例很浪费的;另外,db查询速度和带不带nginx没啥关系,请优化db本身,比如读写分离、增加cache层、分布式等等
    kslr
        3
    kslr  
       2014-11-18 17:39:24 +08:00   ❤️ 2
    一般都是多少颗CPU,就起多少实例,前面用nginx负载均衡。
    zeeler
        4
    zeeler  
       2014-11-18 18:25:39 +08:00
    看下官方文档,非常建议用nginx http://unicorn.bogomips.org/PHILOSOPHY.html
    By acting as a buffer to shield unicorn from slow I/O, a reverse proxy will inevitably incur overhead in the form of extra data copies.
    .....
    nginx is the only (Free) solution we know of that meets the above requirements.
    skybr
        5
    skybr  
       2014-11-18 18:33:16 +08:00   ❤️ 1
    db查询也得找异步库, tornado那个分离出去的mysql db库是block的, 而且如果要测得相对准一点, db和应用最好别放在同一个节点上.
    mulog
        6
    mulog  
    OP
       2014-11-18 18:40:28 +08:00
    @skybr
    我的应用里数据库查询是一个分离出去的服务 服务调用也是异步的 所以应该没问题
    不过我也觉得是该把db放另一台机器上测试 因为我们生产环境也是这样 谢谢建议~
    msg7086
        7
    msg7086  
       2014-11-18 19:06:39 +08:00 via iPhone
    Nginx解决的是慢连接问题,不是性能问题。组件变多,性能基本是会降低,所以只有在实际要解决问题的情况下才有意义增加组件。
    wwqgtxx
        8
    wwqgtxx  
       2014-11-18 21:48:14 +08:00 via Android   ❤️ 1
    v2ex就是t+n的
    lianghui
        9
    lianghui  
       2014-11-19 12:54:43 +08:00
    多台机器跑可以用nginx,如果一台机器直接用tornado多进程监听同一端口就行了。
    freestyle
        10
    freestyle  
       2017-02-16 21:42:24 +08:00
    @skybr 请教一下适合 tornado 的异步 db 库是哪个,谢谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   954 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 21:11 · PVG 05:11 · LAX 14:11 · JFK 17:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.