Running the server across multiple workers
In high-traffic environments, running a FastAPI application with a single worker may not be sufficient to handle all incoming requests efficiently. To improve performance and ensure better resource use, you can run your FastAPI instance across multiple workers. This can be achieved using tools such as Gunicorn.
In this recipe, we will explore how to run a FastAPI application with multiple workers using Gunicorn in a Docker container, and we will also discuss Uvicorn’s ability to handle multiple workers along with its limitations.
Getting ready
The gunicorn
package is not Windows compatible. To ensure operating system operability, we will run our Live Application
in a Docker container.
The recipe will be based on the project created in the previous recipe, Running FastAPI applications in Docker containers.
How to do it…
FastAPI with multiple workers runs multiple copies of the app on different CPU processes.
...