openraft icon indicating copy to clipboard operation
openraft copied to clipboard

Add a Monoio async runtime

Open Miaxos opened this issue 1 year ago • 2 comments

Starting a work around AsyncRuntime to have a MonoioRuntime available & tested.

The main issue is around is_panic and abort right now, as to properly abort a task by using monoio, you need to cancel the IO with a Canceller.

⚠️ This a still a draft, the end idea is to have monoio available and this PR is also used to find out what steps are needed to achieve this. ⚠️

Checklist

  • [ ] Updated guide with pertinent info (may not always apply).
  • [ ] Squash down commits to one or two logical commits which clearly describe the work you've done.
  • [ ] Unittest is a friend:)

Considerations

  • async-entry worker_threads have no impact on monoio with the current implementation of async-entry

References

  • Issue linked: https://github.com/datafuselabs/openraft/issues/1011

This change is Reviewable

Miaxos avatar Feb 16 '24 14:02 Miaxos

BTW, we should probably make all required types part of the runtime, so tokio would be optional as well.

I do completely agree!

Currently, oneshot and mpsc channels as well as some other primitives are taken 1:1 from Tokio.

👍

Feel free to propose an API where you can pass the Canceller around properly. Can't it be part of a JoinHandle (i.e., wrap monoio::JoinHandle in a new type)?

Yeah, well, you need to have access to the Canceller when you want to abort the task, but you'll also need to have access to the Canceller when you do some IO related to io-uring when you are inside the spawned task, so you need it when you are spawning your task, something like this could be possible:

        #[inline]
        fn spawn<T>(fn: F) -> Self::JoinHandle<T::Output>
        where
            T: Future + OptionalSend + 'static,
            T::Output: OptionalSend + 'static,
            F: FnOnce(&AsyncRuntimeContext) -> T,
        {
          ...
        }

I'll try to have some ideas around, and it would be better to also have integration tests running on this new runtime too (linked to https://github.com/drmingdrmer/async-entry/issues/1 )

Miaxos avatar Feb 16 '24 17:02 Miaxos

Fix OptionalSend usage:

  • #1014

drmingdrmer avatar Feb 18 '24 12:02 drmingdrmer