I've a simple FastAPI server
@app.get("/")
async def root():
time.sleep(0.5) # any I/O bound task
return {"message": "home"}
I'm sending 10 concurrent requests to the server, which would take little over 0.5 seconds if it was a def
method instead of async def
:
# sending concurrent requests
with concurrent.futures.ThreadPoolExecutor() as executor:
results = executor.map(send_request, [...])
I understand that I should be using some asynchronous method to sleep on the server but why does my CONCURRENT code behave sequentially and taking 5+ seconds when I'm sending concurrent requests?
Technically there's some latency in every line so does it mean I need to make every line asynchronous?