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

用用 uwsgi 来部署 django 项目用--http 和--socket 的不同处在哪?

  •  
  •   chengxiao · 2018-11-26 10:59:50 +08:00 · 3776 次点击
    这是一个创建于 1949 天前的主题,其中的信息可能已经有所发展或是发生改变。
    以前一直是用 --socket 来部署的,感觉不管用--http 还是-- socket,最后都要包一层 nginx 在外面,就是比较好奇,两种方式在执行效率上哪个会高一些
    10 条回复    2018-11-27 08:25:48 +08:00
    wingyiu
        1
    wingyiu  
       2018-11-26 11:07:26 +08:00
    文档有写
    wizardoz
        2
    wizardoz  
       2018-11-26 11:09:59 +08:00
    http 的话,nginx 和 uwsgi 中间走的是 http 协议,文本
    socket 的话,nginx 和 uwsgi 中间走的是 wsgi 协议,二进制

    感觉 wsgi 协议效率会更高一点
    knightdf
        3
    knightdf  
       2018-11-26 14:32:35 +08:00   ❤️ 1
    通信协议不一样,就这,http 的多了包校验之类的
    xpresslink
        4
    xpresslink  
       2018-11-26 15:20:59 +08:00   ❤️ 1
    连接方式其实有三种
    unix Socket,这个性能效率最高,直接内存交换,但必须应用和 NGX 同在一台服务器上
    TCP Socket, 二进制包传递
    HTTP, 是基于 TCP 上面的一层文本协议
    chengxiao
        5
    chengxiao  
    OP
       2018-11-26 15:34:11 +08:00
    @xpresslink 感谢,其实问这个问题是因为现在想用 docker 来部署,想把 docker+uwsgi 放一个容器,然后 nginx 单独一个容器,似乎这样部署就只能用 http 了
    allen0125
        6
    allen0125  
       2018-11-26 16:33:11 +08:00
    在文档里面看到一句
    Using Unix sockets instead of ports
    So far we have used a TCP port socket, because it ’ s simpler, but in fact it ’ s better to use Unix sockets than ports - there ’ s less overhead.

    docker 部署的话,容器里面如果没有 nginx,静态文件怎么搞啊。
    Neojoke
        7
    Neojoke  
       2018-11-26 17:13:58 +08:00
    生产环境百分之九十九是 unix Socket 的方式,ngnix 是做反向代理用的,因为 uwsgi 不具备路由、过滤等方向代理功能,但论执行效率,可以做性能测试,如果是 http 协议的话,性能是没有 unix Socket 方式好的
    xpresslink
        8
    xpresslink  
       2018-11-26 18:25:33 +08:00
    @chengxiao 用 docker 来部署一般用 TCP socket,如果容器用主机网络模式,用个不冲突的端口号就可以了。
    chengxiao
        9
    chengxiao  
    OP
       2018-11-26 21:51:36 +08:00
    @allen0125 静态文件可以挂载出来的吧
    wonderay
        10
    wonderay  
       2018-11-27 08:25:48 +08:00
    @allen0125 可以共享 volume

    @chengxiao 也可以用 socket
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1766 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 16:35 · PVG 00:35 · LAX 09:35 · JFK 12:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.