R
R
Rodion2021-04-01 14:20:33
Python
Rodion, 2021-04-01 14:20:33

Why is Uvicorn advised to run through gunicorn?

Hey!

Does anyone know why the Uvicorn documentation advises running an ASGI application through gunicorn using uvicorn workers? Is this purely due to process management or is uvicorn not considered reliable for live environments...? And if the application is launched inside a docker container (by means of docker-compose) - do you need process management from gunicorn at all if docker-compose does this? Maybe in this case it's worth running uvicorn directly? Thank you!


Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Kitaev, 2021-04-01
@rodion4dev

Because uvicorn is not a process manager. It launches exactly one process, in which there will be one event loop, which will spin everything on one core. If you have a 4-core CPU on the server, then you need to run at least 4 such uvicorns to fully utilize the resources. That's what gunicorn is for.

R
RastyazhenkoAV, 2021-09-12
@RastyazhenkoAV

Uvicorn runs in multiple threads ( config.workers )

server = Server(Config)
if server.config.workers > 1:
  app = Multiprocess(server.config, target=server.run, sockets=[server.config.bind_socket()]).run
else:
  app = server.run

app()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question