Skip to content

Commit c234a92

Browse files
authored
Add multicore to default features (#612)
We don't have any blockers to using the threaded runtime by default. This change adds the `multicore` feature flag to the default feature list. It also modifies the threaded runtime initialization to use all available cores. The thread names have been changed from `linkerd2-proxy-worker` to just `proxy`, which is more consistent with the `admin` thread name. This should be unambiguous in the context of the process.
1 parent 935b65d commit c234a92

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

linkerd2-proxy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ publish = false
77
description = "The main proxy executable"
88

99
[features]
10+
default = ["multicore"]
1011
mock-orig-dst = ["linkerd2-app/mock-orig-dst"]
1112
multicore = ["tokio/rt-threaded", "num_cpus"]
1213

linkerd2-proxy/src/rt.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,35 @@
1-
use tokio::runtime::{self, Runtime};
1+
use tokio::runtime::{Builder, Runtime};
22

33
#[cfg(feature = "multicore")]
44
pub(crate) fn build() -> Runtime {
5-
let builder = runtime::Builder::new()
6-
.enable_all()
7-
.thread_name("linkerd2-proxy-worker");
8-
let num_cpus = num_cpus::get();
9-
if num_cpus > 2 {
10-
builder
11-
.threaded_scheduler()
12-
.core_threads(num_cpus - 1) // Save 1 core for the admin runtime.
13-
.build()
14-
.expect("failed to build multithreaded runtime!")
15-
} else {
16-
builder
5+
// The proxy creates an additional admin thread, but it would be wasteful to allocate a whole
6+
// core to it; so we let the main runtime consume all cores the process has. The basic scheduler
7+
// is used when the threaded scheduler would provide no benefit.
8+
match num_cpus::get() {
9+
// `0` is unexpected, but it's a wild world out there.
10+
0 | 1 => Builder::new()
11+
.enable_all()
12+
.thread_name("proxy")
1713
.basic_scheduler()
1814
.build()
19-
.expect("failed to build single-threaded runtime!")
15+
.expect("failed to build basic runtime!"),
16+
num_cpus => Builder::new()
17+
.enable_all()
18+
.thread_name("proxy")
19+
.threaded_scheduler()
20+
.core_threads(num_cpus)
21+
.max_threads(num_cpus)
22+
.build()
23+
.expect("failed to build threaded runtime!"),
2024
}
2125
}
2226

2327
#[cfg(not(feature = "multicore"))]
2428
pub(crate) fn build() -> Runtime {
25-
runtime::Builder::new()
29+
Builder::new()
2630
.enable_all()
27-
.thread_name("linkerd2-proxy-worker")
31+
.thread_name("proxy")
2832
.basic_scheduler()
2933
.build()
30-
.expect("failed to build single-threaded runtime!")
34+
.expect("failed to build basic runtime!")
3135
}

0 commit comments

Comments
 (0)