TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Tokio internals: Understanding Rust's async I/O framework

110 点作者 bowyakka超过 7 年前

5 条评论

carllerche超过 7 年前
I&#x27;m (one of) the author of Tokio, hopefully I can clarify some points.<p>&gt; Unfortunately, Tokio is notoriously difficult to learn due to its sophisticated abstractions.<p>IMO, this is largely due to the current state of the docs (which are going to be rewritten as soon as some API changes land).<p>The docs were written at a point where we were still trying to figure out how to present Tokio, and they ended up focusing on the wrong things.<p>The Tokio docs currently focus on a very high level concept (`Service`) which is an RPC like abstraction similar to finagle.<p>The problem is that, Tokio also includes a novel runtime model and future system and the docs don&#x27;t spend any time explaining this.<p>The next iteration of Tokio&#x27;s docs is going to focus entirely at the &quot;tokio-core&quot; level, which is the reactor, runtime model, and TCP streams.<p>tl;dr, I think the main reason people have trouble learning Tokio is because the current state of the docs are terrible.<p>&gt; Aren’t abstractions supposed to make things easier to learn?<p>Tokio&#x27;s goal is to provide as ergonomic abstractions as possible <i></i>without adding runtime overhead<i></i>. Tokio will never be as &quot;easy&quot; as high level runtimes simply because we don&#x27;t accept the overhead that comes with them.<p>The abstractions are also structured to help you avoid a lot of errors that tend to be introduced in asynchronous applications. For example, Tokio doesn&#x27;t add any implicit buffering anywhere. A lot of other async libraries hide difficult details by adding unlimited buffering layers.
olix0r超过 7 年前
I&#x27;ve written a few production-facing applications with Tokio; and I think the author exactly identifies the stumbling blocks I hit while learning the landscape.<p>My takeaway from working with Tokio is that it&#x27;s a fairly low-level abstraction and doesn&#x27;t do much to address the challenges of building networked _applications_. And this is OK.<p>We&#x27;ll need higher-level layers that use Tokio, however, to address more specific use cases. I&#x27;ll point to the nascent tower-grpc[1] library as something in this direction. I hope to see more things like this fall out of our work on Conduit[2].<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;tower-rs&#x2F;tower-grpc" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tower-rs&#x2F;tower-grpc</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;runconduit&#x2F;conduit" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;runconduit&#x2F;conduit</a>
kindfellow92超过 7 年前
&gt; Unfortunately, Tokio is notoriously difficult to learn due to its sophisticated abstractions.<p>Aren’t abstractions supposed to make things easier to learn? Something about the idea of “complex abstractions” seems wrong.<p>(Edit: this is not a criticism of Tokio, it’s a criticism of the OP’s characterization of “sophisticated abstractions” which IMO should reduce complexity)
评论 #15973057 未加载
评论 #15973028 未加载
评论 #15973710 未加载
评论 #15974306 未加载
评论 #15973032 未加载
评论 #15973095 未加载
Const-me超过 7 年前
&gt; The tokio-core crate provides the central event loop<p>Does it mean it only uses a single thread for IO notifications?<p>If yes, the performance won’t be exceptionally great, especially on servers with many CPU cores and fast network interfaces.<p>The underlying OS APIs (both epoll, kqueue and iocp) do support multithreaded asynchronous IO, so that’s not some platform limitation.
评论 #15974013 未加载
jbirer超过 7 年前
I prefer golang&#x27;s syscalls and os modules. Just direct interfaces to the C functions, no abstractions and no cruft.
评论 #15973031 未加载
评论 #15972976 未加载
评论 #15972938 未加载
评论 #15973234 未加载
评论 #15973041 未加载
评论 #15972941 未加载
评论 #15972895 未加载
评论 #15972931 未加载
评论 #15974394 未加载
评论 #15973250 未加载