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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Async Ruby

305 点作者 brunosutic超过 3 年前

16 条评论

BMorearty超过 3 年前
This gem had a huge impact in May of this year on one of Airbnb’s Ruby services. Last year when I was still at Airbnb I did the research and foundational work to make Airbnb’s HTTP client gem compatible with the Async gem and Falcon server. I’m no longer there but this year, one of my friends who’s still at Airbnb put that work to use on Airbnb’s Ruby service that talks to a Genesys API.<p>Most Genesys API calls have reasonable response times but there are these occasional, weird, unpredictable 30-second response times. The slow responses can come in bursts, where you can a bunch of them at once. This makes it extremely hard to predictably scale the Ruby service that calls it, because in normal synchronous mode, every thread that calls Genesys is blocked and on longer available to take more client requests. You could scale up the service to assume these 30-second response times will happen all the time, but then you’ve got huge server costs just for the 1% case.<p>But using Async and Falcon (an Async-compatible HTTP server), Airbnb was able to safely scale down the service by around 85% and turn on autoscaling, and it’s working <i>beautifully</i>.
评论 #29053016 未加载
sizediterable超过 3 年前
&gt; any blocking operation (a method where Ruby interpreter waits) is compatible with Async and will work asynchronously within Async code block with Ruby 3.0 and later.<p>That&#x27;s pretty magical. Does this mean it would be possible to implement structured concurrency [0], but without the function coloring problem?<p>Regardless, I think I prefer how this looks from a code read&#x2F;writeability perspective compared to Zig&#x27;s or Swift&#x27;s (and potentially future Rust&#x27;s [2]) approaches.<p>[0] <a href="https:&#x2F;&#x2F;vorpus.org&#x2F;blog&#x2F;notes-on-structured-concurrency-or-go-statement-considered-harmful" rel="nofollow">https:&#x2F;&#x2F;vorpus.org&#x2F;blog&#x2F;notes-on-structured-concurrency-or-g...</a><p>[1] <a href="https:&#x2F;&#x2F;kristoff.it&#x2F;blog&#x2F;zig-colorblind-async-await&#x2F;" rel="nofollow">https:&#x2F;&#x2F;kristoff.it&#x2F;blog&#x2F;zig-colorblind-async-await&#x2F;</a><p>[2] <a href="https:&#x2F;&#x2F;blog.yoshuawuyts.com&#x2F;async-overloading&#x2F;" rel="nofollow">https:&#x2F;&#x2F;blog.yoshuawuyts.com&#x2F;async-overloading&#x2F;</a>
评论 #29050552 未加载
评论 #29051547 未加载
评论 #29051786 未加载
评论 #29060245 未加载
midrus超过 3 年前
I stopped using python long ago, out of the frustration with the breakage caused in the ecosystem first due to the 2&#x2F;3 transition, and then by splitting again the ecosystem with all the async stuff they introduced, when having instead gone the way of gevent would have ended up in something like this.<p>The company I was at the time tried really hard to move to python 3. It was a huge codebase with thousands of engineers. After more than a year of work they cancelled the project and said they&#x27;ll never upgrade to python 3, and instead started writing smaller &quot;microservices&quot; around the core product just to calm engineers anxiety to use python3. Now Django is suffering kind of the same problem with all the async stuff being bolted on, adding a lot of gotchas and side effects and incompatibilities around every corner. It is a mess.<p>I left that company and I will never use python again.<p>I love how Ruby seems to care about the ecosystem, and both ruby and rails keep innovating and providing awesome full stack solutions.
评论 #29055004 未加载
评论 #29054904 未加载
Toutouxc超过 3 年前
There may be some huge piece I&#x27;m missing, but how exactly is the &quot;starting multiple async tasks wrapped in blocks and waiting for them to finish at the end of the main Async block&quot; different from &quot;starting multiple threads wrapped in blocks and manually collecting them at some point&quot;? I thought Ruby did release the GIL when a thread is blocked (waiting for IO etc).
评论 #29054617 未加载
评论 #29050618 未加载
评论 #29051639 未加载
评论 #29162818 未加载
评论 #29050644 未加载
评论 #29050577 未加载
评论 #29050996 未加载
veesahni超过 3 年前
Does Falcon + Async allow a second request to be processed while the first is blocked on a network call?<p>For example:<p>* HTTP request 1 requires information for which we can&#x27;t respond immediately.. so we hold the connection open and respond in a few seconds.<p>* Can HTTP request 2 come in at the same time?<p>EventMachine enabled the above with what they called &quot;streaming responses&quot;
评论 #29051675 未加载
评论 #29051321 未加载
评论 #29053554 未加载
continuational超过 3 年前
That seems kinda verbose to use. It&#x27;s also a bit suspicious that all the examples discard the results; is it hard to get the results back out?
评论 #29051051 未加载
评论 #29051219 未加载
评论 #29052274 未加载
jasonhansel超过 3 年前
No function colors! Is this like Go, where each fiber maintains a separate stack at runtime, or is this like Rust, where each task is effectively transformed into a state machine?
评论 #29053431 未加载
claudiug超过 3 年前
another cool ruby library for async is <a href="https:&#x2F;&#x2F;github.com&#x2F;digital-fabric&#x2F;polyphony" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;digital-fabric&#x2F;polyphony</a>
评论 #29050968 未加载
评论 #29051443 未加载
rememberlenny超过 3 年前
This seems huge.<p>Does anyone know plans around how this will be implemented into Rails?
评论 #29050481 未加载
评论 #29051668 未加载
评论 #29050446 未加载
评论 #29050882 未加载
评论 #29050476 未加载
jmarchello超过 3 年前
I can&#x27;t wait to play with this! Having worked with Python&#x27;s Asyncio a lot, this looks SO MUCH easier to work with.
matheusmoreira超过 3 年前
&gt; you can think of it as &quot;threads with none of the downsides&quot;<p>And likely no actual parallel execution of Ruby code. I suppose fibers are scheduled for later when they perform I&#x2F;O. Just like how C extensions release the interpreter lock before some expensive function, allowing other Ruby code to run in concurrently.
评论 #29052697 未加载
评论 #29147053 未加载
michauu超过 3 年前
Could anyone comment on the thread safety? What&#x27;s shared between async blocks and what&#x27;s safe to modify?
评论 #29052883 未加载
pinzonjulian超过 3 年前
Great article! I was wondering if you could add an extra section on why Async will make the @counter error go away. I&#x27;m new to Async and Threads in general and the rest of the article was super easy to follow but I didn&#x27;t quite understand why or how that error would disappear.
pinzonjulian超过 3 年前
Great article!<p>I was wondering if you could add an extra section on why Async will make the @counter error go away. I&#x27;m new to Async and Threads in general and the rest of the article was super easy to follow but I didn&#x27;t quite understand why or how that error would disappear.
faebi超过 3 年前
How will this deal with temporary CPU starvation in long running connections? I am currently using concurrent-ruby&#x27;s thread pool to run a few hundred Net-SSH Connections per process at the same time. This helped me to avoid most of these kind of issues.
Mikeb85超过 3 年前
This gem is almost a decade old (although looks like it&#x27;s been updated to work with fibers?). There&#x27;s a bunch of gems that allow for asynchronous&#x2F;concurrent and&#x2F;or parallel execution for Ruby. It looks like a nice enough gem but it&#x27;s not particularly novel. Seems like it&#x27;s just trying to ride JS&#x27; popularity with the name. Ruby threads also allow for non-blocking operations.<p>Edit - this isn&#x27;t some new paradigm for Ruby. It&#x27;s a gem... A bunch of others (&quot;Parallel&quot;, &quot;Concurrent-Ruby&quot;, &quot;Eventmachine&quot;, etc...) have been around forever and do similar things.<p>Edit2 - <a href="https:&#x2F;&#x2F;rubygems.org&#x2F;gems&#x2F;async" rel="nofollow">https:&#x2F;&#x2F;rubygems.org&#x2F;gems&#x2F;async</a>
评论 #29050669 未加载
评论 #29052061 未加载