Gunicorn gevent workers vs Uvicorn ASGI

Question:

I’m currently developing a service in Django which makes use of a slow external API (takes about 10s to get a response), which means the connections to my server are kept open waiting for the external API to respond, and occupying worker time/resources.

I know I can use gunicorn’s thread or gevent workers to add concurrency, but can’t seem to grasp the exact difference between using gunicorn with gevent workers and uvicorn (or any other server) with the asgi interface.

What would be the criteria for using one over the other?

Django still doesn’t fully support async/await views. Would it be better if I just stick with gevent workers?

Asked By: imricardoramos

||

Answers:

Gunicorn has a pre-fork worker model

A pre-fork worker model basically means a master creates forks which handle each request. A fork is a completely separate *nix process (Source).

Uvicorn is a ASGI server running uvloop

Python async needs a event loop for it to use it’s async features. And uvloop is an alternative to the asyncio loop. So if you’re having async calls in your code you could use uvloop internally or use uvicorn as your ASGI server. Note: You still have just a single event loop. You can choose to use gunicorn and uvicorn to have multiple workers and use uvloop.

In your django application it makes sense to use uvloop internally (if you choose to) and use gunicorn as your ASGI.

Answered By: clamentjohn