Skip to content

Use oxide-tokio-rt rather than #[tokio::main] #80

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Jul 16, 2025

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:

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 in order to use tokio-conssole, so that shouldn't be a problem.

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 in order to use `tokio-conssole`, so
that shouldn't be a problem.

[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
@hawkw hawkw requested a review from Nieuwejaar July 16, 2025 20:02
@Nieuwejaar
Copy link
Collaborator

For the most part dendrite's use of tokio and async is pretty basic. If it weren't required for dropshot, I'm not sure we would be using it at all.

One way in which we are possibly more complicated than other components is that we need to play nicely with the standard illumos multithreading mechanisms. The tofino SDE on which we are built uses threads and mutexes internally for all of its asynchrony. There are times we call into thread-land from tokio code, and there are times we use tokio channels from the SDE's thread-land to send notifications back to the main body of our code.

All of that is just to say that this should really get a workout on real hardware before being integrated, even though it look syntactically straightforward.

@hawkw
Copy link
Member Author

hawkw commented Jul 16, 2025

All of that is just to say that this should really get a workout on real hardware before being integrated, even though it look syntactically straightforward.

Yeah, I think it's definitely worth testing the change the same way you'd exercise any other change, but I think it's unlikely to break anything. Most of the risk associated with picking up this stuff in other repos has actually just been build/dev environment complexity due to requiring tokio_unstable --- the build.rustflags setting in .cargo/config.toml doesn't compose with other ways of setting RUSTFLAGS which is unfortunate when people are setting the env var or doing other things. That's less of an issue here because there's already a .cargo/config.toml that's enabling tokio-unstable, and dendrite already won't build without it.

@hawkw
Copy link
Member Author

hawkw commented Jul 16, 2025

(Sorry for the CI churn --- I couldn't get Dendrite to build locally due to some kind of libclang symbol versioning mess, so I thought I'd just let CI do it... 😅)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants