How does flask's built-in web server open many processes or threads?

is currently working on a multi-computer manager. The web server made with flask performs tasks for administrative requests and returns the results to the front-end page (can wait).

for ease of processing, web servers such as nginx are not used.
for convenience, the same administrative command sends a command from the front end to the back end for each host. (when it comes to the display of processing results, you don"t want to use other modes.)
backend processing means that ssh logs in to other hosts to execute commands (it takes a long time, but does not consume the resources of the host where flask resides)

now I"m going to issue commands to about 50 machines. Now, every time I issue a command, flask will only open 6 processes or threads to process 6 requests, and wait a few dozen minutes to process the rest of the request.
whether you are using the default multithreaded mode or changing to multiprocess mode, specifying a number of processes of 32, 64, or more, only six processes are processing six requests, and the subsequent requests will not be processed until the processing is complete (it will take a long time).

I hope that after the front end sends 50 requests to the backend, the backend can open 50 processes or threads to process. In this way, we don"t have to wait so long, but I don"t know how to deal with it.

traces back to the flask internal process setting value processors is assigned to an object"s max_children property, which is not found to be used in the code.


answer
to find the source, not flask. The werkzeug,werkzeug used by flask to handle connections uses socketserver.
socketserver processes up to 5 requests at the same time by default, but werkzeug has changed the value to 128.
processes only 6 requests at a time because chrome browsers limit a maximum of 6 requests at a time, and many requests can only be sent out at a time, and the rest will wait.
waiting occurs on the browser side, not on the server side. The


run method has the threaded parameter. Just set it to True.


it is recommended to go to NGINX + WSGI. The server that comes with Flask is only suitable for development and debugging

.
Menu