How many simultaneous requests does one process in the bulb receive?

I am building an application using Flask, but I know very little about WSGI and its HTTP database, Werkzeug. When I start serving a Flask application with gunicorn and 4 workflows, does this mean that I can handle 4 simultaneous requests?

I mean parallel queries, not queries per second or something else.

+95
python flask wsgi gunicorn
Jun 07 '12 at 19:12
source share
4 answers

When you start the development server, you run app.run() , you get one synchronous process, which means no more than 1 processed requests at a time.

By holding Gunicorn in front of its default setting and simply increasing the number of --workers , you get essentially a series of processes (managed by Gunicorn) that each behave as an app.run() development server. 4 workers == 4 simultaneous requests. This is because Gunicorn uses the included sync working class by default.

It is important to note that Gunicorn also includes asynchronous workers, namely eventlet and gevent (as well as tornado , but it is best used with the Tornado infrastructure). By specifying one of these asynchronous workers with the --worker-class flag, you get Gunicorn controlling several asynchronous processes, each of which controls its own concurrency. These processes do not use threads, and coroutines instead. Basically, in each process only one thing can happen at a time (1 thread), but objects can be β€œsuspended” when they wait for the completion of external processes (think about database queries or waiting for network I / O).

This means that if you use one of the Gunicorn asynchronous workers, each worker can process more than one request at a time. Just how many workers best depends on the nature of your application, its environment, the equipment on which it runs, etc. More information can be found on the Gunicorn page design and notes on how gevent works on its login page.

+136
Dec 18
source share

The flask will process one request per thread at a time. If you have 2 processes with 4 threads each, these are 8 simultaneous requests.

The bulb does not create or control flows or processes. Responsibility of the WSGI gateway (e.g. guns).

+25
Jun 08 2018-12-12T00:
source share

Currently, there is a much simpler solution than the one already provided. When starting the application, you just need to pass the app.run() threaded=True parameter to the app.run() call, for example:

 app.run(host="your.host", port=4321, threaded=True) 

Another option, according to what we see in the werkzeug docs , is to use the procesess parameter, which gets a number> 1 indicating the maximum number of simultaneous processes to process:

  • threaded - should the process process each request in a separate thread?
  • processes - if more than 1, then process each request in a new process to this maximum number of simultaneous processes.

Something like:

 app.run(host="your.host", port=4321, processes=3) #up to 3 processes 

More information on the run() method here and on the blog that led me to find a solution and API links.

+15
Jun 06 '18 at 1:05
source share

No - you can definitely handle this.

It is important to remember that at heart, assuming that you are using a single-core machine, the processor really only works on one command * at a time.

Namely, the processor can execute only a very limited set of instructions and cannot execute more than one instruction per cycle (many instructions even take more than 1 tick).

Therefore, most of the concurrency that we talk about in computer science is concurrency software. In other words, there are layers of software implementation that abstract the lower level processor from us and make us think that we are running the code at the same time.

These β€œthings” can be processes that are units of code that run simultaneously in the sense that each process thinks that it works in its own world with its own, non-shared memory.

Another example is threads, which are units of code within processes that also allow concurrency.

The reason your 4 workflows will be able to process more than 4 requests is because they will start threads to handle more and more requests.

The actual request limit depends on the selected HTTP server, I / O, OS, hardware, network connection, etc.

Good luck

* Instructions are the most basic instructions that a processor can execute. examples - adding two numbers, switching from one instruction to another

+7
Jun 08 2018-12-12T00:
source share



All Articles