Skip to content
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

rt: Remove threaded_scheduler() and basic_scheduler() #2876

Merged
merged 43 commits into from Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f3b8d88
rt: Remove `threaded_scheduler()` and `basic_scheduler()`
LucioFranco Sep 23, 2020
692b418
Fix docs
LucioFranco Sep 25, 2020
1db81a9
Rewrite tokio-macros to new argument format
Darksonn Oct 3, 2020
1ecd3bc
Update tests
Darksonn Oct 3, 2020
ccd426d
Rename to current_thread/threaded and remove max_threads
Darksonn Oct 5, 2020
019945f
Use match in build
Darksonn Oct 6, 2020
8c2b54a
Fix tests
Darksonn Oct 7, 2020
a1ae97c
rustfmt
Darksonn Oct 7, 2020
430993d
clippy
Darksonn Oct 7, 2020
10a2735
Try to fix doctests
Darksonn Oct 7, 2020
0775bd4
test_fail as main -> test
Darksonn Oct 7, 2020
9c22b85
Add `new_multi_thread`/`new_current_thread`/`new_single_thread`
LucioFranco Oct 7, 2020
45c4977
Add runtime builders
LucioFranco Oct 7, 2020
2178252
remove shell runtime
LucioFranco Oct 7, 2020
97717ac
Remove shell runtime test
Darksonn Oct 7, 2020
0a8c401
more feature flag mess
LucioFranco Oct 9, 2020
1f747ca
Merge remote-tracking branch 'origin/master' into lucio/refactor-runt…
carllerche Oct 9, 2020
5c9e72d
fix feature flags
carllerche Oct 9, 2020
53f28e2
remove stray blocking cfgs
carllerche Oct 9, 2020
456af82
fix tests
carllerche Oct 9, 2020
fabd58e
fix feature combo
carllerche Oct 9, 2020
559cf99
fix windows
carllerche Oct 9, 2020
8b78067
fix build
carllerche Oct 10, 2020
b982350
fix docs
carllerche Oct 10, 2020
112cf71
fix docs hopefully
carllerche Oct 10, 2020
f9a22e6
fix loom build
carllerche Oct 10, 2020
3270ce5
fix tokio-util
carllerche Oct 10, 2020
3b1eb17
Merge remote-tracking branch 'origin/macro-new-builder' into lucio/re…
carllerche Oct 12, 2020
61421e7
fix macro doc examples
carllerche Oct 12, 2020
130beed
fix bad type
carllerche Oct 12, 2020
2c9acd1
Update tokio/src/io/driver/mod.rs
carllerche Oct 12, 2020
bc77b12
tests + rename num_workers
carllerche Oct 12, 2020
55ba939
Merge branch 'lucio/refactor-runtime-builder' of https://github.com/t…
carllerche Oct 12, 2020
9003409
tweak ff
carllerche Oct 12, 2020
f8bb6a0
fix a test
carllerche Oct 12, 2020
f10eedf
fix doc links
carllerche Oct 12, 2020
5c5f205
try to fix CI
carllerche Oct 12, 2020
fb155dd
tweak multi-threaded flavor
carllerche Oct 12, 2020
5a94b7e
fix doc test
carllerche Oct 12, 2020
22f5237
update error message
carllerche Oct 12, 2020
e3f2f86
Apply suggestions from code review
LucioFranco Oct 12, 2020
3ad8f3b
address comments
LucioFranco Oct 12, 2020
5829241
Merge branch 'master' of github.com:tokio-rs/tokio into lucio/refacto…
LucioFranco Oct 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions benches/mpsc.rs
Expand Up @@ -45,7 +45,6 @@ fn send_large(b: &mut Bencher) {
fn contention_bounded(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.core_threads(6)
.threaded_scheduler()
.build()
.unwrap();

Expand All @@ -72,7 +71,6 @@ fn contention_bounded(b: &mut Bencher) {
fn contention_bounded_full(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.core_threads(6)
.threaded_scheduler()
.build()
.unwrap();

Expand All @@ -99,7 +97,6 @@ fn contention_bounded_full(b: &mut Bencher) {
fn contention_unbounded(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.core_threads(6)
.threaded_scheduler()
.build()
.unwrap();

Expand All @@ -126,7 +123,6 @@ fn contention_unbounded(b: &mut Bencher) {
fn uncontented_bounded(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.core_threads(6)
.threaded_scheduler()
.build()
.unwrap();

Expand All @@ -148,7 +144,6 @@ fn uncontented_bounded(b: &mut Bencher) {
fn uncontented_unbounded(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.core_threads(6)
.threaded_scheduler()
.build()
.unwrap();

Expand Down
1 change: 0 additions & 1 deletion benches/scheduler.rs
Expand Up @@ -140,7 +140,6 @@ fn chained_spawn(b: &mut Bencher) {

fn rt() -> Runtime {
runtime::Builder::new()
.threaded_scheduler()
.core_threads(4)
.enable_all()
.build()
Expand Down
2 changes: 1 addition & 1 deletion benches/signal.rs
Expand Up @@ -47,7 +47,7 @@ fn many_signals(bench: &mut Bencher) {

let rt = runtime::Builder::new()
// Intentionally single threaded to measure delays in propagating wakes
.basic_scheduler()
.core_threads(0)
.enable_all()
.build()
.unwrap();
Expand Down
14 changes: 4 additions & 10 deletions benches/spawn.rs
Expand Up @@ -11,7 +11,7 @@ async fn work() -> usize {

fn basic_scheduler_local_spawn(bench: &mut Bencher) {
let runtime = tokio::runtime::Builder::new()
.basic_scheduler()
.core_threads(0)
.build()
.unwrap();
runtime.block_on(async {
Expand All @@ -23,10 +23,7 @@ fn basic_scheduler_local_spawn(bench: &mut Bencher) {
}

fn threaded_scheduler_local_spawn(bench: &mut Bencher) {
let runtime = tokio::runtime::Builder::new()
.threaded_scheduler()
.build()
.unwrap();
let runtime = tokio::runtime::Builder::new().build().unwrap();
runtime.block_on(async {
bench.iter(|| {
let h = tokio::spawn(work());
Expand All @@ -37,7 +34,7 @@ fn threaded_scheduler_local_spawn(bench: &mut Bencher) {

fn basic_scheduler_remote_spawn(bench: &mut Bencher) {
let runtime = tokio::runtime::Builder::new()
.basic_scheduler()
.core_threads(0)
.build()
.unwrap();

Expand All @@ -48,10 +45,7 @@ fn basic_scheduler_remote_spawn(bench: &mut Bencher) {
}

fn threaded_scheduler_remote_spawn(bench: &mut Bencher) {
let runtime = tokio::runtime::Builder::new()
.threaded_scheduler()
.build()
.unwrap();
let runtime = tokio::runtime::Builder::new().build().unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, this shouldn't work. A default builder should not enable the work-stealing scheduler. I would expect this to panic or enable the shell runtime.


bench.iter(|| {
let h = runtime.spawn(work());
Expand Down
7 changes: 2 additions & 5 deletions benches/sync_rwlock.rs
Expand Up @@ -5,7 +5,6 @@ use tokio::{sync::RwLock, task};
fn read_uncontended(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.core_threads(6)
.threaded_scheduler()
.build()
.unwrap();

Expand All @@ -24,7 +23,6 @@ fn read_uncontended(b: &mut Bencher) {
fn read_concurrent_uncontended_multi(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.core_threads(6)
.threaded_scheduler()
.build()
.unwrap();

Expand Down Expand Up @@ -52,7 +50,7 @@ fn read_concurrent_uncontended_multi(b: &mut Bencher) {

fn read_concurrent_uncontended(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.basic_scheduler()
.core_threads(0)
.build()
.unwrap();

Expand Down Expand Up @@ -80,7 +78,6 @@ fn read_concurrent_uncontended(b: &mut Bencher) {
fn read_concurrent_contended_multi(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.core_threads(6)
.threaded_scheduler()
.build()
.unwrap();

Expand Down Expand Up @@ -109,7 +106,7 @@ fn read_concurrent_contended_multi(b: &mut Bencher) {

fn read_concurrent_contended(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.basic_scheduler()
.core_threads(0)
.build()
.unwrap();

Expand Down
7 changes: 2 additions & 5 deletions benches/sync_semaphore.rs
Expand Up @@ -5,7 +5,6 @@ use tokio::{sync::Semaphore, task};
fn uncontended(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.core_threads(6)
.threaded_scheduler()
.build()
.unwrap();

Expand All @@ -29,7 +28,6 @@ async fn task(s: Arc<Semaphore>) {
fn uncontended_concurrent_multi(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.core_threads(6)
.threaded_scheduler()
.build()
.unwrap();

Expand All @@ -52,7 +50,7 @@ fn uncontended_concurrent_multi(b: &mut Bencher) {

fn uncontended_concurrent_single(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.basic_scheduler()
.core_threads(0)
.build()
.unwrap();

Expand All @@ -75,7 +73,6 @@ fn uncontended_concurrent_single(b: &mut Bencher) {
fn contended_concurrent_multi(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.core_threads(6)
.threaded_scheduler()
.build()
.unwrap();

Expand All @@ -98,7 +95,7 @@ fn contended_concurrent_multi(b: &mut Bencher) {

fn contended_concurrent_single(b: &mut Bencher) {
let rt = tokio::runtime::Builder::new()
.basic_scheduler()
.core_threads(0)
.build()
.unwrap();

Expand Down
36 changes: 23 additions & 13 deletions tokio-macros/src/entry.rs
@@ -1,6 +1,5 @@
use proc_macro::TokenStream;
use quote::quote;
use std::num::NonZeroUsize;

#[derive(Clone, Copy, PartialEq)]
enum Runtime {
Expand Down Expand Up @@ -43,8 +42,8 @@ fn parse_knobs(
if rt_threaded {
match &namevalue.lit {
syn::Lit::Int(expr) => {
let num = expr.base10_parse::<NonZeroUsize>().unwrap();
if num.get() > 1 {
let num = expr.base10_parse::<usize>().unwrap();
if num > 1 {
runtime = Some(Runtime::Threaded);
} else {
runtime = Some(Runtime::Basic);
Expand Down Expand Up @@ -77,7 +76,7 @@ fn parse_knobs(
}
"max_threads" => match &namevalue.lit {
syn::Lit::Int(expr) => {
let num = expr.base10_parse::<NonZeroUsize>().unwrap();
let num = expr.base10_parse::<usize>().unwrap();

if let Some(v) = core_threads {
if num < v {
Expand Down Expand Up @@ -128,17 +127,28 @@ fn parse_knobs(
}
}

let mut rt = quote! { tokio::runtime::Builder::new().basic_scheduler() };
let mut rt = quote! { tokio::runtime::Builder::new() };

if rt_threaded && (runtime == Some(Runtime::Threaded) || (runtime.is_none() && !is_test)) {
rt = quote! { #rt.threaded_scheduler() };
}
if let Some(v) = core_threads.map(|v| v.get()) {
rt = quote! { #rt.core_threads(#v) };
rt = quote! { #rt };
}
if let Some(v) = max_threads.map(|v| v.get()) {
rt = quote! { #rt.max_threads(#v) };

// if let Some(v) = core_threads {
// rt = quote! { #rt.core_threads(#v) };
// }

// if let Some(v) = max_threads {
// rt = quote! { #rt.max_threads(#v) };
// }

if is_test {
rt = quote! { #rt.core_threads(0) };
}

// if is_test && core_threads.is_none() {
// rt = quote! { #rt.core_threads(0) };
// }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't really care if we merge this, likely going to be rewritten in a follow up PR anyways.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't include #2906, so yes, it will be rewritten by that PR if this is merged first.


let header = {
if is_test {
quote! {
Expand Down Expand Up @@ -269,7 +279,7 @@ pub(crate) mod old {
#(#attrs)*
#vis #sig {
tokio::runtime::Builder::new()
.basic_scheduler()
.core_threads(0)
.enable_all()
.build()
.unwrap()
Expand Down Expand Up @@ -345,7 +355,7 @@ pub(crate) mod old {
#(#attrs)*
#vis fn #name() #ret {
tokio::runtime::Builder::new()
.basic_scheduler()
.core_threads(0)
.enable_all()
.build()
.unwrap()
Expand Down
8 changes: 3 additions & 5 deletions tokio-macros/src/lib.rs
Expand Up @@ -62,7 +62,6 @@ use proc_macro::TokenStream;
/// ```rust
/// fn main() {
/// tokio::runtime::Builder::new()
/// .threaded_scheduler()
/// .enable_all()
/// .build()
/// .unwrap()
Expand All @@ -88,7 +87,7 @@ use proc_macro::TokenStream;
/// ```rust
/// fn main() {
/// tokio::runtime::Builder::new()
/// .basic_scheduler()
/// .core_threads(0)
/// .enable_all()
/// .build()
/// .unwrap()
Expand All @@ -112,7 +111,6 @@ use proc_macro::TokenStream;
/// ```rust
/// fn main() {
/// tokio::runtime::Builder::new()
/// .threaded_scheduler()
/// .core_threads(2)
/// .enable_all()
/// .build()
Expand Down Expand Up @@ -191,7 +189,7 @@ pub fn main_threaded(args: TokenStream, item: TokenStream) -> TokenStream {
/// ```rust
/// fn main() {
/// tokio::runtime::Builder::new()
/// .basic_scheduler()
/// .core_threads(0)
/// .enable_all()
/// .build()
/// .unwrap()
Expand Down Expand Up @@ -242,7 +240,7 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
/// ```rust
/// fn main() {
/// tokio::runtime::Builder::new()
/// .basic_scheduler()
/// .core_threads(0)
/// .enable_all()
/// .build()
/// .unwrap()
Expand Down
2 changes: 1 addition & 1 deletion tokio-test/src/lib.rs
Expand Up @@ -29,7 +29,7 @@ pub fn block_on<F: std::future::Future>(future: F) -> F::Output {
use tokio::runtime;

let rt = runtime::Builder::new()
.basic_scheduler()
.core_threads(0)
.enable_all()
.build()
.unwrap();
Expand Down
8 changes: 4 additions & 4 deletions tokio-util/src/context.rs
Expand Up @@ -49,13 +49,13 @@ pub trait RuntimeExt {
/// use tokio::time::{delay_for, Duration};
///
/// let rt = tokio::runtime::Builder::new()
/// .threaded_scheduler()
/// .enable_all()
/// .build().unwrap();
/// .build()
/// .unwrap();
///
/// let rt2 = tokio::runtime::Builder::new()
/// .threaded_scheduler()
/// .build().unwrap();
/// .build()
/// .unwrap();
///
/// let fut = delay_for(Duration::from_millis(2));
///
Expand Down
8 changes: 1 addition & 7 deletions tokio-util/tests/context.rs
Expand Up @@ -7,17 +7,11 @@ use tokio_util::context::RuntimeExt;
#[test]
fn tokio_context_with_another_runtime() {
let rt1 = Builder::new()
.threaded_scheduler()
.core_threads(1)
// no timer!
.build()
.unwrap();
let rt2 = Builder::new()
.threaded_scheduler()
.core_threads(1)
.enable_all()
.build()
.unwrap();
let rt2 = Builder::new().core_threads(1).enable_all().build().unwrap();

// Without the `HandleExt.wrap()` there would be a panic because there is
// no timer running, since it would be referencing runtime r1.
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/stdio_common.rs
Expand Up @@ -124,7 +124,7 @@ mod tests {
wr.write_all(data.as_bytes()).await.unwrap();
};
crate::runtime::Builder::new()
.basic_scheduler()
.core_threads(0)
.build()
.unwrap()
.block_on(fut);
Expand Down
29 changes: 3 additions & 26 deletions tokio/src/lib.rs
Expand Up @@ -408,32 +408,9 @@ cfg_macros! {
#[doc(hidden)]
pub use tokio_macros::select_priv_declare_output_enum;

doc_rt_core! {
cfg_rt_threaded! {
// This is the docs.rs case (with all features) so make sure macros
// is included in doc(cfg).

#[cfg(not(test))] // Work around for rust-lang/rust#62127
#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
pub use tokio_macros::main_threaded as main;

#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
pub use tokio_macros::test_threaded as test;
}

cfg_not_rt_threaded! {
#[cfg(not(test))] // Work around for rust-lang/rust#62127
pub use tokio_macros::main_basic as main;
pub use tokio_macros::test_basic as test;
}
}

// Maintains old behavior
cfg_not_rt_core! {
#[cfg(not(test))]
pub use tokio_macros::main;
pub use tokio_macros::test;
}
#[cfg(not(test))]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again here, this will be re-reviewed once I get to the macros. This Pr is just for the builder.

pub use tokio_macros::main;
pub use tokio_macros::test;
}

// TODO: rm
Expand Down