1

Im developing Fast API application which is doing a lot of I/O operations per single request. The request are handled synchronously.

Whats the difference between serving the application using:

  • uvicorn uvicorn main:app --workers 4
  • gunicorn - gunicorn main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker

Whats better any why ? Many thanks :)

Jakub Zilinek
  • 219
  • 1
  • 2
  • 7
  • Does this answer your question? [What is the difference between Uvicorn and Gunicorn+Uvicorn?](https://stackoverflow.com/questions/66362199/what-is-the-difference-between-uvicorn-and-gunicornuvicorn) – MatsLindh Apr 29 '23 at 18:37

1 Answers1

1

The difference lies in the type of server you are using and how it interacts with the underlying application.

GUNICORN is a WSGI framework which, di per se, is not compatible with Fastapi, since Fastapi uses the ASGI standard (i.e. asynchronous). This means that Gunicorn will have to use some layer of abstraction (uvicorn.workers.UvicornWorker) in order to communicate with the asynchronous calls.

On the other hand, Uvicorn is an ASGI framework which has been developed with asynchronous in mind and can interact directly with the underlying Fastapi application.

That being said, you are spawning in both cases 4 workers that will run in parallel and independently, serving the requests that arrive to the server. The way they serve the requests and handle the underlying application, is server specific, as mentioned above.

Sources:

What is the difference between Uvicorn and Gunicorn+Uvicorn?

lsabi
  • 3,641
  • 1
  • 14
  • 26