Await-Tree Async Rust 可观测性的灵丹妙药 - 赵梓淇
Rust 开发者大会 Await-Tree Async Rust 可观测性的灵丹妙药 赵梓淇 Bugen Zhao Await-Tree Async Rust 可观测性的灵丹妙药 Await-Tree 的 设计原理与实现 2 回顾 Async Rust 的设计与痛点 1 Await-Tree 的 应用与真实案例 3 Await-Tree Async Rust 可观测性的灵丹妙药 可观测性的灵丹妙药 Await-Tree 的 设计原理与实现 2 回顾 Async Rust 的设计与痛点 1 Await-Tree 的 应用与真实案例 3 Async Rust 的优势 • 异步编程的共同优势 • async/await 关键字 • 用户态调度 • Async Rust 的独特优势 • Ownership 与 Lifetime • 无栈协程 Async Rust 回顾 回顾 Rust 的无栈协程抽象 — Future Async Rust 回顾 • 通过 poll 驱动的状态机 • 组合嵌套为调度单元: Task • async fn 语法糖 Async Rust 观测与调试的痛点 Async Rust 回顾 • 特性: Future 灵活的可组合性 • 任意定制 Poll 的执行逻辑 (Join / Select / Timeout) • 动态的调用关系0 码力 | 37 页 | 8.60 MB | 1 年前3How Meta Made Debugging Async Code Easier with Coroutines and Senders
… … Stack Traces for Async Code are Unhelpful Threadpool threads: #0 process_file(...) #5 pool.run() #10 __clone … … IO Thread: #0 async_read_some_at(...) #3 ctx Threadpool threads: #0 process_file(...) #5 pool.run() #10 … IO Thread: … #0 async_read_some_at(...) #3 ctx.run() #5 __clone … … Main thread: #0 unifex::sync_wait( … #0 async_read_some_at(...) … #12 unifex::sync_wait(...) #16 main() #19 __libc_start_main() … … Async Stacks are BetterStructured Concurrency Makes Async Stacks Possible0 码力 | 131 页 | 907.41 KB | 5 月前3WebAssembly 简介 - 陈思衡
之类的 async runtime 中执行一些特别的 WASM 时就会遇到 WASM 阻塞 tokio 最终导致服务不可用的情况。 阻塞示例 WASM 使用场景和问题 利用语言本身 Async 机制 因为 Rust 的 async 机制是无栈协程,会将 async 部分在编译时隐式转换成一个 Future。 所以我们可以利用这一点来实现一个 Async 的 Wasm。 Async Wasm Photo / image / chart 利用本身 Async 机制 自行实现 Async Runtime Async 的 Wasm • 在 wasm 中把 future 存入固定内存处。 • 导出 poll 函数给 host 调用。 • 把 host function 包装成自定义 Future。 • 实现简单 利用本身 Async 机制 优点 • 方案不通用(wasm 局限于某一种语言) 无法与现有生态配合 缺点 Async 的 Wasm 基于 fiber / ucontext Async Wasm 解决方案 wasmtime-fiber 是一个通过内联汇编,保存当前寄存 器和栈数据来实现有栈协程的 rust 库。 wasmtime-fiber Ucontext 和 fiber 功能相同,但是 linux 的系统库。 ucontext 执行流程 Async Wasm 解决方案0 码力 | 24 页 | 773.46 KB | 1 年前3Deciphering C++ Coroutines
Cheat Sheet - Awaitable 1 struct Awaitable { 2 bool await_ready (); 3 auto await_suspend (std:: coroutine_handle < promise_type >); 4 auto await_resume (); 5 };12/55 Cheat Sheet: Map of Coroutine Land13/55 Task18/55 Threads - A straightforward solution std::futurespawn_task () { return std:: async( outer_function ); }18/55 Threads - A straightforward solution main() spawn task()18/55 Threads auto data = co_await async_io (...); co_return IoResult :: from_io_data(data ); }24/55 Suspending nested coroutines Async inner_function () { auto data = co_await async_io (...); co_return 0 码力 | 156 页 | 1.79 MB | 5 月前3Coroutines and Structured Concurrency in Practice
demonstrated to justify switchingCallbacks vs coroutines // read length auto len = make_unique(); async_read(socket, buffer(len.get(), sizeof(int32_t)), [len = move(len)](auto ec, size_t len1){ && len1 == sizeof(int32_t)) { // read data auto buf = make_unique (*len); async_read(socket, buffer(buf.get(), *len), [buf = move(buf), len = *len] (auto // read length int32_t len; co_await async_read(s, buffer(&len, sizeof(len)), use_awaitable); // read data auto buf = make_unique (len); co_await async_read(s, buffer(buf.get(), len) 0 码力 | 103 页 | 1.98 MB | 5 月前3Falcon v3.0.0 Documentation
Reference Router Inspection Information Classes Visitor Classes Utilities URI Date and Time HTTP Status Async Other Testing Helpers Simulating Requests Other Helpers Changelogs 3.0.0 Summary Changes to Supported containers. $ pip install [gunicorn|uwsgi|waitress] ASGI Server Conversely, in order to run an async Falcon ASGI app, you will need an ASGI [https://asgi.readthedocs.io/en/latest/] application server in terms of resources and state # transitions, which map to HTTP verbs. class ThingsResource: async def on_get(self, req, resp): """Handles GET requests""" resp.status = falcon.HTTP_2000 码力 | 1055 页 | 739.30 KB | 1 年前3Falcon v3.0.1 Documentation
Reference Router Inspection Information Classes Visitor Classes Utilities URI Date and Time HTTP Status Async Other Testing Helpers Simulating Requests Other Helpers Changelogs 3.0.1 Summary Fixed Contributors containers. $ pip install [gunicorn|uwsgi|waitress] ASGI Server Conversely, in order to run an async Falcon ASGI app, you will need an ASGI [https://asgi.readthedocs.io/en/latest/] application server in terms of resources and state # transitions, which map to HTTP verbs. class ThingsResource: async def on_get(self, req, resp): """Handles GET requests""" resp.status = falcon.HTTP_2000 码力 | 1058 页 | 741.59 KB | 1 年前3Falcon v3.0.0-b2 Documentation
HTTP error responses Full Unicode support Intuitive request and response objects Works great with async libraries like gevent Minimal attack surface for writing secure APIs 100% code coverage with a comprehensive Reference Router Inspection Information Classes Visitor Classes Utilities URI Date and Time HTTP Status Async Other Testing Helpers Simulating Requests Other Helpers Changelogs 3.0.0 Changes to Supported containers. $ pip install [gunicorn|uwsgi|waitress] ASGI Server Conversely, in order to run an async Falcon ASGI app, you will need an ASGI [https://asgi.readthedocs.io/en/latest/] application server0 码力 | 1041 页 | 730.21 KB | 1 年前3Falcon v3.0.0-b1 Documentation
HTTP error responses Full Unicode support Intuitive request and response objects Works great with async libraries like gevent Minimal attack surface for writing secure APIs 100% code coverage with a comprehensive Reference Router Inspection Information Classes Visitor Classes Utilities URI Date and Time HTTP Status Async Other Testing Helpers Simulating Requests Other Helpers Changelogs 3.0.0 Changes to Supported Falcon on it. $ pip install [gunicorn|uwsgi|waitress] ASGI Server Conversely, in order to run an async Falcon ASGI app, you will need an ASGI [https://asgi.readthedocs.io/en/latest/] application server0 码力 | 1028 页 | 725.86 KB | 1 年前3websockets Documentation Release 9.0
import asyncio import websockets async def hello(): uri = "ws://localhost:8765" async with websockets.connect(uri) as websocket: await websocket.send("Hello world!") await websocket.recv() asyncio.get_event_loop() server: #!/usr/bin/env python import asyncio import websockets async def echo(websocket, path): async for message in websocket: await websocket.send(message) start_server = websockets.serve(echo, "localhost" example import asyncio import websockets async def hello(websocket, path): name = await websocket.recv() print(f"< {name}") greeting = f"Hello {name}!" await websocket.send(greeting) print(f"> {greeting}")0 码力 | 81 页 | 352.88 KB | 1 年前3
共 1000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 100