Skip to content

Commit c082b46

Browse files
authored
Use oxide-tokio-rt crate for common Tokio runtime config (#8412)
Currently, all the async Rust binaries in the Omicron workspace use the `#[tokio::main]` attribute on an `async fn main()`. This creates a Tokio runtime with the default configuration provided by that attribute, and runs the contents of the `async` main function on that runtime. We now have need to configure the Tokio runtime used by Omicron differently than the defaults provided by the `#[tokio::main]` macro. In particular, we want to do the following: - Disable the LIFO slot optimization, which can cause severe latency spikes in some cases (see #8334 (comment)) - When running on illumos, configure runtime callbacks to emit `tokio-dtrace` probes (see #8364) In order to make it easier to use these configurations in all production binaries in Omicron and other projects, I've introduced a new [`oxide-tokio-rt` crate](https://github.com/oxidecomputer/oxide-tokio-rt). This crate provides functions that configure a runtime with our desired settings and runs a future on it. This can be used to replace `#[tokio::main]` fairly simply, which I've done for most binaries in the repo. There are a handful of binaries I did *not* update to use `omicron-runtime`. In particular, I didn't change the use of `#[tokio::main]` in example binaries (in particular, `oximeter-producer` and `update-engine`), as I didn't want to add an `omicron-runtime` dependency to those crates just for example. In the case of `oximeter-producer`, in particular, which is depended on by code outside of the Omicron repo, that would force those binaries to compile `omicron-runtime` unnecessarily. Similarly, I didn't make some of the dev-tools binaries which are used in xtasks use `oxide-tokio-rt`, because I didn't want to introduce another dependency that has to be compiled before an xtask can run, and that felt more important than adding DTrace probes to those simple commands --- if something goes wrong with them, we can add the proves later. The exception to this are the `mgs-dev` and `omicron-dev` binaries, which run MGS and Nexus *in-process*; in those cases, I felt it was useful to have the DTrace probes enabled when running in development. Similarly, I also thought it was worthwhile to use `omicron-runtime` in OMDB, as it's deployed on production systems and would be harder to recompile with DTrace probes if we end up wanting them. Closes #8364
1 parent 75d391d commit c082b46

File tree

77 files changed

+289
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+289
-129
lines changed

.cargo/config.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@
1111
# - .github/buildomat/jobs/check-features.sh
1212
# - .github/workflows/rust.yml
1313
#
14+
# WARNING: If you're setting `RUSTFLAGS` in a global `~/.cargo/config.toml`, or
15+
# as an environment variable in your shell, this will CONFLICT WITH THE
16+
# CONFIGURATION HERE, as `build.rustflags` configuration is NOT ADDITIVE.
17+
# This is particularly relevant for folks using the `mold` linker via
18+
# `RUSTFLAGS`. `mold` users should consider using `mold -run cargo` instead, as
19+
# described here: https://github.com/rui314/mold#how-to-use
1420
[build]
1521
rustdocflags = "--document-private-items"
22+
rustflags = "--cfg tokio_unstable"
1623

1724
# On illumos, use `-znocompstrtab` to reduce link time. We also add the Oxide
1825
# specific platform directory to the RPATH where additional libraries can be
@@ -57,7 +64,9 @@ rustdocflags = "--document-private-items"
5764
# variety of things such as host OS.
5865
[target.x86_64-unknown-illumos]
5966
rustflags = [
60-
"-C", "link-arg=-Wl,-znocompstrtab,-R/usr/platform/oxide/lib/amd64"
67+
"-C", "link-arg=-Wl,-znocompstrtab,-R/usr/platform/oxide/lib/amd64",
68+
# enable the `tokio-unstable` config for `tokio-dtrace` probes
69+
"--cfg", "tokio_unstable"
6170
]
6271

6372
# Set up `cargo xtask`.

.github/buildomat/build-and-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ banner ls-apis
9292
# from end-to-end-tests.
9393
#
9494
banner build
95-
export RUSTFLAGS="-D warnings"
95+
export RUSTFLAGS="--cfg tokio_unstable -D warnings"
9696
export RUSTDOCFLAGS="--document-private-items -D warnings"
9797
# When running on illumos we need to pass an additional runpath that is
9898
# usually configured via ".cargo/config" but the `RUSTFLAGS` env variable

.github/buildomat/jobs/clippy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ ptime -m bash ./tools/install_builder_prerequisites.sh -y
3434
banner clippy
3535
export CARGO_INCREMENTAL=0
3636
ptime -m cargo xtask clippy
37-
RUSTDOCFLAGS="--document-private-items -D warnings" ptime -m cargo doc --workspace --no-deps
37+
RUSTDOCFLAGS="--document-private-items -D warnings --cfg tokio" ptime -m cargo doc --workspace --no-deps

Cargo.lock

Lines changed: 49 additions & 0 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
@@ -564,6 +564,7 @@ omicron-test-utils = { path = "test-utils" }
564564
omicron-workspace-hack = "0.1.0"
565565
omicron-zone-package = "0.12.2"
566566
oxide-client = { path = "clients/oxide-client" }
567+
oxide-tokio-rt = "0.1.1"
567568
oxide-vpc = { git = "https://github.com/oxidecomputer/opte", rev = "f5560fae02ad3fc349fabc6454c321143199ca9e", features = [ "api", "std" ] }
568569
oxlog = { path = "dev-tools/oxlog" }
569570
oxnet = "0.1.2"

clickhouse-admin/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ http.workspace = true
1717
illumos-utils.workspace = true
1818
omicron-common.workspace = true
1919
omicron-uuid-kinds.workspace = true
20+
oxide-tokio-rt.workspace = true
2021
oximeter-db.workspace = true
2122
schemars.workspace = true
2223
slog.workspace = true

clickhouse-admin/src/bin/clickhouse-admin-keeper.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ enum Args {
3939
},
4040
}
4141

42-
#[tokio::main]
43-
async fn main() {
44-
if let Err(err) = main_impl().await {
42+
fn main() {
43+
if let Err(err) = oxide_tokio_rt::run(main_impl()) {
4544
fatal(err);
4645
}
4746
}

clickhouse-admin/src/bin/clickhouse-admin-server.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ enum Args {
3939
},
4040
}
4141

42-
#[tokio::main]
43-
async fn main() {
44-
if let Err(err) = main_impl().await {
42+
fn main() {
43+
if let Err(err) = oxide_tokio_rt::run(main_impl()) {
4544
fatal(err);
4645
}
4746
}

clickhouse-admin/src/bin/clickhouse-admin-single.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ enum Args {
3838
},
3939
}
4040

41-
#[tokio::main]
42-
async fn main() {
43-
if let Err(err) = main_impl().await {
41+
fn main() {
42+
if let Err(err) = oxide_tokio_rt::run(main_impl()) {
4443
fatal(err);
4544
}
4645
}

clippy.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,12 @@ disallowed-types = [
2828
{ path = "once_cell::unsync::Lazy", reason = "use `std::cell::LazyCell` instead" },
2929
{ path = "once_cell::unsync::LazyCell", reason = "use `std::cell::LazyCell` instead" },
3030
]
31+
32+
[[disallowed-macros]]
33+
path = "tokio::main"
34+
reason = """\
35+
Binaries deployed in production should use the `oxide_tokio_rt` \
36+
crate, as it enables DTrace probes and runtime configuration. \
37+
dev-tools, xtasks, and examples may use `#[tokio::main]` when \
38+
necessary to avoid an `omicron-runtime` dependency.\
39+
"""

0 commit comments

Comments
 (0)