{"id":13415622,"url":"https://github.com/bytedance/monoio","last_synced_at":"2025-05-14T22:00:27.255Z","repository":{"id":37915007,"uuid":"433350425","full_name":"bytedance/monoio","owner":"bytedance","description":"Rust async runtime based on io-uring.","archived":false,"fork":false,"pushed_at":"2025-04-22T21:31:00.000Z","size":5294,"stargazers_count":4468,"open_issues_count":58,"forks_count":244,"subscribers_count":49,"default_branch":"master","last_synced_at":"2025-05-07T21:13:40.335Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bytedance.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":"CONTRIBUTING-zh.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-11-30T08:25:46.000Z","updated_at":"2025-05-07T09:11:56.000Z","dependencies_parsed_at":"2024-04-07T09:21:22.374Z","dependency_job_id":"d1f61e50-589b-497c-b986-54973c13a4ba","html_url":"https://github.com/bytedance/monoio","commit_stats":{"total_commits":90,"total_committers":21,"mean_commits":4.285714285714286,"dds":"0.28888888888888886","last_synced_commit":"ef21bca117e057676b435702b463b7a50ed6fb67"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytedance%2Fmonoio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytedance%2Fmonoio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytedance%2Fmonoio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytedance%2Fmonoio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bytedance","download_url":"https://codeload.github.com/bytedance/monoio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235685,"owners_count":22036962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T21:00:50.846Z","updated_at":"2025-05-14T22:00:27.192Z","avatar_url":"https://github.com/bytedance.png","language":"Rust","funding_links":[],"categories":["Rust","Projects","库"],"sub_categories":["Storage engines \u003ca name=\"storage\"\u003e\u003c/a\u003e"],"readme":"# Monoio\n一个基于 io_uring/epoll/kqueue 和 thread-per-core 模型 Rust Runtime。\n\n[![Crates.io][crates-badge]][crates-url]\n[![MIT/Apache-2 licensed][license-badge]][license-url]\n[![Build Status][actions-badge]][actions-url]\n[![Codecov][codecov-badge]][codecov-url]\n[English Readme][en-readme-url]\n\n[crates-badge]: https://img.shields.io/crates/v/monoio.svg\n[crates-url]: https://crates.io/crates/monoio\n[license-badge]: https://img.shields.io/crates/l/monoio.svg\n[license-url]: LICENSE-MIT\n[actions-badge]: https://github.com/bytedance/monoio/actions/workflows/ci.yml/badge.svg\n[actions-url]: https://github.com/bytedance/monoio/actions\n[codecov-badge]: https://codecov.io/gh/bytedance/monoio/branch/master/graph/badge.svg?token=3MSAMJ6X3E\n[codecov-url]: https://codecov.io/gh/bytedance/monoio\n[en-readme-url]: README.md\n\n## 设计目标\n作为一个基于 io_uring/epoll/kqueue 的 Runtime，Monoio 目标是在兼顾平台兼容性的情况下，做最高效、性能最优的 thread-per-core Rust Runtime。\n\n我们的出发点很简单：跨线程任务调度会带来额外开销，且对 Task 本身有 `Send` 和 `Sync` 约束，导致无法很好地使用 thread local storage。而很多场景并不需要跨线程调度。如 `nginx` 这种负载均衡代理，我们往往可以以 thread-per-core 的模式编写。这样可以减少跨线程通信的开销，提高性能；也可以尽可能地利用 thread local 来做极低成本的任务间通信。当任务不需要被跨线程调度时，它就没有了实现 `Send` 和 `Sync` 的约束。另一点是 io_uring 相比 epoll 在性能上有很大提升，我们也希望能够尽可能利用它达到最佳性能。所以基于 io_uring 做一套 thread-per-core 的 Runtime 理论上可以获得一些场景下的最佳性能。\n\nMonoio 就是这样一个 Runtime：它并不像 Tokio 那样通过公平调度保证通用性，它的目标是在**特定场景下**(thread per core 模型并不适用于所有场景)提供最好的性能。为了性能，Monoio 还开启了 GAT 等一系列的 unstable feature；同时也提供了全新的无拷贝的 IO 抽象。\n\n功能上目前支持了部分网络 IO 和计时器；也支持跨线程异步通信。\n\n[我们的基准测试](docs/zh/benchmark.md) 表明 Monoio 比其他常见的 Rust 运行时具有更好的性能。\n\n## 快速上手\n要使用 Monoio，你需要最新的 nightly 工具链。如果你已经安装了 nightly 工具链，请确保是最新的版本。\n\n在项目中创建 `rust-toolchain` 文件并在其中写入 `nightly` 即可强制指定；也可以使用 `cargo +nightly` 来构建或运行。\n\n同时，如果你想使用 io_uring，你需要确保你当前的内核版本是较新的([5.6+](docs/zh/platform-support.md))；并且 memlock 是一个[合适的配置](docs/zh/memlock.md)。如果你的内核版本不满足需求，可以尝试使用 legacy driver 启动([参考这里](/docs/zh/use-legacy-driver.md))，当前支持 Linux 和 macOS。\n\n🚧实验性的 windows 系统支持正在开发中。\n\n这是一个非常简单的例子，基于 Monoio 实现一个简单的 echo 服务。运行起来之后你可以通过 `nc 127.0.0.1 50002` 来连接它。\n\n```rust,no_run\n/// A echo example.\n///\n/// Run the example and `nc 127.0.0.1 50002` in another shell.\n/// All your input will be echoed out.\nuse monoio::io::{AsyncReadRent, AsyncWriteRentExt};\nuse monoio::net::{TcpListener, TcpStream};\n\n#[monoio::main]\nasync fn main() {\n    let listener = TcpListener::bind(\"127.0.0.1:50002\").unwrap();\n    println!(\"listening\");\n    loop {\n        let incoming = listener.accept().await;\n        match incoming {\n            Ok((stream, addr)) =\u003e {\n                println!(\"accepted a connection from {}\", addr);\n                monoio::spawn(echo(stream));\n            }\n            Err(e) =\u003e {\n                println!(\"accepted connection failed: {}\", e);\n                return;\n            }\n        }\n    }\n}\n\nasync fn echo(mut stream: TcpStream) -\u003e std::io::Result\u003c()\u003e {\n    let mut buf: Vec\u003cu8\u003e = Vec::with_capacity(8 * 1024);\n    let mut res;\n    loop {\n        // read\n        (res, buf) = stream.read(buf).await;\n        if res? == 0 {\n            return Ok(());\n        }\n\n        // write all\n        (res, buf) = stream.write_all(buf).await;\n        res?;\n\n        // clear\n        buf.clear();\n    }\n}\n```\n\n在本仓库的 `examples` 目录中有更多的例子。\n\n## 限制\n1. 在 Linux 5.6 或更新版本上，Monoio 可以以 uring 或 epoll 作为可选驱动方式，低版本 Linux 上只能以 epoll 方式运行，在 macOS 上可以使用 kqueue。其他平台暂不支持。\n2. Monoio 这种 thread per core 的 runtime 并不适用于任意场景。如果负载非常不均衡，相比公平调度模型的 Tokio 它可能会性能变差，因为 CPU 利用可能不均衡，不能充分利用可用核心。\n\n## 贡献者\n\u003ca href=\"https://github.com/bytedance/monoio/graphs/contributors\"\u003e\u003cimg src=\"https://opencollective.com/monoio/contributors.svg?width=890\u0026button=false\" /\u003e\u003c/a\u003e\n\n在此表示感谢！\n\n## 社区\nMonoio 是 [CloudWego](https://www.cloudwego.io/) 的子项目，我们致力于建设云原生生态系统。\n\n## 关联项目\n- [local-sync](https://github.com/monoio-rs/local-sync)：一个线程内的 channel 实现\n- [monoio-tls](https://github.com/monoio-rs/monoio-tls)：Monoio TLS 支持\n- [monoio-codec](https://github.com/monoio-rs/monoio-codec)：Monoio Codec 支持\n\nHTTP 框架和 RPC 框架在做了在做了(咕咕咕)。\n\n## 协议\nMonoio 基于 MIT 或 Apache 协议授权。\n\n在开发中我们大量参考了 Tokio, Mio, Tokio-uring 和其他一些项目，在此向这些项目的贡献者们表示感谢。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytedance%2Fmonoio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytedance%2Fmonoio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytedance%2Fmonoio/lists"}