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

uvicorn 都有 worker 的功能 了 为什么还要 gunicorn 挂 uvicorn worker 启动

  •  
  •   MRlaopeng · 282 天前 · 1400 次点击
    这是一个创建于 282 天前的主题,其中的信息可能已经有所发展或是发生改变。
    16 条回复    2023-08-02 13:57:54 +08:00
    julyclyde
        1
    julyclyde  
       282 天前   ❤️ 1
    参加展会的时候,各展台都会给一个手提袋
    外面画着自家的广告,里面装着别家的手提袋
    MRlaopeng
        2
    MRlaopeng  
    OP
       282 天前
    @julyclyde 虽然你这个回答很妙,,但是,,我还是很疑惑
    ruanimal
        3
    ruanimal  
       282 天前
    https://www.uvicorn.org/#running-with-gunicorn

    read the fucking doc

    This allows you to increase or decrease the number of worker processes on the fly, restart worker processes gracefully, or perform server upgrades without downtime.
    MRlaopeng
        4
    MRlaopeng  
    OP
       282 天前
    ,,我来看看
    MRlaopeng
        5
    MRlaopeng  
    OP
       282 天前
    @ruanimal ,,好吧 官方确实推荐这样使用
    还是有点晦涩难懂,我去找找具体应用实例
    ruanimal
        6
    ruanimal  
       282 天前
    @MRlaopeng 就是 gunicorn 的功能更多,比如动态调整 worker 数量。如果你不需要这些功能,直接用 uvicorn 应该也是可以的吧
    MRlaopeng
        7
    MRlaopeng  
    OP
       282 天前
    @ruanimal 原来如此,,就是想要跟高级的功能, 就得套一层更高级的应用
    locoz
        8
    locoz  
       282 天前
    @ruanimal #6 是可以的,比如在 k8s 环境中部署时,就没必要用 gunicorn ,直接用 uvicorn + k8s 自身的管理方式就行
    0x0208v0
        9
    0x0208v0  
       281 天前
    说白了就是功能多。。。那就套娃呗
    MRlaopeng
        10
    MRlaopeng  
    OP
       281 天前
    @v2exblog 套娃岂不是有性能损失
    ruanimal
        11
    ruanimal  
       281 天前
    @MRlaopeng 这个思想就很不对了, 连怎么实现都没有了解,如何妄谈性能损失。
    MRlaopeng
        12
    MRlaopeng  
    OP
       281 天前
    @ruanimal 有道理
    panxi
        13
    panxi  
       281 天前   ❤️ 1
    你提到的这个问题非常有意义。Uvicorn 确实可以单独作为 ASGI 服务器运行,而 Gunicorn 通常用于运行 WSGI 应用程序。但是,当你将它们结合在一起使用时,会有一些特定的好处:

    1. **稳定性**:Gunicorn 作为一个长期存在且经过良好测试的项目,它的稳定性和健壮性是有保障的。通过将 Gunicorn 与 Uvicorn 结合使用,可以利用 Gunicorn 的管理能力和稳定性,以及 Uvicorn 的异步性能。

    2. **进程管理**:Gunicorn 提供了一些强大的进程管理功能,例如工作进程的启动、停止和重启。当系统负载增加时,它可以更好地管理资源,而 Uvicorn 单独运行时可能没有这些特性。

    3. **部署的简化**:对于那些已经习惯使用 Gunicorn 来部署 WSGI 应用程序的组织来说,将 Gunicorn 与 Uvicorn 结合使用可以简化迁移到 ASGI 的过程。团队可以利用现有的 Gunicorn 部署、监控和日志记录基础设施。

    4. **配置灵活性**:Gunicorn 提供了许多配置选项和插件,可以方便地自定义应用程序的行为。与 Uvicorn 结合使用时,你可以利用这些灵活性,并允许在同一台机器上同时运行 WSGI 和 ASGI 应用程序。

    5. **负载均衡**:Gunicorn 能够在多个工作进程之间进行负载均衡。这不仅能够更好地利用多核 CPU ,还可以增加系统的可扩展性和冗余性。

    总而言之,尽管 Uvicorn 单独使用具有优势,但将 Gunicorn 与 Uvicorn 结合使用可以提供额外的稳定性、灵活性和管理功能。这种组合在具有大量流量和需要高可用性的生产环境中可能尤为有用。


    by GPT
    julyclyde
        14
    julyclyde  
       280 天前
    @MRlaopeng 但是你等几个月可能发现那个低级的也进化出这个功能了
    MRlaopeng
        15
    MRlaopeng  
    OP
       280 天前
    @julyclyde 啥意思,,uvicorn 具备 Gunicorn 的功能了吗
    julyclyde
        16
    julyclyde  
       280 天前
    @MRlaopeng 我没具体去了解
    但是即使现在没有,将来大概也会有
    谁都不会放弃“包别人”的想法
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1034 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 77ms · UTC 21:57 · PVG 05:57 · LAX 14:57 · JFK 17:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.