Skip to content

Commit a183fb6

Browse files
committed
add more docs
1 parent 0d00b2f commit a183fb6

File tree

5 files changed

+173
-23
lines changed

5 files changed

+173
-23
lines changed

README.md

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,33 @@
88
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/acl-dev/open-coroutine.svg)](http://isitmaintained.com/project/acl-dev/open-coroutine "Average time to resolve an issue")
99
[![Percentage of issues still open](http://isitmaintained.com/badge/open/acl-dev/open-coroutine.svg)](http://isitmaintained.com/project/acl-dev/open-coroutine "Percentage of issues still open")
1010

11-
The `open-coroutine` is a simple, efficient and generic stackfull-coroutine library, you can use this as a performance replacement for IO thread pools.
11+
The `open-coroutine` is a simple, efficient and generic stackfull-coroutine library, you can use this as a performance
12+
replacement for IO thread pools, see [why better](core/docs/en/why-better.md).
1213

1314
English | [中文](README_ZH.md)
1415

1516
## 🚀 Features
1617

17-
- [x] Preemptive(`not supported in windows`): even if the coroutine enters a dead loop, it can still be seized, see [example](https://github.com/loongs-zhang/open-coroutine/blob/master/open-coroutine/examples/preemptive.rs);
18-
- [x] Hook: you are free to use most of the slow syscall in coroutine, see supported syscall on [unix](https://github.com/acl-dev/open-coroutine/blob/master/hook/src/syscall/unix.rs)/[windows](https://github.com/acl-dev/open-coroutine/blob/master/hook/src/syscall/windows.rs);
19-
- [x] Scalable: the size of the coroutine stack supports unlimited expansion without the cost of copying stack, and immediately shrinks to the original size after use, see [example](https://github.com/loongs-zhang/open-coroutine/blob/master/open-coroutine/examples/scalable_stack.rs);
20-
- [x] io_uring(`only in linux`): supports and is compatible with io_uring in terms of local file IO and network IO. If it's not supported on your system, it will fall back to non-blocking IO;
18+
- [x] Preemptive(`not supported in windows`): even if the coroutine enters a dead loop, it can still be seized,
19+
see [example](https://github.com/loongs-zhang/open-coroutine/blob/master/open-coroutine/examples/preemptive.rs);
20+
- [x] Hook: you are free to use most of the slow syscall in coroutine, see supported syscall
21+
on [unix](https://github.com/acl-dev/open-coroutine/blob/master/hook/src/syscall/unix.rs)/[windows](https://github.com/acl-dev/open-coroutine/blob/master/hook/src/syscall/windows.rs);
22+
- [x] Scalable: the size of the coroutine stack supports unlimited expansion without the cost of copying stack, and
23+
immediately shrinks to the original size after use,
24+
see [example](https://github.com/loongs-zhang/open-coroutine/blob/master/open-coroutine/examples/scalable_stack.rs);
25+
- [x] io_uring(`only in linux`): supports and is compatible with io_uring in terms of local file IO and network IO. If
26+
it's not supported on your system, it will fall back to non-blocking IO;
2127
- [x] Priority: support custom task priority, note that coroutine priority is not open to users;
2228
- [x] Work Steal: internally using a lock free work steal queue;
23-
- [x] Compatibility: the implementation of open-coroutine is no async, but it is compatible with async, which means you can use this crate in `tokio/async-std/smol/...`;
29+
- [x] Compatibility: the implementation of open-coroutine is no async, but it is compatible with async, which means you
30+
can use this crate in `tokio/async-std/smol/...`;
2431
- [x] Platforms: running on Linux, macOS and Windows;
2532

2633
## 🕊 Roadmap
2734

2835
- [ ] add docs;
29-
- [ ] add performance [benchmark](https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview);
36+
- [ ] add
37+
performance [benchmark](https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview);
3038
- [ ] cancel coroutine/task;
3139
- [ ] add metrics;
3240
- [ ] add synchronization toolkit;
@@ -79,7 +87,7 @@ graph TD
7987
subgraph open-coroutine
8088
end
8189
hook -->|depends on| core
82-
open-coroutine -->|depends on| hook
90+
open-coroutine -->|link| hook
8391
open-coroutine -->|depends on| macros
8492
end
8593
subgraph OperationSystem
@@ -179,11 +187,12 @@ fn main() {
179187
## ⚓ Learn More
180188

181189
- [Coroutine Overview](core/docs/en/coroutine.md)
190+
- [Scalable Stack Overview](core/docs/en/scalable-stack.md)
182191
- [Monitor Overview](core/docs/en/monitor.md)
183192

184193
[我有故事,你有酒吗?](https://github.com/acl-dev/open-coroutine-docs)
185194

186-
## 🙏 Credits
195+
## 👍 Credits
187196

188197
This crate was inspired by the following projects:
189198

@@ -194,3 +203,10 @@ This crate was inspired by the following projects:
194203
- [monoio](https://github.com/bytedance/monoio)
195204
- [compio](https://github.com/compio-rs/compio)
196205
- [may](https://github.com/Xudong-Huang/may)
206+
207+
Thanks to those who have provided assistance:
208+
209+
![Amanieu](https://images.weserv.nl/?url=avatars.githubusercontent.com/Amanieu?v=4&h=79&w=79&fit=cover&mask=circle&maxage=7d)
210+
![bjorn3](https://images.weserv.nl/?url=avatars.githubusercontent.com/bjorn3?v=4&h=79&w=79&fit=cover&mask=circle&maxage=7d)
211+
![workingjubilee](https://images.weserv.nl/?url=avatars.githubusercontent.com/workingjubilee?v=4&h=79&w=79&fit=cover&mask=circle&maxage=7d)
212+
![Noratrieb](https://images.weserv.nl/?url=avatars.githubusercontent.com/Noratrieb?v=4&h=79&w=79&fit=cover&mask=circle&maxage=7d)

README_ZH.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@
88
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/acl-dev/open-coroutine.svg)](http://isitmaintained.com/project/acl-dev/open-coroutine "解决issue的平均时间")
99
[![Percentage of issues still open](http://isitmaintained.com/badge/open/acl-dev/open-coroutine.svg)](http://isitmaintained.com/project/acl-dev/open-coroutine "仍未关闭issue的百分比")
1010

11-
`open-coroutine`是一个简单、高效、通用的有栈协程库,您可以将其用作IO线程池的性能替代
11+
`open-coroutine`是一个简单、高效、通用的有栈协程库,您可以将其用作IO线程池的性能替代,查看[为什么更好](core/docs/en/why-better.md).
1212

1313
[English](README.md) | 中文
1414

1515
## 🚀 当前特性
1616

17-
- [x] 抢占调度(`不支持windows`): 即使协程进入死循环,它仍能被抢占,查看[例子](https://github.com/loongs-zhang/open-coroutine/blob/master/open-coroutine/examples/preemptive.rs);
18-
- [x] Hook: 您可以在协程中自由使用大多数慢系统调用,查看支持的系统调用[unix](https://github.com/acl-dev/open-coroutine/blob/master/hook/src/syscall/unix.rs)/[windows](https://github.com/acl-dev/open-coroutine/blob/master/hook/src/syscall/windows.rs);
19-
- [x] 可伸缩栈: 协程栈的大小支持无限制扩容而没有复制堆栈的开销,查看[例子](https://github.com/loongs-zhang/open-coroutine/blob/master/open-coroutine/examples/scalable_stack.rs);
17+
- [x] 抢占调度(`不支持windows`):
18+
即使协程进入死循环,它仍能被抢占,查看[例子](https://github.com/loongs-zhang/open-coroutine/blob/master/open-coroutine/examples/preemptive.rs);
19+
- [x] Hook:
20+
您可以在协程中自由使用大多数慢系统调用,查看支持的系统调用[unix](https://github.com/acl-dev/open-coroutine/blob/master/hook/src/syscall/unix.rs)/[windows](https://github.com/acl-dev/open-coroutine/blob/master/hook/src/syscall/windows.rs);
21+
- [x] 可伸缩栈:
22+
协程栈的大小支持无限制扩容而没有复制堆栈的开销,查看[例子](https://github.com/loongs-zhang/open-coroutine/blob/master/open-coroutine/examples/scalable_stack.rs);
2023
- [x] io_uring(`只支持linux`): 在本地文件IO和网络IO方面支持并兼容io_uring。如果您的系统不支持,它将回退到NIO;
2124
- [x] 优先级: 支持自定义任务优先级,注意协程优先级未对用户开放;
2225
- [x] 任务窃取: 内部使用无锁任务窃取队列;
@@ -26,7 +29,8 @@
2629
## 🕊 未来计划
2730

2831
- [ ] 完善文档;
29-
- [ ] 增加性能[基准测试](https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview);
32+
- [ ]
33+
增加性能[基准测试](https://github.com/TechEmpower/FrameworkBenchmarks/wiki/Project-Information-Framework-Tests-Overview);
3034
- [ ] 取消协程/任务;
3135
- [ ] 增加性能指标;
3236
- [ ] 增加并发工具包;
@@ -79,7 +83,7 @@ graph TD
7983
subgraph open-coroutine
8084
end
8185
hook -->|depends on| core
82-
open-coroutine -->|depends on| hook
86+
open-coroutine -->|link| hook
8387
open-coroutine -->|depends on| macros
8488
end
8589
subgraph OperationSystem
@@ -153,7 +157,7 @@ fn main() {
153157
}
154158
```
155159

156-
### 扩容栈
160+
### 可伸缩栈
157161

158162
```rust
159163
#[open_coroutine::main]
@@ -183,7 +187,7 @@ fn main() {
183187

184188
[我有故事,你有酒吗?](https://github.com/acl-dev/open-coroutine-docs)
185189

186-
## 🙏 鸣谢
190+
## 👍 鸣谢
187191

188192
这个crate的灵感来自以下项目:
189193

@@ -193,4 +197,11 @@ fn main() {
193197
- [stacker](https://github.com/rust-lang/stacker)
194198
- [monoio](https://github.com/bytedance/monoio)
195199
- [compio](https://github.com/compio-rs/compio)
196-
- [may](https://github.com/Xudong-Huang/may)
200+
- [may](https://github.com/Xudong-Huang/may)
201+
202+
感谢那些提供帮助的人:
203+
204+
![Amanieu](https://images.weserv.nl/?url=avatars.githubusercontent.com/Amanieu?v=4&h=79&w=79&fit=cover&mask=circle&maxage=7d)
205+
![bjorn3](https://images.weserv.nl/?url=avatars.githubusercontent.com/bjorn3?v=4&h=79&w=79&fit=cover&mask=circle&maxage=7d)
206+
![workingjubilee](https://images.weserv.nl/?url=avatars.githubusercontent.com/workingjubilee?v=4&h=79&w=79&fit=cover&mask=circle&maxage=7d)
207+
![Noratrieb](https://images.weserv.nl/?url=avatars.githubusercontent.com/Noratrieb?v=4&h=79&w=79&fit=cover&mask=circle&maxage=7d)

core/docs/en/coroutine.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ The above is excerpted from [corosensei](https://github.com/Amanieu/corosensei).
6565
| limitations | ✅ Few | ❌ Many |
6666

6767
In general, if the requirements for resource utilization and switching performance are not very strict, using a
68-
stackfull approach would be more convenient and the code would be easier to maintain.
68+
stackfull approach would be more convenient and the code would be easier to maintain. So, `open-coroutine` chooses the
69+
stackfull coroutine.
6970

7071
## State in open-coroutine
7172

core/docs/en/overview.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
## open-coroutine overview
1+
---
2+
title: open-coroutine Overview
3+
date: 2025-01-10 08:24:00
4+
author: loongs-zhang
5+
---
6+
7+
# open-coroutine overview
28

39
[![crates.io](https://img.shields.io/crates/v/open-coroutine.svg)](https://crates.io/crates/open-coroutine)
410
[![docs.rs](https://img.shields.io/badge/docs-release-blue)](https://docs.rs/open-coroutine)
@@ -8,12 +14,14 @@
814
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/acl-dev/open-coroutine.svg)](http://isitmaintained.com/project/acl-dev/open-coroutine "Average time to resolve an issue")
915
[![Percentage of issues still open](http://isitmaintained.com/badge/open/acl-dev/open-coroutine.svg)](http://isitmaintained.com/project/acl-dev/open-coroutine "Percentage of issues still open")
1016

11-
The `open-coroutine` is a simple, efficient and generic stackfull-coroutine library, you can use this as a performance replacement for IO thread pools.
17+
The `open-coroutine` is a simple, efficient and generic stackfull-coroutine library, you can use this as a performance
18+
replacement for IO thread pools, see [why better](../en/why-better.md).
1219

1320
[//]: # (todo 增加英文版本的文档)
21+
1422
- [Background](../../../docs/cn/background.md)
15-
- [Why rust](../../../docs/cn/why-rust.md)
16-
- [Why better]()
23+
- [Why Rust](../../../docs/cn/why-rust.md)
24+
- [Why Better](../en/why-better.md)
1725
- [Quick Start](../../../README.md)
1826
- [Coroutine Overview](../en/coroutine.md)
1927
- [Scalable Stack Overview](../en/scalable-stack.md)

core/docs/en/why-better.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
title: Why Better
3+
date: 2025-01-10 08:28:00
4+
author: loongs-zhang
5+
---
6+
7+
# Why Better
8+
9+
## Syscall will not block
10+
11+
Firstly, let's take a look at how thread collaborate with syscall.
12+
13+
```mermaid
14+
sequenceDiagram
15+
Actor User Thread
16+
participant Operation System
17+
18+
User Thread ->>+ User Thread: execute
19+
alt User Thread blocked
20+
User Thread ->>+ Operation System: slow syscall
21+
Operation System ->> User Thread: return
22+
end
23+
User Thread ->>+ User Thread: execute
24+
```
25+
26+
If the syscall is a slow syscall, such as `accept` without setting non-blocking, the thread will be blocked for a long
27+
time and unable to do anything until the OS returns. Now, let's take a look at how open-coroutine collaborate with
28+
syscall.
29+
30+
```mermaid
31+
sequenceDiagram
32+
Actor EventLoop Thread
33+
participant Coroutine1
34+
participant Coroutine2
35+
participant Hooked Syscall
36+
participant Operation System
37+
38+
EventLoop Thread ->>+ Coroutine1: schedule
39+
alt Coroutine1 blocked logically
40+
Coroutine1 ->>+ Hooked Syscall: slow syscall
41+
Hooked Syscall ->>+ Operation System: fast syscall
42+
Operation System ->> Hooked Syscall: return errno
43+
Hooked Syscall ->> Coroutine1: suspend the coroutine for a period of time
44+
end
45+
Coroutine1 ->>+ EventLoop Thread: suspended
46+
EventLoop Thread ->>+ Coroutine2: schedule
47+
alt Coroutine2 blocked logically
48+
Coroutine2 ->>+ Hooked Syscall: slow syscall
49+
Hooked Syscall ->>+ Operation System: fast syscall
50+
Operation System ->> Hooked Syscall: return
51+
Hooked Syscall ->> Coroutine2: return
52+
end
53+
Coroutine2 ->>+ EventLoop Thread: return
54+
EventLoop Thread ->>+ Coroutine1: schedule
55+
alt Coroutine1 blocked logically
56+
Coroutine1 ->>+ Hooked Syscall: resume from the last pause
57+
Hooked Syscall ->>+ Operation System: fast syscall
58+
Operation System ->> Hooked Syscall: return
59+
Hooked Syscall ->> Coroutine1: return
60+
end
61+
Coroutine1 ->>+ EventLoop Thread: return
62+
EventLoop Thread ->>+ EventLoop Thread: schedule other coroutines
63+
```
64+
65+
As you can see, `Hooked Syscall` converts `slow syscall` to `fast syscall`. In this way, although the `EventLoop Thread`
66+
will still be blocked when executing syscall, the blocking time is very short. Therefore, compared to the thread model,
67+
`EventLoop Thread` can do more things in the same amount of time.
68+
69+
## Heavy computing will not block
70+
71+
Secondly, let's take a look at how threads handle heavy computations.
72+
73+
```mermaid
74+
sequenceDiagram
75+
Actor User Thread
76+
77+
alt User Thread gets stuck in a loop
78+
User Thread ->>+ User Thread: execute loop
79+
end
80+
```
81+
82+
Just like syscall above, thread will always block in the loop. Then, let's take a look at how open-coroutine handle
83+
heavy computations.
84+
85+
```mermaid
86+
sequenceDiagram
87+
Actor EventLoop Thread
88+
participant Coroutine1
89+
participant Coroutine2
90+
participant Monitor
91+
92+
EventLoop Thread ->>+ Coroutine1: schedule
93+
alt Coroutine1 enters loop
94+
Coroutine1 ->>+ Coroutine1: execute loop for a period of time
95+
Monitor ->> Coroutine1: suspend the coroutine
96+
end
97+
Coroutine1 ->>+ EventLoop Thread: suspended
98+
EventLoop Thread ->>+ Coroutine2: schedule
99+
alt Coroutine2 enters loop
100+
Coroutine2 ->>+ Coroutine2: execute loop for a period of time
101+
Monitor ->> Coroutine1: suspend the coroutine
102+
end
103+
Coroutine2 ->>+ EventLoop Thread: suspended
104+
EventLoop Thread ->>+ Coroutine1: schedule
105+
alt Coroutine1 enters loop
106+
Coroutine1 ->>+ Coroutine1: resume from the last pause
107+
end
108+
Coroutine1 ->>+ EventLoop Thread: return
109+
EventLoop Thread ->>+ EventLoop Thread: schedule other coroutines
110+
```
111+
112+
`Monitor` will monitor the execution of coroutines, and once it found that the execution time of a coroutine is too
113+
long, it will force the coroutine to suspend. So now, we can even use just one `EventLoop Thread` to execute multiple
114+
loops, which cannot be achieved under the single threaded model.

0 commit comments

Comments
 (0)