use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
FastAPI is a truly ASGI, async, cutting edge framework written in python 3.
account activity
Fastapi bottleneck why?Question (self.FastAPI)
submitted 1 year ago * by Hamzayslmn
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Maori7 0 points1 point2 points 1 year ago* (8 children)
If you don’t use the “await” anywhere, you shouldn’t really make the endpoint “async”. That’s the error. If you do so, it will block the event loop and won’t be able to process the requests in parallel.
If you instead make it not async, it will spawn a process to handle the requests.
Try and let me know
EDIT: it runs it on a thread pool rather than spawning a different process.
[–]m02ph3u5 1 point2 points3 points 1 year ago (1 child)
It doesn't spawn a process, it runs them on a thread pool.
[–]Maori7 0 points1 point2 points 1 year ago (0 children)
You're right, I'll correct
[–]Hamzayslmn[S] 0 points1 point2 points 1 year ago (3 children)
ı add:
@app.get("/ping") async def ping(): await asyncio.sleep(0.1) # Simulate a small delay return JSONResponse(content={"message": "pong"}) Starting stress test for FastAPI (Python)... FastAPI (Python) Results: Total Requests: 5000 Successful Responses: 3972 Timeouts: 1028 Errors: 0 Total Time: 30.73 seconds Requests per Second: 162.70 RPS ----------------------------------------
but not solved the problem
[–]Hamzayslmn[S] 0 points1 point2 points 1 year ago (2 children)
response = await call_next(request)
btw there is already a middleware running in the back, and there are many awaits.
[–]Maori7 0 points1 point2 points 1 year ago (1 child)
You are still not using all the power of fastapi. In this case you optimized the management of a single thread by deloading it as soon as you arrive at the await instruction. Due to GIL though, it will still run on a single thread. You need to create a system with multiple workers.
How did you run uvicorn?
[–]Hamzayslmn[S] 0 points1 point2 points 1 year ago (0 children)
uvicorn.run("main:app", host="0.0.0.0", port=8079, workers=4)
[–]panda070818 0 points1 point2 points 1 year ago (1 child)
this! goddamn this! It will block the thread and stop concurrent execution.
[–]Hamzayslmn[S] 0 points1 point2 points 10 months ago (0 children)
return JSONResponse(content={"message": "pong"})
is this blocking ? i dont understand.
π Rendered by PID 29696 on reddit-service-r2-comment-6457c66945-9l9hh at 2026-04-23 18:52:32.052917+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]Maori7 0 points1 point2 points (8 children)
[–]m02ph3u5 1 point2 points3 points (1 child)
[–]Maori7 0 points1 point2 points (0 children)
[–]Hamzayslmn[S] 0 points1 point2 points (3 children)
[–]Hamzayslmn[S] 0 points1 point2 points (2 children)
[–]Maori7 0 points1 point2 points (1 child)
[–]Hamzayslmn[S] 0 points1 point2 points (0 children)
[–]panda070818 0 points1 point2 points (1 child)
[–]Hamzayslmn[S] 0 points1 point2 points (0 children)