Performance: Sending and receiving messages
MEDIUM IMPACT
This affects how quickly messages are sent and received over the network, impacting server response time and user interaction speed.
from fastapi import FastAPI import asyncio app = FastAPI() @app.post('/send') async def send_message(message: str): # Simulate async processing await asyncio.sleep(0.1) return {'status': 'sent'}
from fastapi import FastAPI app = FastAPI() @app.post('/send') def send_message(message: str): # Simulate heavy processing import time time.sleep(5) return {'status': 'sent'}
| Pattern | Server Blocking | Concurrency | Response Time | Verdict |
|---|---|---|---|---|
| Synchronous blocking with time.sleep | High (blocks worker) | Low (serial requests) | Slow (delays response) | [X] Bad |
| Asynchronous with await asyncio.sleep | Low (non-blocking) | High (handles many requests) | Fast (quick response) | [OK] Good |