5 个版本 (1 个稳定版)
使用旧的 Rust 2015
1.1.0 | 2017 年 1 月 27 日 |
---|---|
0.12.0 | 2016 年 12 月 21 日 |
0.11.0 | 2016 年 11 月 5 日 |
0.1.1 | 2016 年 10 月 18 日 |
0.1.0 | 2016 年 10 月 18 日 |
#1071 在 并发
745KB
10K SLoC
内核
TL;DR 自动平衡低延迟非阻塞零拷贝 CAS-多游标队列,具有优先级任务和可扩展计时器。
特性
- MIO 兼容的带有连接的网络服务器
- 可向量化的 SMP 感知流组合器
- 具有环形缓冲区 CAS-语义的 MPSC、SPMC、SPSC 队列
- 零拷贝解释器和队列
- 会话类型和 π-演算语义
- 5-20 纳秒延迟
- BERT 协议用于 VM 统计
- AVX 向量化
- 专用 InterCore 总线协议(星型拓扑)
O 语言
$ cargo build ; rlwrap ./target/debug/o -init etc/init.q
Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
AP core 3
AP core 2
AP core 1
BSP core 0
Welcome to The O Language 1.1.0
o)InterCore Exec 0 "a:pub 1;b:pub 2;c:pub 2;d:[a;b;c]\n\n" Yield(Nil)
InterCore Pub 2 1 Pub { from: 0, to: 1, task_id: 0, name: "", cap: 8 }
InterCore AckPub 0 AckPub { from: 1, to: 0, task_id: 0, result_id: 1 }
InterCore Pub 3 2 Pub { from: 0, to: 2, task_id: 0, name: "", cap: 8 }
InterCore AckPub 0 AckPub { from: 2, to: 0, task_id: 0, result_id: 1 }
InterCore Pub 3 2 Pub { from: 0, to: 2, task_id: 0, name: "", cap: 8 }
InterCore AckPub 0 AckPub { from: 2, to: 0, task_id: 0, result_id: 2 }
o)a:pub 2
InterCore Exec 0 "a:pub 2\n" Yield(Nil)
InterCore Pub 3 2 Pub { from: 0, to: 2, task_id: 0, name: "", cap: 8 }
InterCore AckPub 0 AckPub { from: 2, to: 0, task_id: 0, result_id: 3 }
o)fac:{$[x=1;1;x*fac[x-1]]};fac[20]
InterCore Exec 0 "fac:{$[x=1;1;x*fac[x-1]]};fac[20]\n" End(Node(Value(Number(2432902008176640000))))
o)a
InterCore Exec 0 "a\n" End(Node(Value(Number(3))))
启用 AVX 向量化
$ cat ./cargo/config
[target.x86_64-unknown-linux-gnu]
rustflags="-C target-feature=+avx,+avx2"
$ cargo build --release
$ objdump ./target/release/o -d | grep mulpd
223f1: c5 f5 59 0c d3 vmulpd (%rbx,%rdx,8),%ymm1,%ymm1
223f6: c5 dd 59 64 d3 20 vmulpd 0x20(%rbx,%rdx,8),%ymm4,%ymm4
22416: c5 f5 59 4c d3 40 vmulpd 0x40(%rbx,%rdx,8),%ymm1,%ymm1
2241c: c5 dd 59 64 d3 60 vmulpd 0x60(%rbx,%rdx,8),%ymm4,%ymm4
2264d: c5 f5 59 0c d3 vmulpd (%rbx,%rdx,8),%ymm1,%ymm1
22652: c5 e5 59 5c d3 20 vmulpd 0x20(%rbx,%rdx,8),%ymm3,%ymm3
$ objdump ./target/release/o -d | grep vpmul
2251c: c5 d5 f4 fb vpmuludq %ymm3,%ymm5,%ymm7
22525: c4 41 55 f4 c0 vpmuludq %ymm8,%ymm5,%ymm8
2253a: c5 d5 f4 db vpmuludq %ymm3,%ymm5,%ymm3
22547: c5 cd f4 ec vpmuludq %ymm4,%ymm6,%ymm5
22550: c5 cd f4 ff vpmuludq %ymm7,%ymm6,%ymm7
22562: c5 cd f4 e4 vpmuludq %ymm4,%ymm6,%ymm4
22595: c5 d5 f4 fb vpmuludq %ymm3,%ymm5,%ymm7
示例
extern crate kernel;
use kernel::io::poll::*;
use kernel::io::tcp::*;
use kernel::io::server::*;
use kernel::io::console::*;
fn main() {
let x = std::thread::spawn(|| net());
let y = std::thread::spawn(|| console());
x.join();
}
fn net() {
let addr = "127.0.0.1:8000".parse::<std::net::SocketAddr>().ok().expect("Parser Error");
let sock = TcpListener::bind(&addr).ok().expect("Failed to bind address");
let mut poll = Poll::new().expect("Failed to create Poll");
let mut net = Server::new(sock);
net.run(&mut poll).expect("Failed to run server");
}
fn console() {
let mut poll = Poll::new().expect("Failed to create Poll");
let mut con = Console::new();
con.run(&mut poll);
}
测试 WebSocket 服务器
先决条件
$ sudo apt-get install webfs
$ brew install webfs
$ cd /usr/ports/www/webfs/ && make install clean
打开浏览器
$ open http://127.0.0.1:8001/etc/status/index.htm
阅读
- Kohei Honda 会话类型和 π-演算 http://mrg.doc.ic.ac.uk/kohei/
- Rust 版本 http://munksgaard.me/laumann-munksgaard-larsen.pdf
- Haskell 版本 http://users.eecs.northwestern.edu/~jesse/pubs/haskell-session-types/session08.pdf
致谢
- Viktor Sovietov,核心建议
- Anton Kundenko,流处理
- Ievgenii Lysiuchenko,优化,系统编程
- Denis Golovan,向量化,KCell,解释器
- Mykola Oleksiienko,K 专业技能
- Maxim Sokhatsky,总体观点
灵感
- Ken Pratt,Rusty Scheme
- Carl Lerche,MIO
依赖项
~8MB
~165K SLoC