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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

A Visual Journey Through Async Rust

151 点作者 PaulHoule29 天前

8 条评论

OskarS29 天前
Very neat visualizations! Really good way to demonstrate the underlying principles. Great article.<p>I will add one thing: the author makes much of how problematic CPU-intensive tasks are. That&#x27;s true, but also: if you need to do a CPU-intensive operation, you need to tie up a CPU to do it, there&#x27;s no getting around it. What you might want to do is break the computation up in to smaller chunks with `.await`s sprinkled in there or dispatch it to a background thread, but at some point you have to pay the cost in CPU time.<p>What is much more problematic is blocking I&#x2F;O operations. That also ties up a CPU and blocks the event loop, but for no good reason. All the CPU is going to be doing is sleeping waiting for the network or hard-drives or whatever it is to do it&#x27;s work, when it could be doing other useful things, processing other events. That kind of thing leads to huge under-utilization of your resources, and it kills your concurrency.<p>This means you really can&#x27;t mix async I&#x2F;O with blocking I&#x2F;O: if you go async, ALL your I&#x2F;O operations need to be async. Or you have to do it off the event loop in a background thread or something, but then you&#x27;re losing all the benefits of using async in the first place.
评论 #43794068 未加载
评论 #43793214 未加载
inglor29 天前
&gt; Unlike Node.js, Rust&#x27;s Tokio allows us to spawn a new Task and run futures within it.<p>Nice article! For future reference in Node.js this would be `worker_threads` or if you want a higher level tokio like API something like <a href="https:&#x2F;&#x2F;piscinajs.dev&#x2F;" rel="nofollow">https:&#x2F;&#x2F;piscinajs.dev&#x2F;</a><p>This has been possible in Node.js for quite a while<p>--<p>Also for blocking I&#x2F;O CPU bound parallelism I&#x27;ve found Rayon to be a pleasure. It has a few caveats but it leverages the Rust race condition checking well and it&#x27;s very ergonomic.<p>I happily mix it with `tokio` in an application that is CPU bound but has to perform some async I&#x2F;O (due to the SDKs it uses)
评论 #43793186 未加载
评论 #43796558 未加载
vermilingua29 天前
It’s never addressed in the article that the calculations running on spawned threads produce deformed sine curves. Is that just a result of how its plotted or do tokio threads have less accurate track of time?
评论 #43793204 未加载
评论 #43794364 未加载
评论 #43794731 未加载
binary13229 天前
This is not limited only to Rust and I&#x27;d be very curious to see a similar comparison across multiple runtimes!
jdnier29 天前
&gt; Alright! We managed to plot two sine waves in the most convoluted method ever!<p>Those sine waves start to resemble a multi-voice music score. You might get some interesting pitch variability depending on other processes that are running.
jwufasdfsds29 天前
The async disaster can be avoided by using Plan9 or Inferno.<p>Don&#x27;t misinterpret this as criticism of async-rust. It&#x27;s required to work on legacy platforms like linux.
评论 #43794018 未加载
rc0029 天前
Shared 12 days ago: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=43675098">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=43675098</a>
ModernMech29 天前
&quot;Visualizing futures runtime like this really makes some pennies drop.&quot;<p>What&#x27;s it mean to drop pennies?
评论 #43794551 未加载