Skip to content

Latest commit

 

History

History
171 lines (125 loc) · 8.59 KB

README.md

File metadata and controls

171 lines (125 loc) · 8.59 KB

Async Python Web Frameworks comparison

Updated: 2022-03-14

benchmarks tests


This is a simple benchmark for python async frameworks. Almost all of the frameworks are ASGI-compatible (aiohttp and tornado are exceptions on the moment).

The objective of the benchmark is not testing deployment (like uvicorn vs hypercorn and etc) or database (ORM, drivers) but instead test the frameworks itself. The benchmark checks request parsing (body, headers, formdata, queries), routing, responses.

Table of contents

The Methodic

The benchmark runs as a Github Action. According to the github documentation the hardware specification for the runs is:

  • 2-core vCPU (Intel® Xeon® Platinum 8272CL (Cascade Lake), Intel® Xeon® 8171M 2.1GHz (Skylake))
  • 7 GB of RAM memory
  • 14 GB of SSD disk space
  • OS Ubuntu 20.04

ASGI apps are running from docker using the gunicorn/uvicorn command:

gunicorn -k uvicorn.workers.UvicornWorker -b 0.0.0.0:8080 app:app

Applications' source code can be found here.

Results received with WRK utility using the params:

wrk -d15s -t4 -c64 [URL]

The benchmark has a three kind of tests:

  1. "Simple" test: accept a request and return HTML response with custom dynamic header. The test simulates just a single HTML response.

  2. "API" test: Check headers, parse path params, query string, JSON body and return a json response. The test simulates an JSON REST API.

  3. "Upload" test: accept an uploaded file and store it on disk. The test simulates multipart formdata processing and work with files.

The Results (2022-03-14)

Accept a request and return HTML response with a custom dynamic header

The test simulates just a single HTML response.

Sorted by max req/s

Framework Requests/sec Latency 50% (ms) Latency 75% (ms) Latency Avg (ms)
blacksheep 1.2.5 18546 2.80 4.53 3.41
muffin 0.87.0 16571 3.09 5.17 3.83
sanic 21.12.1 15558 4.70 5.14 4.08
falcon 3.0.1 15554 3.29 5.49 4.08
baize 0.15.0 13880 3.69 6.21 4.58
starlette 0.17.1 13797 3.70 6.16 4.60
emmett 2.4.5 13380 5.54 6.10 4.75
fastapi 0.75.0 9060 5.46 9.79 7.03
aiohttp 3.8.1 7240 8.74 9.01 8.84
quart 0.16.3 3425 18.99 20.08 18.68
tornado 6.1 3232 19.76 19.94 19.81
django 4.0.3 1002 59.00 66.26 63.72

Parse path params, query string, JSON body and return a json response

The test simulates a simple JSON REST API endpoint.

Sorted by max req/s

Framework Requests/sec Latency 50% (ms) Latency 75% (ms) Latency Avg (ms)
sanic 21.12.1 10777 6.97 7.67 5.90
blacksheep 1.2.5 10505 4.70 8.16 6.07
muffin 0.87.0 10319 4.79 8.41 6.17
falcon 3.0.1 10133 4.88 8.61 6.28
starlette 0.17.1 8135 6.03 10.76 7.83
emmett 2.4.5 7091 7.17 11.58 9.12
baize 0.15.0 6581 9.96 10.24 9.71
fastapi 0.75.0 5882 8.36 15.16 10.85
aiohttp 3.8.1 4496 14.15 14.32 14.24
tornado 6.1 2780 22.95 23.17 23.02
quart 0.16.3 2146 29.42 30.05 29.81
django 4.0.3 883 68.00 71.74 72.37

Parse uploaded file, store it on disk and return a text response

The test simulates multipart formdata processing and work with files.

Sorted by max req/s

Framework Requests/sec Latency 50% (ms) Latency 75% (ms) Latency Avg (ms)
blacksheep 1.2.5 5604 8.87 15.77 11.40
sanic 21.12.1 5025 10.44 16.83 12.72
muffin 0.87.0 4425 11.14 19.99 14.43
falcon 3.0.1 3433 14.56 25.48 18.73
baize 0.15.0 2834 21.89 24.48 22.57
starlette 0.17.1 2434 20.10 36.39 26.26
aiohttp 3.8.1 2218 28.81 29.09 28.84
fastapi 0.75.0 2099 23.61 41.91 30.44
tornado 6.1 2067 30.89 31.09 30.95
quart 0.16.3 1746 36.68 37.58 36.63
emmett 2.4.5 1414 41.83 50.86 45.21
django 4.0.3 689 86.45 89.44 92.51

Composite stats

Combined benchmarks results

Sorted by completed requests

Framework Requests completed Avg Latency 50% (ms) Avg Latency 75% (ms) Avg Latency (ms)
blacksheep 1.2.5 519825 5.46 9.49 6.96
sanic 21.12.1 470400 7.37 9.88 7.57
muffin 0.87.0 469725 6.34 11.19 8.14
falcon 3.0.1 436800 7.58 13.19 9.7
starlette 0.17.1 365490 9.94 17.77 12.9
baize 0.15.0 349425 11.85 13.64 12.29
emmett 2.4.5 328275 18.18 22.85 19.69
fastapi 0.75.0 255615 12.48 22.29 16.11
aiohttp 3.8.1 209310 17.23 17.47 17.31
tornado 6.1 121185 24.53 24.73 24.59
quart 0.16.3 109755 28.36 29.24 28.37
django 4.0.3 38610 71.15 75.81 76.2

Conclusion

Nothing here, just some measures for you.

License

Licensed under a MIT license (See LICENSE file)