Middleware significantly degrades performance
Just tried robyn and in general I am impressed - it looks very promising, thank you!
However, after first quick test for framework overhead (empty response) I noticed serious degradation in performance after adding an empty middleware.
My test code is dead simple:
from robyn import Robyn, Request, Response
app = Robyn(__file__)
@app.before_request()
async def middleware_1(request: Request):
return request
@app.before_request()
async def middleware_2(request: Request):
return request
@app.get("/")
async def root(request: Request):
return Response(200, {}, "OK!\n")
app.start(port=8000, url="0.0.0.0", )I run it on Python 3.11.3 with robyn 0.36.0 (default config, single process), and test with httpit -d60s -c8 'http://10.200.0.210:8000/' (8 concurrent connections) and results are as follows:
| rps | latency | performance | |
|---|---|---|---|
| no middleware | ~23600 | 0.32 ms | 100% |
| middlware 1 | ~17500 | 0.46 ms | 74% (-26%) |
| middleware 1&2 | ~13700 | 0.58 ms | 58% (-42%) |
Both the server and the client are running on idling systems and network so other factors could be excluded, and results are consistent when tests are repeated.
What is interesting is that fastapi delivers similar results - rps are lower of course but empty middleware also introduces ~30% degradation, while blacksheep has almost no overhead.
Now the question is - what could be the possible reason for this degradation?
Source: sparckles/Robyn