Performance: Accepting connections
This affects how quickly the server can start handling incoming user requests, impacting initial response time and throughput.
import uvicorn if __name__ == "__main__": uvicorn.run("app:app", host="0.0.0.0", port=8000, workers=4, loop="uvloop")
import uvicorn if __name__ == "__main__": uvicorn.run("app:app", host="0.0.0.0", port=8000, workers=1, loop="asyncio")
| Pattern | Concurrent Connections | Request Queue | Response Start Delay | Verdict |
|---|---|---|---|---|
| Single worker, default loop | Low | High under load | High delay | [X] Bad |
| Multiple workers, uvloop | High | Low | Low delay | [OK] Good |
import uvicorn
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def read_root():
return {"message": "Hello World"}
uvicorn.run(app, host="127.0.0.1", port=9000)import uvicorn from fastapi import FastAPI app = FastAPI() uvicorn.run(app, host="localhost", port="8000")
Option A: uvicorn.run(app, host="0.0.0.0", port=8080) Option B: uvicorn.run(app, host="127.0.0.1", port=8080) Option C: uvicorn.run(app, host="localhost", port=80) Option D: uvicorn.run(app, host="192.168.1.100", port=8080)
Pass the test and this pattern moves unknown