服务器程序源代码分析之三:gunicorn

gunicorn是一个python web 服务部署工具,类似flup,完全用python开发,参考了ruby的部署工具: Unicorn project

gunicorn主要功能:

  • wsgi-http 协议的转换

    python有一个官方的module叫做WSGI(The Web Server Gateway Interface),版本号PEP333,定义了一些接口规范

    所以凡是python web框架都会遵守这个规范,django或者web.py都是这样

  • gunicorn对协议的支持很单一:输入wsgi,输出http

    flup也是输入wsgi,但支持多种输出:ajp,cgi,fcgi,scgi,就偏偏不支持http

    所以flup和gunicorn是前浪后浪的关系

  • IO模型采用pre-fork模式
  • 子进程里面,可以支持sync,eventlet,gevent,tornado 4种网络处理方法,默认用sync
  • gunicorn的代码质量比较差,起码比flup要差,缺乏python-style

    python-style:只要看看python自带的lib就了然,就是那种感觉

sync的实现
  1. 采用阻塞的accept等待新连接
  2. 一旦连接成功,就用select来驱动所有的client

select是遍历fd_set的方式,并且在linux有句柄数量必须小于1024的限制,这两点导致了sync模式的并发能力有限,flup也是这样,如果选择sync模式,那么和用 flup 没有什么区别

gunicorn还可以采用异步IO
  • 可以通过import代码包的方式,使用eventlet,gevent,tornado 之一
  • 这3种都是高性能异步IO(Fast event loop based on libev (epoll on Linux, kqueue on FreeBSD))
  • python 2.6就在select module里面加上了epoll/poll/kqueue/kevent 支持,把sync模块 改造为高性能异步IO其实非常容易

本文地址: http://lutaf.com/219.htm 鲁塔弗原创文章,欢迎转载,请附带原文链接

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用\[1\]和引用\[2\]的内容,当在安装了gunicorn后执行"gunicorn -h"命令时出现"-bash: gunicorn: command not found"错误,这可能是因为gunicorn的可执行文件路径没有正确添加到系统的环境变量中。为了解决这个问题,你可以尝试以下方法: 1. 确保你已经正确安装了gunicorn。可以使用命令"pip list"来查看已安装的包列表,确认gunicorn的版本号是否正确显示。 2. 检查系统的环境变量配置。可以使用命令"echo $PATH"来查看当前的环境变量路径。确保gunicorn的可执行文件所在的路径已经被正确添加到环境变量中。 3. 如果发现gunicorn的可执行文件路径没有被正确添加到环境变量中,你可以手动添加。可以编辑你的bash配置文件(例如~/.bashrc或~/.bash_profile),在其中添加一行类似于"export PATH=$PATH:/path/to/gunicorn"的代码,将"/path/to/gunicorn"替换为gunicorn的实际安装路径。然后保存文件并执行"source ~/.bashrc"或"source ~/.bash_profile"来使配置生效。 4. 重新启动终端窗口或会话,然后再次尝试执行"gunicorn -h"命令,看是否问题已经解决。 希望以上方法能够帮助你解决"gunicorn: 未找到命令"的问题。如果问题仍然存在,请提供更多的信息,以便我们能够更好地帮助你解决。 #### 引用[.reference_title] - *1* [服务器运行gunicorn服务抛错:-bash: gunicorn: command not found](https://blog.csdn.net/weixin_45380689/article/details/129013801)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [安装pip install gunicorn,执行gunicorn -h,显示-bash: gunicorn: command not found](https://blog.csdn.net/vcrookie2008/article/details/130999360)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [解决Linux下安装gunicorn提示-bash: gunicorn: command not found](https://blog.csdn.net/jiduochou963/article/details/88784947)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值