bytedance/monoio

Send/Sync monoio::time::* structs

ThaddeusTreloar opened this issue · 2 comments

We are currently working on a codegen/RPC framework and are adding support for the monoio runtime. Unfortunately, due to the current architecture (using tokio), Send/Sync time data structures are required to re implement some of the timeout logic.

I notice that the current implementation is heavily derived from the solutions in tokio::time, in which most of the data structures are Send/Sync due to the use of thread safe sync primitives. For some reason when the time module was implemented for monoio these primitives were swapped out for their non thread safes equivalents.

I see one of two approaches being viable. The first involves migrating the non thread safe primitives to those found in std::sync and parking_lot, bringing the current implementation in line with that found in tokio. Alternatively, as the tokio implementation is quite complex and uses a lot of shared mutable state, it looks like one could re-engineer the module to a simpler implementation using consumer/producer channels.

If help is required I would be happy to contribute, I'm not sure what your policy on contributions is. Otherwise, feel free to let me know if you require any further context for this feature.

Since every thread has a time driver, and the driver would be accessed only by its thread, there's no need to keep those locks or atomics. The performance is better.

As for channel, users are free to use any channel implementation(include tokio's). We also provide a local-sync(using non thread safe primitives) if you'd like to use channel within the same thread and would not move to another. Note: if you want to use channel across different threads in monoio, you must enable sync feature and use thread-safe impl(tokio's channel, async-channel, etc.)

That makes perfect sense! I didn't realise the worker threads don't share tasks. Thank you for your help, I will close this issue.