Replies: 6 comments 1 reply
-
FastApi docs talk about ThreadPoolExecutor being used under the hood, but i didn't find that in the implementation. Instead, i found anyio, and in order to change the thread limit anyio uses, i have to replace an internal value called
|
Beta Was this translation helpful? Give feedback.
-
fastAPI is based on starlette that use to control the ThreadPoolExecutor , but starlette is now using anyio , so I don't see a better way than your proposition : RunVar("_default_thread_limiter").set(CapacityLimiter(2)) |
Beta Was this translation helpful? Give feedback.
-
We can also set the variable directly, AnyIO's docs |
Beta Was this translation helpful? Give feedback.
-
Hi I am facing a weird issue that when I run pod on Kubernetes I can't spawn more than 14 threads even if I set the limit to 200. The other usages like cpu and men are well beyond the limits. Any idea where the issue is ? |
Beta Was this translation helpful? Give feedback.
-
I came here, cause I was looking for a way to limit the amount of simultaneously processed requests and in the end it seems there's a way outside of FastAPI: use |
Beta Was this translation helpful? Give feedback.
-
姚宏锋已收到您的来信,谢谢。
|
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
I want to limit the ammount of threads spawned by the framework when using sync endpoints. On my PC i have 4 cores, and when i try the following code i get up to 40-41 threads spawned. Tried to limit the workers with the answers found here https://github.com/tiangolo/fastapi/issues/603 but had no luck, it always spawns up to 41.
I'm using the latest version of fastapi, uvicorn, etc.
uvicorn app_file:app
How can i apply a limit like 4 concurrent threads?
Operating System
Linux
Operating System Details
Ubuntu 20.0.4
FastAPI Version
0.70.0
Python Version
3.8.10
Additional Context
Tried the same on Windows, but no limit is applied there, like if an infinite ammount is allowed.
Beta Was this translation helpful? Give feedback.
All reactions