-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asyncio uses too many threads by default #79460
Comments
By default, asyncio spawns as many as os.cpu_count() * 5 threads to run I/O on. When combined with beefy machines (e.g. kubernetes servers) with, says, 56 cores, it results in very high memory usage. This is amplified by the fact that the Workaround: loop.set_default_executor(concurrent.futures.ThreadPoolExecutor(max_workers=8)) This is still not ideal as the program might not need max_workers threads, but they are still spawned anyway. I've hit this issue when running asyncio program in kubernetes. It created 260 idle threads and then ran out of memory. I think the default max_workers should be limited to some max value and ThreadPoolExecutor should not spawn new threads unless necessary. |
What about making it dependant on memory as well as logical processor count:
|
node.js default threadpool size is 4 regardless number of cores. Since we has GIL, I think fixed-size pool is better idea. |
asyncio uses bare concurrent.futures.ThreadPoolExecutor. |
Current default value is decided in here: It seems there were no strong reason for current cpu_count * 5.
Note that this is fixed by bpo-24882. |
I'm ok with changing the default threads number limit. I insist on changing the default calculation schema in concurrent.futures, not in asyncio. There is no case for asyncio to be exceptional. |
I proposed cpu_count + 4 because bpo-24882 almost fixed the problem of large maxworks.
Makes sense. |
I think it produces reasonable good numbers for any CPU count. Do you have time for preparing a pull request? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: