简体   繁体   English

如何在Flask中设置最大未决连接数

[英]How to set maximum number of pending connections in Flask

How can I set a maximum number of pending connections in a Flask application? 如何在Flask应用程序中设置未决连接的最大数量?

Eg 例如

After I run this code, I can send it two requests at the same time. 运行此代码后,我可以同时发送两个请求。 While the first request is being processed, the other one will wait. 在处理第一个请求时,另一个将等待。 When the first one is done, the second one will be processed. 当第一个完成时,将处理第二个。

from flask import Flask
application = Flask(__name__)


@application.route("/")
def hello():
    for x in range(10000000):
        x += 1
    return "Hello World!"


if __name__ == '__main__':
    application.run()

How can I make it so that when I send two requests at the same time, the first one will be processed and the second one, instead of waiting, will not be able to connected (maybe it will get a some kind of error instead). 如何做到这一点,以便当我同时发送两个请求时,第一个请求将被处理,第二个请求将无法连接(而不是等待)(可能会收到某种错误) 。

You can use Flask with some sort of web server, such as Gunicorn, Nginx or Apache, to accept HTTP requests which it will then operate on. 您可以将Flask与某些类型的Web服务器一起使用,例如Gunicorn,Nginx或Apache,以接受HTTP请求,然后对其进行操作。 The reason why people run Nginx and Gunicorn together is that in addition to being a web server, Nginx can also proxy connections to Gunicorn which brings certain performance benefits. 人们一起运行Nginx和Gunicorn的原因是,除了作为Web服务器之外,Nginx还可以代理到Gunicorn的连接,这带来了一定的性能优势。

Gunicorn is pre-forking software. Gunicorn是预分叉软件。 For low latency communications, such as load balancer to app server or communications between services, pre-fork systems can be very successful. 对于低延迟通信,例如到应用程序服务器的负载平衡器或服务之间的通信,前叉系统可能会非常成功。 A gunicorn server can; Gunicorn服务器可以; Runs any WSGI Python web application (and framework) 运行任何WSGI Python Web应用程序(和框架)

Can be used as a drop-in replacement for Paster (Pyramid), Django's Development Server, web2py etc. 可以用作Paster(金字塔),Django开发服务器,web2py等的直接替代。

Comes with various worker types and configurations 带有各种工人类型和配置

Manages worker processes automatically 自动管理工作流程

HTTP/1.0 and HTTP/1.1 (Keep-Alive) support through synchronous and asynchronous workers 通过同步和异步工作程序支持HTTP / 1.0和HTTP / 1.1(保持活动)

You can take help from this blogpost , for setting up a flask application with gunicorn. 您可以从此博客文章获得帮助,以使用gunicorn设置flask应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM