《施继成-2023RustChinaConf 异步兼容层.pdf》由会员分享,可在线阅读,更多相关《施继成-2023RustChinaConf 异步兼容层.pdf(22页珍藏版)》请在三个皮匠报告上搜索。
1、Rust 异步 Runtime 的兼容层施继成 DatenLordIntroduce whats rust async runtime#Rust async runtimeAnalyze the reason of runtime isolation#Async runtime binding#Compatible layer1Create a wheel used everywhere Table of Contents23#Rust async runtime1Light-weight taskLanguage and compiler define tasksHow to run it?
2、When to run it?How does it deal with the I/O?Rust async runtimeRuntime responsibilities Invoke waiting tasks and halt tasks Get notifications from the OS Schedule tasks across threads if its multi-thread modelRust async runtimeAvailable Runtimes Tokio Async-std Smol MonoioRust async runtime#Async ru
3、ntime binding2Which runtime to choose?More adoptersRich eco-systemRich out-of-box featuresMaybe better performanceClean interfaceAsync runtime bindingEco system binding Panic“not currently running on the Tokioruntime”Hyper-fast and safe HTTP for tokio Surf-HTTP client framework for async-stdAsync ru
4、ntime bindingBarriers on runtime switch Switch all I/O related data structures Switch all async macros Switch all functions Scan everywhere We have to provide an abstraction to avoid thatAsync runtime bindingBuild libs for all runtimes Impossible You dont know how many runtimes there Provide a wrapp
5、er for runtimes Easy switch with rust features and conditional compilationAsync runtime binding#Compatible layer3Insight of compatible layerRust lang and compiler syntax and task typeAsync compatible layer I/O and task managementCompatible layerCompatible LayerCompare runtimesTokioAsync-stdSimilar c
6、omponent structuresCompatible layerCompare runtimesTokioAsync-stdAlmost the same APIsCompatible layerMain components in async runtimes Macros Data structures and associate functions Raw functionsCompatible layerMacro wrapperConditional compilingAttribute proc macroCompatible layerData structure wrap
7、perThe same type name but different typeGATTrait abstractionCompatible layerData structure wrapper cont.The same type name but different typeGATTrait abstractionCompatible layerFunction wrapperConditional compilingType conversionCompatible layerLimitations Conditional compiling global single runtime External Libs(Http,S3,etc.)Force the libs use this compatible layerWe provide a layer to wrap the popular utils,such as HTTP compatible layerCompatible layerThank you!