Skip to content

Commit 666ccc9

Browse files
authored
Use oxide-tokio-rt rather than #[tokio::main] (#523)
As described in [RFD 579], we are now recommending certain non-default Tokio runtime configurations in all software we deploy in production. The [`oxide-tokio-rt`] crate provides a way to easily get these common recommended configurations by using its functions to initialize the runtime rather than `#[tokio::main]` Presently, `oxide-tokio-rt` does the following: - Enables DTrace probes for Tokio runtime events using [`tokio-dtrace`] - Disables the [LIFO slot optimization][lifo], which was the root cause of omicron#8334 But, we anticipate that if there are additional Tokio configurations which we want to recommend in the future, we'll add them here as well. This commit updates `dendrite` to initialize the Tokio runtime using `oxide-tokio-rt`. I've added a Clippy config for warning on uses of `#[tokio::main]`, as well, to avoid forgetting to use `oxide-tokio-rt` if new binaries are added. All the configs we set currently in `oxide-tokio-rt` requires the `tokio_unstable` RUSTFLAGS cfg, but it looks like that's already being set, so that shouldn't be a problem. I've changed every binary to use `oxide-tokio-rt` with the exception of `mg-package` --- it didn't seem necessary to use the production-like config there and maybe avoiding an additional dependency to fetch would make it build slightly faster, although I'm unconvinced. I did change the lab binaries to use `oxide-tokio-rt`, as I figured that the DTrace probes could come in handy there. [RFD 579]: https://rfd.shared.oxide.computer/rfd/0579 [`oxide-tokio-rt`]: https://github.com/oxidecomputer/oxide-tokio-rt [`tokio-dtrace`]: https://github.com/oxidecomputer/tokio-dtrace [lifo]: https://rfd.shared.oxide.computer/rfd/0579#_disabling_the_lifo_slot_optimization
1 parent 1c7bb10 commit 666ccc9

File tree

20 files changed

+90
-24
lines changed

20 files changed

+90
-24
lines changed

Cargo.lock

Lines changed: 30 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ rand = "0.8.5"
8282
backoff = "0.4"
8383
mg-common = { path = "mg-common" }
8484
chrono = { version = "0.4.41", features = ["serde"] }
85+
oxide-tokio-rt = "0.1.2"
8586
oximeter = { git = "https://github.com/oxidecomputer/omicron", branch = "main"}
8687
oximeter-producer = { git = "https://github.com/oxidecomputer/omicron", branch = "main"}
8788
oxnet = { version = "0.1.2", default-features = false, features = ["schemars", "serde"] }

clippy.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[[disallowed-macros]]
2+
path = "tokio::main"
3+
reason = "prefer `oxide_tokio_rt` for production software"
4+
replacement = "oxide_tokio_rt::run"

ddmadm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ anstyle.workspace = true
1111
anyhow.workspace = true
1212
clap.workspace = true
1313
colored.workspace = true
14+
oxide-tokio-rt.workspace = true
1415
oxnet.workspace = true
1516
slog-async.workspace = true
1617
slog-envlogger.workspace = true

ddmadm/src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ struct Peer {
8989
addr: Ipv6Addr,
9090
}
9191

92-
#[tokio::main]
93-
async fn main() -> Result<()> {
94-
run().await
92+
fn main() -> Result<()> {
93+
oxide_tokio_rt::run(run())
9594
}
9695

9796
async fn run() -> Result<()> {

ddmd/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mg-common = { path = "../mg-common" }
99
anyhow.workspace = true
1010
clap.workspace = true
1111
libnet.workspace = true
12+
oxide-tokio-rt.workspace = true
1213
slog.workspace = true
1314
slog-bunyan.workspace = true
1415
slog-async.workspace = true

ddmd/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ struct Dendrite {
107107
port: u16,
108108
}
109109

110-
#[tokio::main]
111-
async fn main() {
110+
fn main() {
111+
oxide_tokio_rt::run(run())
112+
}
113+
114+
async fn run() {
112115
let arg = Arg::parse();
113116
let log = init_logger();
114117

lab/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2018"
77
libfalcon = { git = "https://github.com/oxidecomputer/falcon", branch = "main" }
88
anyhow.workspace = true
99
tokio.workspace = true
10+
oxide-tokio-rt.workspace = true
1011

1112
[[bin]]
1213
name = "solo"

lab/src/2x2/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ use libfalcon::error::Error;
99
use libfalcon::unit::gb;
1010
use libfalcon::Runner;
1111

12-
#[tokio::main]
13-
async fn main() -> Result<(), Error> {
12+
fn main() -> Result<(), Error> {
13+
oxide_tokio_rt::run(main_impl())
14+
}
15+
16+
async fn main_impl() -> Result<(), Error> {
1417
let mut d = Runner::new("mg2x2");
1518

1619
// routers

lab/src/duo/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ use libfalcon::error::Error;
1010
use libfalcon::unit::gb;
1111
use libfalcon::Runner;
1212

13-
#[tokio::main]
14-
async fn main() -> Result<(), Error> {
13+
fn main() -> Result<(), Error> {
14+
oxide_tokio_rt::run(main_impl())
15+
}
16+
17+
async fn main_impl() -> Result<(), Error> {
1518
let mut d = Runner::new("duo");
1619

1720
// nodes

0 commit comments

Comments
 (0)