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

tokio-uring missing similar tokio runtime builder options #286

Open
ciehanski opened this issue Nov 24, 2023 · 0 comments
Open

tokio-uring missing similar tokio runtime builder options #286

ciehanski opened this issue Nov 24, 2023 · 0 comments

Comments

@ciehanski
Copy link

Hello!

I am currently utilizing the standard tokio crate to start an asynchronous runtime for my app like so:

let runtime = Builder::new_multi_thread()
      .worker_threads(cfg.settings.worker_threads)
      .thread_name("myapp")
      .enable_all()
      .on_thread_start(|| {
          info!("thread started");
      })
      .on_thread_stop(|| {
          info!("thread stopped");
      })
      .build()
      .unwrap_or_else(|e| {
          terminate!(1, "unable to initialize runtime: {e}.");
      });

runtime.block_on(async { 
    // do stuff 
});

Since tokio-uring needs to inject a driver into the runtime to utilize io_uring, is it possible to support this with tokio or will I just need to replace this with tokio_uring::start(async { ... });?

I ask because after reviewing the builder docs it doesn't appear that we have options like worker_threads, on_thread_start, and on_thread_stop to initialize the tokio_uring runtime with.

Would it be possible to nest the tokio-uring runtime within a standard tokio runtime like so for ad hoc file operations?

runtime.block_on(async { 
   // do stuff

   // io tasks
   let (tx, rx) = unbounded_channel();
   tokio_uring::start(async {
        let tx = tx.clone();
        let file = File::open("hello.txt").await?;
        let buf = vec![0; 4096];
        let (res, buf) = file.read_at(buf, 0).await;
        let n = res?;
        tx.send(buf[..n])?;
        Ok(())
   });

   while let Some(bytes) = rx.recv().await {
       // handle recv
   }

   // do other stuff
});

I'm sure nested async runtimes are against best practice, but I wanted to reach out here and get consensus of how others are integrating tokio-uring into their projects if they depended on the standard tokio builder options. I may be overthinking this or missing something. Any pointers in the right direction would be helpful.

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

No branches or pull requests

1 participant