-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rt: use task::Inject with current_thread scheduler (#5702)
Previously, the current_thread scheduler used its own injection queue instead of sharing the same one as the multi-threaded scheduler. This patch updates the current_thread scheduler to use the same injection queue as the multi-threaded one (`task::Inject`). `task::Inject` includes an optimization where it does not need to acquire the mutex if the queue is empty.
- Loading branch information
1 parent
ddd7250
commit 93bde08
Showing
8 changed files
with
246 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
//! Benchmark implementation details of the threaded scheduler. These benches are | ||
//! intended to be used as a form of regression testing and not as a general | ||
//! purpose benchmark demonstrating real-world performance. | ||
use tokio::runtime::{self, Runtime}; | ||
|
||
use bencher::{benchmark_group, benchmark_main, Bencher}; | ||
|
||
const NUM_SPAWN: usize = 1_000; | ||
|
||
fn spawn_many_local(b: &mut Bencher) { | ||
let rt = rt(); | ||
let mut handles = Vec::with_capacity(NUM_SPAWN); | ||
|
||
b.iter(|| { | ||
rt.block_on(async { | ||
for _ in 0..NUM_SPAWN { | ||
handles.push(tokio::spawn(async move {})); | ||
} | ||
|
||
for handle in handles.drain(..) { | ||
handle.await.unwrap(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
fn spawn_many_remote_idle(b: &mut Bencher) { | ||
let rt = rt(); | ||
let rt_handle = rt.handle(); | ||
let mut handles = Vec::with_capacity(NUM_SPAWN); | ||
|
||
b.iter(|| { | ||
for _ in 0..NUM_SPAWN { | ||
handles.push(rt_handle.spawn(async {})); | ||
} | ||
|
||
rt.block_on(async { | ||
for handle in handles.drain(..) { | ||
handle.await.unwrap(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
fn spawn_many_remote_busy(b: &mut Bencher) { | ||
let rt = rt(); | ||
let rt_handle = rt.handle(); | ||
let mut handles = Vec::with_capacity(NUM_SPAWN); | ||
|
||
rt.spawn(async { | ||
fn iter() { | ||
tokio::spawn(async { iter() }); | ||
} | ||
|
||
iter() | ||
}); | ||
|
||
b.iter(|| { | ||
for _ in 0..NUM_SPAWN { | ||
handles.push(rt_handle.spawn(async {})); | ||
} | ||
|
||
rt.block_on(async { | ||
for handle in handles.drain(..) { | ||
handle.await.unwrap(); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
fn rt() -> Runtime { | ||
runtime::Builder::new_current_thread().build().unwrap() | ||
} | ||
|
||
benchmark_group!( | ||
scheduler, | ||
spawn_many_local, | ||
spawn_many_remote_idle, | ||
spawn_many_remote_busy | ||
); | ||
|
||
benchmark_main!(scheduler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.