协程库
文章目录
【注意】最后更新于 March 14, 2020,文中内容可能已过时,请谨慎使用。
卡片
协程库 | 语言 | 开发者 |
---|---|---|
state threads library | 3000行C代码 | 历史渊源 |
摘要
今日理解。
一、一个普通的应用程序,假如采用st库,那么这个应用具备2个特点
- highly scalable applications,在负载伸缩和系统伸缩方面 将很容易的扩展,
- design of fast ,让开发快速简单,可以自由地使用静态变量和不可重入的库函数。
二、scalable:是什么
简单说,一个用户把cpu个数,或者线程个数增加一倍,性能也应该提一倍(system1蓝色原来的配置,system2 提高一倍之后的)
an application has a good load scalability if it can sustain its throughput over a wide range of loads
三、ST的多核架构核心是:Multi-Process EDSM,
继承了 Multi-Process, Multi-Threaded, and Event-Driven State Machine architectures全部优点。
The State Threads library combines the advantages of all of the above architectures。
Architecture | load scalability | system scalability | note |
---|---|---|---|
Multi-Process Architecture | poor | good | 负载差 |
Multi-Threaded Architecture | good | poor | 有资源竞争 |
Event-Driven State Machine Architecture | good | poor | 系统负载扩展差 |
Multi-Process EDSM | good | good | 完美 |
但是,
这是半成品,我只提供一个lib,因为其他方面,操作系统或者第三方技术已经做很好了。完全交给开发者,
Process management is not in the ST’s scope but instead is left up to the application.
具体完成过程需要开发者来实现
用户来决定fork多少进程,每个进程分配多少资源 。
The application designer has full control of how many processes to create
项目实践
- task 编译成动态库和静态库 10分钟
|
|
-
阅读 examples代码 50分钟
https://github.com/wangcy6/state-threads/blob/master/examples/server.c
————————————看到这里可以 -end——下面是记录 ———————————-
遗留问题
- st 真的有那么厉害吗?和golang 等其他语言比较是不是弱?
- st根本无法利用多核,怎么宣称是为互联网应用而生的呢?
文档FQA
阅读文档1 ,累计盘茄次数 5 耗时 130分钟
理解 ST本质上仍然是基于EDSM模型,但旨在取代传统的异步回调方式 ,为互联网应用程序而生的State Threads
涉及内容
State Threads Library Documentation
-
ST scheduler (不懂)
the ST scheduler is hidden inside the library and invisible to an application writer.
- traditional EDSM (不懂)
event-driven state machines (EDSM)
- virtual processor (不懂)
ST的多核架构
-
,ST的threads可以并发地线性地处理I/O事件 (不懂)
-
execute state event wait queue
-
setjmp/longjmp (不懂)
the context switch overhead is a cost of doing
_setjmp()/_longjmp()
(no system calls are involved).
并发不是并行,只要不让cpu闲着就行 这就是好的设计,例如多线程,多进程。
whenever a thread needs to wait for a specific event to occur, it saves its execution state and puts itself on an event wait queue – this is equivalent to registering a callback in traditional EDSMs.
Then the scheduler is executed. It pulls the first thread from the run queue and restores its execution state – this is equivalent to invoking a callback in traditional EDSMs.
If there are no runnable threads (the run queue is empty), the scheduler waits for I/O or timing events using select()
, poll()
or possibly other exotic mechanism available on that OS.
When events occur, the scheduler “wakes up” threads waiting for those events by putting them on the run queue. Then it restores the execution state of the first runnable thread. The cycle is complete.
- 看了一下代码和运行一个例子 懂了
-
The Go scheduler
-
TCP-Finite-State-Machine TCP 有限状态机
代码FQA
重要数据结构
|
|
重要接口
循环处理
|
|