Web-frameworks: Running ASGI on uvicorn without gunicorn ?

Created on 28 Jul 2019  Â·  6Comments  Â·  Source: the-benchmarker/web-frameworks

Hi @encode,

In this repository, all ASGI based frameworks are running with uvicorn (but throught gunicorn), like tfb does.

For example, with starlette, I have the following results on

OS: Linux (version: 5.1.19-300.fc30.x86_64, arch: x86_64)
CPU Cores: 4
threads: 5, connections: 1000

| | Average | 50th percentile | 90th percentile | 99th percentile | 99.9th percentile | Standard deviation |
|--------------------------------|----------------:|----------------:|----------------:|----------------:|----------------:|----------------:|
| uvicorn | 24.74 ms | 19.33 ms | 45.26 ms | 59.51 ms | 151.46 ms | 12390.67 |
| uvicorn (asyncio / httptools) | 41.27 ms | 34.55 ms | 71.75 ms | 97.56 ms | 518.38 ms | 31331.00 |
| uvicorn (asyncio / h11) | 108.97 ms | 104.79 ms | 165.86 ms | 224.94 ms | 423.49 ms | 42378.00 |
| uvicorn (uvloop / httptools) | 27.22 ms | 24.44 ms | 38.29 ms | 77.58 ms | 717.78 ms | 26329.33 |
| uvicorn (uvloop / h11) | 84.99 ms | 83.65 ms | 111.71 ms | 180.97 ms | 385.15 ms | 28448.33 |
| gunicorn (reuse port) | 24.10 ms | 23.11 ms | 37.83 ms | 55.63 ms | 254.28 ms | 11240.33 |
| gunicorn | 25.34 ms | 22.95 ms | 37.50 ms | 59.64 ms | 217.41 ms | 10781.67 |

It could be useful to run all ASGI on uvicorn without gunicorn, because :

  • it avoid another dependency
  • it avoid a (perhaps) bottleneck
  • it show more performances

What do you think ?

/cc @ahopkins @florimondmanca @tiangolo @pgjones @taoufik07

python

Most helpful comment

It would be nice to include Hypercorn as well (I think variants would be required first). I tend to use uvicorn directly (when used in production).

All 6 comments

Hey @waghanza,

I think running behind Gunicorn and the Uvicorn worker is fine, because I would guess that's how most people run their ASGI apps in production (since this gives you multiple worker processes and a familiar workflow if you're already working with Gunicorn for other projects). Besides, this is what the Uvicorn docs recommend:

As a general rule, you'll probably want to [...] run gunicorn -k uvicorn.workers.UvicornWorker for production.

Based on this assumption, although running this benchmark behind Uvicorn might showcase better performance (although I'd say it's not that obvious from the latency table above), it wouldn't reflect most real-world setups. But then it depends what the priorities for this benchmark are — absolute performance or real-world performance. :-)

You have the point @florimondmanca.

The main goal is real-word performance (I'll introduce variants later this or next year to show absolute performances). I do not use (or used) ASGI in a real-word context, so my opinion will not be factual

Anyone running an ASGI framework in a real-word case can mark his opinion here, and I'll take the decision as the majority :heart:

It would be nice to include Hypercorn as well (I think variants would be required first). I tend to use uvicorn directly (when used in production).

@RobertoPrevato how do you run blacksheep on production ? Directly using uvicorn ? Or using gunicorn on top of uvicorn ?

Hi @waghanza, since now blacksheep adheres to ASGI and drops its previous implementation of HTTP Server, it is now a pure web framework in its server namespace (side note: it still contains a nice implementation of HTTP Client for asyncio). How it is run on production, depends upon the third-party implementation of HTTP Server that is associated to it.

It can be used with uvicorn, daphne, or hypercorn ASGI servers*. If you use uvicorn, then the recommended way for production is to use gunicorn (ref.).

For production deployments we recommend using gunicorn with the uvicorn worker class.

*potentially, blacksheep can also be used with a non-ASGI http server, if desired, but it's easier to use existing ASGI servers.

@waghanza I agree, and sorry that I have been lagging lately in making this PR. I am trying to clear my plate a little, and if someone else does not get to it first, I will try and submit something.

As for whether to use gunicorn AND uvicorn/hypercorn, they probably should be different tests as they would produce different results. I personally do not run with gunicorn in production.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sakthisaran65 picture sakthisaran65  Â·  5Comments

waghanza picture waghanza  Â·  6Comments

florimondmanca picture florimondmanca  Â·  4Comments

drujensen picture drujensen  Â·  8Comments

waghanza picture waghanza  Â·  5Comments