Due the limitation of the GIL, threading is not good for CPU intensive tasks.
They should run in a different process (Multiprocessing).
There are some Modules, which are similar to Flask, but async.
Usually one Thread which handles the requests, is enough.
Most of the time, the WebServer is waiting for IO (sockets, Databases, etc.).
The question is, do you need to handle so many requests per second?
If you have blocking CPU intensive tasks, you should avoid executing them in your WebServer code.
In this case this tasks should be done by other Processes. There are different ways and libraries to handle it.
Multiprocessing together with message queues can handle your CPU intensive tasks.
The benefit is, that async code looks like synchronous code. But you have always to remind, never call blocking functions.
Calling blocking functions in async code, blocks your whole WebServer. Even
I could not remind the name of the other framework. It is also similar, but they are going a different way.
Then you can use also other Frameworks:
Django has also support for asyncio. They made a new standard called ASGI.
There are still mature frameworks like Tornado and Twisted which also supports async programming.
They should run in a different process (Multiprocessing).
There are some Modules, which are similar to Flask, but async.
Usually one Thread which handles the requests, is enough.
Most of the time, the WebServer is waiting for IO (sockets, Databases, etc.).
The question is, do you need to handle so many requests per second?
If you have blocking CPU intensive tasks, you should avoid executing them in your WebServer code.
In this case this tasks should be done by other Processes. There are different ways and libraries to handle it.
Multiprocessing together with message queues can handle your CPU intensive tasks.
The benefit is, that async code looks like synchronous code. But you have always to remind, never call blocking functions.
Calling blocking functions in async code, blocks your whole WebServer. Even
time.sleep(x)
have to be replaced by await asyncio.sleep(x)
I could not remind the name of the other framework. It is also similar, but they are going a different way.
Then you can use also other Frameworks:
Django has also support for asyncio. They made a new standard called ASGI.
There are still mature frameworks like Tornado and Twisted which also supports async programming.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!