-
Notifications
You must be signed in to change notification settings - Fork 341
Open
Labels
api designOpen design questionsOpen design questions
Description
I was wondering if there is any ability, or plans, to support setting the maximum number of threads for the global executor?
I see the num_cpus
is used here which is great 99% of the time, my use case, however, is for docker.
num_cpus
can/will show more CPU's than is allocated for the container to use. I was hoping to be able to directly control this for situations like this.
Thanks you in advance for any information you can provide :)
Metadata
Metadata
Assignees
Labels
api designOpen design questionsOpen design questions
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
yoshuawuyts commentedon Dec 12, 2019
Hey there! Thanks for asking. We definitely want to provide such controls, but it's a question of how we should go about this. One option that's been mentioned is passing it as a global variable. But we haven't really talked about this much, primarily also because setting max threads can be risky (deadlocks!), and setting boundaries in terms of cpu cycles and memory usage tends to be a better option in practice.
deankarn commentedon Dec 12, 2019
@yoshuawuyts I completely agree that in practice most of the time this is a sane default, I just hope that the option to tweak at this low level is not abstracted away so far that it is not tunable and glad it's being thought about 😃
ozgrakkurt commentedon Mar 22, 2023
Hey @deankarn,
this issue seems to be solved.
Tracking how async-std handles thread count limits:
async-std/src/rt/mod.rs
Line 12 in bf316b0
So it seems to use this by default.
And it seems to be controllable by ASYNC_STD_THREAD_COUNT env var.
Apparently this doesnt cover spawn_blocking calls. Those seem like they can be controlled by BLOCKING_MAX_THREADS env var. I found it from async-rs/async-global-executor#4.