{"id":15029943,"url":"https://github.com/xudong-huang/may","last_synced_at":"2025-04-23T23:12:47.685Z","repository":{"id":41377487,"uuid":"86022338","full_name":"Xudong-Huang/may","owner":"Xudong-Huang","description":"rust stackful coroutine library","archived":false,"fork":false,"pushed_at":"2025-03-24T05:51:39.000Z","size":1352,"stargazers_count":2064,"open_issues_count":22,"forks_count":86,"subscribers_count":42,"default_branch":"master","last_synced_at":"2025-04-23T23:12:42.697Z","etag":null,"topics":["async","coroutines","fibers","generator","green-threads","high-performance","io","primitives","rust","scalability"],"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/Xudong-Huang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-24T03:15:37.000Z","updated_at":"2025-04-23T02:46:35.000Z","dependencies_parsed_at":"2022-07-19T01:47:30.772Z","dependency_job_id":"61ef0ab1-7e2d-4f76-9f49-965382113b82","html_url":"https://github.com/Xudong-Huang/may","commit_stats":{"total_commits":539,"total_committers":11,"mean_commits":49.0,"dds":"0.029684601113172504","last_synced_commit":"5ecd454eb43a8b9d401b6714d638a5fdc752cda2"},"previous_names":[],"tags_count":65,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xudong-Huang%2Fmay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xudong-Huang%2Fmay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xudong-Huang%2Fmay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xudong-Huang%2Fmay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Xudong-Huang","download_url":"https://codeload.github.com/Xudong-Huang/may/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250528873,"owners_count":21445518,"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":["async","coroutines","fibers","generator","green-threads","high-performance","io","primitives","rust","scalability"],"created_at":"2024-09-24T20:12:02.942Z","updated_at":"2025-04-23T23:12:47.666Z","avatar_url":"https://github.com/Xudong-Huang.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1\u003eMay\u003c/h1\u003e\n    \u003ca href=\"https://github.com/Xudong-Huang/may/actions?query=workflow%3ACI+branch%3Amaster\"\u003e\n        \u003cimg src=\"https://github.com/Xudong-Huang/may/workflows/CI/badge.svg\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://crates.io/crates/may\"\u003e\n        \u003cimg src=\"https://img.shields.io/crates/v/may.svg\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://docs.rs/may\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/doc-may-green.svg\"\u003e\n    \u003c/a\u003e\n    \nMay is a high-performance library for programming stackful coroutines with which you can easily develop and maintain massive concurrent programs. It can be thought as the Rust version of the popular [Goroutine][go].\n\u003c/div\u003e\n\n----------\n\n## Table of contents\n* [Features](#features)\n* [Usage](#usage)\n* [More examples](#more-examples)\n  * [The CPU heavy load examples](#the-cpu-heavy-load-examples)\n  * [The I/O heavy bound examples](#the-io-heavy-bound-examples)\n* [Performance](#performance)\n* [Caveat](#caveat)\n* [How to tune a stack size](#how-to-tune-a-stack-size)\n* [License](#license)\n\n----------\n\n## Features\n* The stackful coroutine implementation is based on [generator][generator];\n* Support schedule on a configurable number of threads for multi-core systems;\n* Support coroutine version of a local storage ([CLS][cls]);\n* Support efficient asynchronous network I/O;\n* Support efficient timer management;\n* Support standard synchronization primitives, a semaphore, an MPMC channel, etc;\n* Support cancellation of coroutines;\n* Support graceful panic handling that will not affect other coroutines;\n* Support scoped coroutine creation;\n* Support general selection for all the coroutine API;\n* All the coroutine API are compatible with the standard library semantics;\n* All the coroutine API can be safely called in multi-threaded context;\n* Both stable, beta, and nightly channels are supported;\n* x86_64 GNU/Linux, x86_64 Windows, x86_64 macOS, AArch64 GNU/Linux, and AArch64 macOS are supported.\n\n----------\n\n## Usage\nA naive echo server implemented with May:\n```rust\n#[macro_use]\nextern crate may;\n\nuse may::net::TcpListener;\nuse std::io::{Read, Write};\n\nfn main() {\n    let listener = TcpListener::bind(\"127.0.0.1:8000\").unwrap();\n    while let Ok((mut stream, _)) = listener.accept() {\n        go!(move || {\n            let mut buf = vec![0; 1024 * 16]; // alloc in heap!\n            while let Ok(n) = stream.read(\u0026mut buf) {\n                if n == 0 {\n                    break;\n                }\n                stream.write_all(\u0026buf[0..n]).unwrap();\n            }\n        });\n    }\n}\n\n```\n\n----------\n\n## More examples\n\n### The CPU heavy load examples\n* [The \"Quick Sort\" algorithm][sort]\n* [A prime number generator][prime]\n\n### The I/O heavy bound examples\n* [An echo server][echo_server]\n* [An echo client][echo_client]\n* [A simple HTTP][http_sever]\n* [A simple HTTPS][https_sever]\n* [WebSockets][websocket]\n\n\n----------\n\n## Performance\nYou can refer to https://tfb-status.techempower.com/ to get the latest [may_minihttp][may_minihttp] comparisons with other most popular frameworks.\n\n----------\n\n## Caveat\nThere is a detailed [document][caveat] that describes May's main restrictions. In general, there are four things you should follow when writing programs that use coroutines:\n* Don't call thread-blocking API (It will hurt the performance);\n* Carefully use Thread Local Storage (access TLS in coroutine might trigger undefined behavior).\n\n\u003e It's considered **unsafe** with the following pattern:\n\u003e ```rust\n\u003e set_tls();\n\u003e // Or another coroutine API that would cause scheduling:\n\u003e coroutine::yield_now(); \n\u003e use_tls();\n\u003e ```\n\u003e but it's **safe** if your code is not sensitive about the previous state of TLS. Or there is no coroutines scheduling between **set** TLS and **use** TLS.\n\n* Don't run CPU bound tasks for long time, but it's ok if you don't care about fairness;\n* Don't exceed the coroutine stack. There is a guard page for each coroutine stack. When stack overflow occurs, it will trigger segment fault error.\n\n**Note:**\n\u003e The first three rules are common when using cooperative asynchronous libraries in Rust. Even using a futures-based system also have these limitations. So what you should really focus on is a coroutine stack size, make sure it's big enough for your applications. \n\n----------\n\n## How to tune a stack size\nIf you want to tune your coroutine stack size, please check out [this document][stack].\n\n----------\n\n## License\nMay is licensed under either of the following, at your option:\n\n * The Apache License v2.0.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0);\n * The MIT License ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT).\n\n\u003c!-- refs --\u003e\n[generator]:https://github.com/Xudong-Huang/generator-rs\n[sort]:https://github.com/Xudong-Huang/quick_sort\n[prime]:https://github.com/Xudong-Huang/prime\n[echo_server]:examples/echo.rs\n[echo_client]:examples/echo_client.rs\n[http_sever]:examples/http.rs\n[https_sever]:examples/https.rs\n[websocket]:examples/websocket.rs\n[cls]:docs/CLS_instead_of_TLS.md\n[go]:https://tour.golang.org/concurrency/1\n[tokio]:https://github.com/tokio-rs/tokio/blob/master/examples/echo.rs\n[caveat]:docs/may_caveat.md\n[stack]:docs/tune_stack_size.md\n[may_minihttp]:https://github.com/Xudong-Huang/may_minihttp\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxudong-huang%2Fmay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxudong-huang%2Fmay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxudong-huang%2Fmay/lists"}