-
Help Needed: Abnormal Performance - Granian 6x Slower Than Uvicorn in FastAPI BenchmarkI'm running The results are completely abnormal and counterintuitive:
Granian is supposed to be a high-performance Rust-based ASGI server, but in my test, it is 6x slower than Uvicorn. I need help identifying what is wrong with my setup, commands, or environment. Test Environment
dependencies = [
"fastapi[standard]>=0.135.2",
"granian>=2.7.2",
"httptools>=0.7.1",
"uvicorn>=0.42.0",
]Application Code (test_fastapi.py)-Minimal test app with no extra logic: # -*- coding: utf-8 -*-
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Health(BaseModel):
status: str
@app.get(
"/health",
response_model=Health,
)
def read_root():
return Health(
status="ok"
)Startup Commands-Uvicorn (High Performance) uv run uvicorn test_fastapi:app --host 127.0.0.1 --port 8080 --workers 2 --log-level critical --loop uvloop --http httptools-Granian (Very Slow) uv run granian test_fastapi:app --host 127.0.0.1 --port 8080 --workers 2 --loop uvloop --interface asgi-Benchmark Command (wrk) wrk -t4 -c100 -d10s -H "Content-Type: application/json" http://localhost:8080/healthActual ResultsFastAPI + Uvicorn: Requests/sec: 7537 Questions & Help Needed
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Switch your FastAPI does a bunch of stuff with threadpool executors to serve sync methods. That plays poorly with Granian. FYI the same plays with uvicorn, if you switch to |
Beta Was this translation helpful? Give feedback.
Switch your
read_rootfunction to beasync.FastAPI does a bunch of stuff with threadpool executors to serve sync methods. That plays poorly with Granian. FYI the same plays with uvicorn, if you switch to
asyncmethods RPS increase on uvicorn as well.