-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Using ComputeTaskPool for a par_for_each query only uses half of available logical cores #1907
Copy link
Copy link
Open
Labels
A-AppBevy apps and pluginsBevy apps and pluginsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorC-PerformanceA change motivated by improving speed, memory usage or compile timesA change motivated by improving speed, memory usage or compile timesD-ComplexQuite challenging from either a design or technical perspective. Ask for help!Quite challenging from either a design or technical perspective. Ask for help!S-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!
Description
Bevy version
0.5
Operating system & version
Linux
What you did
I have a CPU heavy task and running it as part of a query par_for_each loop in a ComputeTaskPool and only half of my cores are being utilised. I originally used an AsyncTaskPool but this has even fewer threads assigned.
use bevy::tasks::ComputeTaskPool;
pub fn how_many_threads(pool: Res<ComputeTaskPool>, query: Query<(&DummyComponent)>) {
info!("TaskPool threads: {}", pool.thread_num());
info!("Available cores: {}", num_cpus::get());
query.par_for_each_mut(&pool, 1, |_dummy| {
// Will only run on
});
}TaskPool threads: 6
Available cores: 12
I know why this happens but it was unexpected:
| impl Default for DefaultTaskPoolOptions { |
What you expected to happen
When not using the IoTaskPool or AsyncComputeTaskPool I would expect the ComputeTaskPool to use all logical cores. Likewise I would expect the other pools to expand to optimally use the CPU available.
Alternatively, documentation should be updated to make clear what the current behaviour is and steps to create a new task pool.
What actually happened
Only half of the available core were used.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-AppBevy apps and pluginsBevy apps and pluginsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorC-PerformanceA change motivated by improving speed, memory usage or compile timesA change motivated by improving speed, memory usage or compile timesD-ComplexQuite challenging from either a design or technical perspective. Ask for help!Quite challenging from either a design or technical perspective. Ask for help!S-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!