Home

Awesome

Async Python Web Frameworks comparison

https://klen.github.io/py-frameworks-bench/

Updated: 2021-12-27

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

<img src='https://quickchart.io/chart?width=800&height=400&c=%7Btype%3A%22bar%22%2Cdata%3A%7Blabels%3A%5B%22blacksheep%22%2C%22muffin%22%2C%22falcon%22%2C%22starlette%22%2C%22baize%22%2C%22emmett%22%2C%22fastapi%22%2C%22aiohttp%22%2C%22tornado%22%2C%22quart%22%2C%22sanic%22%2C%22django%22%5D%2Cdatasets%3A%5B%7Blabel%3A%22num%20of%20req%22%2Cdata%3A%5B472935%2C420570%2C395925%2C323595%2C321450%2C299400%2C245640%2C184965%2C110085%2C98550%2C61860%2C34710%5D%7D%5D%7D%7D' />

The Methodic

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

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 (2021-12-27)

<h3 id="html"> Accept a request and return HTML response with a custom dynamic header</h3> <details open> <summary> The test simulates just a single HTML response. </summary>

Sorted by max req/s

FrameworkRequests/secLatency 50% (ms)Latency 75% (ms)Latency Avg (ms)
blacksheep 1.2.2170853.074.893.71
muffin 0.86.3148013.565.584.30
falcon 3.0.1141333.636.014.49
baize 0.14.1131543.986.374.83
starlette 0.17.1122334.326.845.19
emmett 2.3.2122004.206.935.21
fastapi 0.70.188345.789.647.21
aiohttp 3.8.164199.749.979.97
quart 0.16.2307321.3422.3020.82
tornado 6.1296921.5921.8621.56
sanic 21.12.0151131.8859.8742.29
django 4.090065.5779.0171.02
</details> <h3 id="api"> Parse path params, query string, JSON body and return a json response</h3> <details open> <summary> The test simulates a simple JSON REST API endpoint. </summary>

Sorted by max req/s

FrameworkRequests/secLatency 50% (ms)Latency 75% (ms)Latency Avg (ms)
blacksheep 1.2.293935.379.136.78
muffin 0.86.393235.479.166.83
falcon 3.0.191015.549.536.99
starlette 0.17.171987.0611.918.86
emmett 2.3.264907.6813.069.93
baize 0.14.1587411.0811.4410.87
fastapi 0.70.156328.8115.6111.33
aiohttp 3.8.1398615.8416.0816.08
tornado 6.1245726.0126.3426.05
quart 0.16.2192532.9633.7733.22
sanic 21.12.0142734.5563.8044.79
django 4.080074.3288.0179.89
</details> <h3 id="upload"> Parse uploaded file, store it on disk and return a text response</h3> <details open> <summary> The test simulates multipart formdata processing and work with files. </summary>

Sorted by max req/s

FrameworkRequests/secLatency 50% (ms)Latency 75% (ms)Latency Avg (ms)
blacksheep 1.2.250519.9817.1912.64
muffin 0.86.3391413.2421.8316.36
falcon 3.0.1316116.6526.8720.30
baize 0.14.1240226.0229.4326.64
starlette 0.17.1214234.1338.9229.82
aiohttp 3.8.1192632.9433.2133.22
tornado 6.1191333.4933.8233.44
fastapi 0.70.1191038.2843.1633.44
quart 0.16.2157240.8441.9940.67
emmett 2.3.2127047.2655.9150.31
sanic 21.12.0118642.2775.8353.86
django 4.061497.99104.67104.02
</details> <h3 id="composite"> Composite stats </h3> <details open> <summary> Combined benchmarks results</summary>

Sorted by completed requests

FrameworkRequests completedAvg Latency 50% (ms)Avg Latency 75% (ms)Avg Latency (ms)
blacksheep 1.2.24729356.1410.47.71
muffin 0.86.34205707.4212.199.16
falcon 3.0.13959258.6114.1410.59
starlette 0.17.132359515.1719.2214.62
baize 0.14.132145013.6915.7514.11
emmett 2.3.229940019.7125.321.82
fastapi 0.70.124564017.6222.817.33
aiohttp 3.8.118496519.5119.7519.76
tornado 6.111008527.0327.3427.02
quart 0.16.29855031.7132.6931.57
sanic 21.12.06186036.2366.546.98
django 4.03471079.2990.5684.98
</details>

Conclusion

Nothing here, just some measures for you.

License

Licensed under a MIT license (See LICENSE file)