首页 > 其他分享 >Gunicorn + Flask Curl命令返回状态Connection: close转keep-alive的方法

Gunicorn + Flask Curl命令返回状态Connection: close转keep-alive的方法

时间:2023-02-22 14:35:45浏览次数:34  
标签:Gunicorn Flask alive Keep Connection Alive close 连接

问题介绍:
在实际的业务中,会存在 CURL命令请求后返回值的header中的"Connection: close"的情况,这种情况下会导致每次请求都要重新建立连接。

HTTP协议采用“请求-应答”模式,当使用普通模式,即非KeepAlive模式时,每个请求/应答客户和服务器都要新建一个连接,完成之后立即断开连接(HTTP协议为无连接的协议);当使用Keep-Alive模式(又称持久连接、连接重用)时,Keep-Alive功能使客户端到服务器端的连接持续有效,当出现对服务器的后继请求时,Keep-Alive功能避免了建立或者重新建立连接。

解决办法:
在使用Gunicorn命令的时候加入--worker-class gevent即可,如下所示:

gunicorn -t 1000 -w 2 -b 0.0.0.0:9000 --worker-class gevent --limit-request-line 8190 manage:app

标签:Gunicorn,Flask,alive,Keep,Connection,Alive,close,连接
From: https://www.cnblogs.com/ache/p/17144220.html

相关文章