All Projects → Xudong-Huang → May

Xudong-Huang / May

Licence: other
rust stackful coroutine library

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to May

Mioco
[no longer maintained] Scalable, coroutine-based, fibers/green-threads for Rust. (aka MIO COroutines).
Stars: ✭ 125 (-86.25%)
Mutual labels:  async, coroutines, fibers, io, scalability
Groupco
PHP的服务化框架。适用于Api、Http Server、Rpc Server;帮助原生PHP项目转向微服务化。出色的性能与支持高并发的协程相结合
Stars: ✭ 473 (-47.96%)
Mutual labels:  async, coroutines, generator
Boson
A C++14 framework for asynchronous I/O, cooperative multitasking and green threads scheduling
Stars: ✭ 154 (-83.06%)
Mutual labels:  coroutines, fibers, io
Recoil
Asynchronous coroutines for PHP 7.
Stars: ✭ 765 (-15.84%)
Mutual labels:  async, coroutines, generator
Minicoro
Single header asymmetric stackful cross-platform coroutine library in pure C.
Stars: ✭ 164 (-81.96%)
Mutual labels:  async, coroutines, fibers
Kotlin Flow Extensions
Extensions to the Kotlin Flow library.
Stars: ✭ 404 (-55.56%)
Mutual labels:  async, coroutines
Asyncawait
async/await for Android built upon coroutines introduced in Kotlin 1.1
Stars: ✭ 410 (-54.9%)
Mutual labels:  async, coroutines
Elle
The Elle coroutine-based asynchronous C++ development framework.
Stars: ✭ 459 (-49.5%)
Mutual labels:  coroutines, fibers
Lwt
OCaml promises and concurrent I/O
Stars: ✭ 505 (-44.44%)
Mutual labels:  fibers, io
Fibertaskinglib
A library for enabling task-based multi-threading. It allows execution of task graphs with arbitrary dependencies.
Stars: ✭ 679 (-25.3%)
Mutual labels:  coroutines, fibers
Swiftcoroutine
Swift coroutines for iOS, macOS and Linux.
Stars: ✭ 690 (-24.09%)
Mutual labels:  async, coroutines
Trio
Trio – a friendly Python library for async concurrency and I/O
Stars: ✭ 4,404 (+384.49%)
Mutual labels:  async, io
Swoole Src
🚀 Coroutine-based concurrency library for PHP
Stars: ✭ 17,175 (+1789.44%)
Mutual labels:  async, coroutines
Asks
Async requests-like httplib for python.
Stars: ✭ 429 (-52.81%)
Mutual labels:  async, io
Umka Lang
Umka: a statically typed embeddable scripting language
Stars: ✭ 308 (-66.12%)
Mutual labels:  coroutines, fibers
Amp
A non-blocking concurrency framework for PHP applications. 🐘
Stars: ✭ 3,457 (+280.31%)
Mutual labels:  async, coroutines
Kotlin Coroutines Retrofit
Kotlin Coroutines await() extension for Retrofit Call
Stars: ✭ 812 (-10.67%)
Mutual labels:  async, coroutines
Zato
ESB, SOA, REST, APIs and Cloud Integrations in Python
Stars: ✭ 889 (-2.2%)
Mutual labels:  scalability, high-performance
Forge Server Utils
Tools for accessing Autodesk Forge APIs from modern Node.js apps.
Stars: ✭ 23 (-97.47%)
Mutual labels:  async, generator
Creed
Sophisticated and functionally-minded async with advanced features: coroutines, promises, ES2015 iterables, fantasy-land
Stars: ✭ 265 (-70.85%)
Mutual labels:  async, coroutines

May

May is a high-performant 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.


Table of contents


Features

  • The stackful coroutine's implementation is based on generator;
  • Support schedule on a configurable number of threads for multi-core systems;
  • Support coroutine's version of a local storage (CLS);
  • Support efficient asynchronous network I/O;
  • Support efficient timer management;
  • Support standard synchronization primitives, a semaphore, an MPMC channel, etc;
  • Support cancellation of coroutines;
  • Support graceful panic handling that will not affect other coroutines;
  • Support scoped coroutine creation;
  • Support general selection for all the coroutine's API;
  • All the coroutine's API are compatible with the standard library semantics;
  • All the coroutine's API can be safely called in multi-threaded context;
  • Both stable, beta, and nightly channels are supported;
  • Both x86_64 GNU/Linux, x86_64 Windows, x86_64 Mac OS are supported.

Usage

A naive echo server implemented with May:

#[macro_use]
extern crate may;

use may::net::TcpListener;
use std::io::{Read, Write};

fn main() {
    let listener = TcpListener::bind("127.0.0.1:8000").unwrap();
    while let Ok((mut stream, _)) = listener.accept() {
        go!(move || {
            let mut buf = vec![0; 1024 * 16]; // alloc in heap!
            while let Ok(n) = stream.read(&mut buf) {
                if n == 0 {
                    break;
                }
                stream.write_all(&buf[0..n]).unwrap();
            }
        });
    }
}


More examples

The CPU heavy load examples

The I/O heavy bound examples


Performance

You can refer to https://tfb-status.techempower.com/ to get the latest may_minihttp comparisons with other most popular frameworks.


Caveat

There is a detailed document that describes May's main restrictions. In general, there are four things you should follow when writing programs that use coroutines:

  • Don't call thread-blocking API (It will hurt the performance);
  • Carefully use Thread Local Storage (access TLS in coroutine might trigger undefined behavior).

It's considered unsafe with the following pattern:

set_tls();
// Or another coroutine's API that would cause scheduling:
coroutine::yield_now(); 
use_tls();

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.

  • Don't run CPU bound tasks for long time, but it's ok if you don't care about fairness;
  • 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.

Note:

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's stack size, make sure it's big enough for your applications.


How to tune a stack size

If you want to tune your coroutine's stack size, please check out this document.


License

May is licensed under either of the following, at your option:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].