推荐学习书目
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 · Nov 26, 2018 · 4591 views
    This topic created in 2726 days ago, the information mentioned may be changed or developed.
    以前一直是用 --socket 来部署的,感觉不管用--http 还是-- socket,最后都要包一层 nginx 在外面,就是比较好奇,两种方式在执行效率上哪个会高一些
    10 replies    2018-11-27 08:25:48 +08:00
    wingyiu
        1
    wingyiu  
       Nov 26, 2018
    文档有写
    wizardoz
        2
    wizardoz  
       Nov 26, 2018
    http 的话,nginx 和 uwsgi 中间走的是 http 协议,文本
    socket 的话,nginx 和 uwsgi 中间走的是 wsgi 协议,二进制

    感觉 wsgi 协议效率会更高一点
    knightdf
        3
    knightdf  
       Nov 26, 2018   ❤️ 1
    通信协议不一样,就这,http 的多了包校验之类的
    xpresslink
        4
    xpresslink  
       Nov 26, 2018   ❤️ 1
    连接方式其实有三种
    unix Socket,这个性能效率最高,直接内存交换,但必须应用和 NGX 同在一台服务器上
    TCP Socket, 二进制包传递
    HTTP, 是基于 TCP 上面的一层文本协议
    chengxiao
        5
    chengxiao  
    OP
       Nov 26, 2018
    @xpresslink 感谢,其实问这个问题是因为现在想用 docker 来部署,想把 docker+uwsgi 放一个容器,然后 nginx 单独一个容器,似乎这样部署就只能用 http 了
    allen0125
        6
    allen0125  
       Nov 26, 2018
    在文档里面看到一句
    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  
       Nov 26, 2018
    生产环境百分之九十九是 unix Socket 的方式,ngnix 是做反向代理用的,因为 uwsgi 不具备路由、过滤等方向代理功能,但论执行效率,可以做性能测试,如果是 http 协议的话,性能是没有 unix Socket 方式好的
    xpresslink
        8
    xpresslink  
       Nov 26, 2018
    @chengxiao 用 docker 来部署一般用 TCP socket,如果容器用主机网络模式,用个不冲突的端口号就可以了。
    chengxiao
        9
    chengxiao  
    OP
       Nov 26, 2018
    @allen0125 静态文件可以挂载出来的吧
    wonderay
        10
    wonderay  
       Nov 27, 2018
    @allen0125 可以共享 volume

    @chengxiao 也可以用 socket
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3389 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 11:25 · PVG 19:25 · LAX 04:25 · JFK 07:25
    ♥ Do have faith in what you're doing.