diff --git a/README.md b/README.md index d1f96c82..e12373b9 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,7 @@ Moreover, Monoio is designed with a thread-per-core model in mind. Users do not As you may have guessed, this runtime is primarily targeted at servers, where operations are io-bound on network sockets, and therefore the use of native asynchronous I/O APIs maximizes the throughput of the server. In order for Monoio to be as efficient as possible, we've enabled some unstable Rust features, and we've designed a whole new IO abstraction, which unfortunately may cause some compatibility problems. [Our benchmarks](https://github.com/bytedance/monoio/blob/master/docs/en/benchmark.md) probe that, for our use-cases, Monoio has a better performance than other Rust runtimes. ## Quick Start -To use monoio, you need the latest nightly rust toolchain. If you already installed it, please make sure it is the latest version. - -To force using nightly, create a file named `rust-toolchain` and write `nightly` in it. Also, you can use `cargo +nightly` to build or run. +To use monoio, you need rust 1.75. If you already installed it, please make sure it is the latest version. Also, if you want to use io_uring, you must make sure your kernel supports it([5.6+](docs/en/platform-support.md)). And, memlock is [configured as a proper number](docs/en/memlock.md). If your kernel version does not meet the requirements, you can try to use the legacy driver to start, currently supports Linux and macOS([ref here](/docs/en/use-legacy-driver.md)). diff --git a/monoio/Cargo.toml b/monoio/Cargo.toml index cceea8d1..06a91e85 100644 --- a/monoio/Cargo.toml +++ b/monoio/Cargo.toml @@ -53,6 +53,8 @@ local-sync = "0.0.5" tempfile = "3.2" [features] +# use nightly only feature flags +unstable = [] # async-cancel will push a async-cancel entry into sq when op is canceled async-cancel = [] # enanle zero copy(enable SOCK_ZEROCOPY + MSG_ZEROCOPY flag) diff --git a/monoio/src/driver/uring/mod.rs b/monoio/src/driver/uring/mod.rs index bb16e8c0..bfe2bb22 100644 --- a/monoio/src/driver/uring/mod.rs +++ b/monoio/src/driver/uring/mod.rs @@ -330,12 +330,21 @@ impl UringInner { fn submit(&mut self) -> io::Result<()> { loop { match self.uring.submit() { + #[cfg(feature = "unstable")] Err(ref e) if e.kind() == io::ErrorKind::Other || e.kind() == io::ErrorKind::ResourceBusy => { self.tick(); } + #[cfg(not(feature = "unstable"))] + Err(ref e) if e.raw_os_error() == Some(libc::EAGAIN) || e.raw_os_error() == Some(libc::EBUSY) => { + // This error is constructed with io::Error::last_os_error(): + // https://github.com/tokio-rs/io-uring/blob/01c83bbce965d4aaf93ebfaa08c3aa8b7b0f5335/src/sys/mod.rs#L32 + // So we can use https://doc.rust-lang.org/nightly/std/io/struct.Error.html#method.raw_os_error + // to get the raw error code. + self.tick(); + }, e => return e.map(|_| ()), } } diff --git a/monoio/src/lib.rs b/monoio/src/lib.rs index 118086ff..ca0d2030 100644 --- a/monoio/src/lib.rs +++ b/monoio/src/lib.rs @@ -1,10 +1,10 @@ #![doc = include_str!("../../README.md")] #![warn(missing_docs, unreachable_pub)] #![allow(stable_features)] -#![feature(io_error_more)] -#![feature(lazy_cell)] -#![feature(stmt_expr_attributes)] -#![feature(thread_local)] +#![cfg_attr(feature = "unstable", feature(io_error_more))] +#![cfg_attr(feature = "unstable", feature(lazy_cell))] +#![cfg_attr(feature = "unstable", feature(stmt_expr_attributes))] +#![cfg_attr(feature = "unstable", feature(thread_local))] #[macro_use] pub mod macros; diff --git a/monoio/src/net/tcp/tfo/linux.rs b/monoio/src/net/tcp/tfo/linux.rs index 32f67dfb..e4a02bd1 100644 --- a/monoio/src/net/tcp/tfo/linux.rs +++ b/monoio/src/net/tcp/tfo/linux.rs @@ -1,8 +1,14 @@ use std::{cell::Cell, io, os::fd::AsRawFd}; +#[cfg(feature = "unstable")] #[thread_local] pub(crate) static TFO_CONNECT_AVAILABLE: Cell = Cell::new(true); +#[cfg(not(feature = "unstable"))] +thread_local!{ + pub(crate) static TFO_CONNECT_AVAILABLE: Cell = Cell::new(true); +} + /// Call before listen. pub(crate) fn set_tcp_fastopen(fd: &S, fast_open: i32) -> io::Result<()> { crate::syscall!(setsockopt( diff --git a/monoio/src/task/waker_fn.rs b/monoio/src/task/waker_fn.rs index 5d7f664e..5b0babfb 100644 --- a/monoio/src/task/waker_fn.rs +++ b/monoio/src/task/waker_fn.rs @@ -27,9 +27,15 @@ pub(crate) fn dummy_waker() -> Waker { unsafe { Waker::from_raw(raw_waker()) } } +#[cfg(feature = "unstable")] #[thread_local] static SHOULD_POLL: Cell = Cell::new(true); +#[cfg(not(feature = "unstable"))] +thread_local!{ + static SHOULD_POLL: Cell = Cell::new(true); +} + #[inline] pub(crate) fn should_poll() -> bool { SHOULD_POLL.replace(false) diff --git a/monoio/src/utils/thread_id.rs b/monoio/src/utils/thread_id.rs index 87681143..4633b3b4 100644 --- a/monoio/src/utils/thread_id.rs +++ b/monoio/src/utils/thread_id.rs @@ -1,12 +1,11 @@ use std::sync::{ atomic::{AtomicUsize, Ordering::Relaxed}, - LazyLock, }; // thread id begins from 16. // 0 is default thread // 1-15 are unused -static ID_GEN: LazyLock = LazyLock::new(|| AtomicUsize::new(16)); +static ID_GEN: AtomicUsize = AtomicUsize::new(16); pub(crate) const DEFAULT_THREAD_ID: usize = 0; diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index bf867e0a..00000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -nightly