Show HN: Io_uring for Ruby
github.com
github.com
https://docs.ruby-lang.org/en/master/extension_rdoc.html#lab... sez:
“Ractor safety around C extensions has the following properties:
— By default, all C extensions are recognized as Ractor-unsafe.
— Ractor-unsafe C-methods may only be called from the main Ractor. If invoked by a non-main Ractor, then a Ractor::UnsafeError is raised.
— If an extension desires to be marked as Ractor-safe the extension should call rb_ext_ractor_safe(true) at the Init_ function for the extension, and all defined methods will be marked as Ractor-safe.”
I don't know enough about io_uring to know if there would be any thread-safety issues to just declaring it, but here's an example pull request from a few years ago enabling Ractor support on a C extension that had no sharing issues: https://github.com/dearblue/ruby-extattr/pull/1/
Ior doesn't contain the multishot stuff because it didn't exist when I still added stuff to it, but apart from that it do include a whole lot of ops.
Of course, the main argument against it is that you require access to the underlying fds, which most libraries in the ecosystem abstract you away from, so there's no way to use p.ex. net-http with this (without some serious patching and low-lever ivars access). That makes its application limited.
Nevertheless, it's very interesting, thx for sharing. I'm of the opinion that it's about time ruby ships a default performant fiber scheduler
If you then process your requests in the slowest programming language, you add back at least 100x the overhead.
It doesn’t make sense to me.
If the difference between IO uring and epoll is 2x, but that was only 5% of the total runtime, the rest being slow Ruby code, then at best you get a 2.5% speed up. Not worth it.
Using flags to shut down entirely reasonable discussion is very lame.
In addition, the blog post measures the cost of avoiding doing the interop, which allows wins as the compiler improves in the case of short-lived calls implemented in a native component.
This, however, is not exclusive to Ruby and statically typed JIT or AOT compiled languages benefit from this to a much higher extent.
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
I remember when these claims were made for Java twenty years ago. It’s still slower than C, most of the time.
Some things don’t change.
Of course, I don’t see why that won’t perform fine for Ruby.
It’s just so slow that optimizing the async IO at the OS level doesn’t matter
In fact, the whole idea for this library is to provide a low-level, fast, flexible, asynchronous I/O layer for building Ruby apps and letting Ruby+YJIT optimize the app code, which it actually is getting pretty good at.
If you're open to learning more about where the Ruby runtime is performance-wise, there was a very interesting recent talk [1] about this very subject.
[0] https://github.com/digital-fabric/iou/blob/main/examples/htt... [1] https://www.youtube.com/watch?v=qf5V02QNMnA
The "performance" of the language is going to have approximately zero effect once a request has to schlep over to the database in a 7ms round-trip.
There's a wide field of applications where language performance has approximately zero effect on application performance. I have 15ms of latency, what do I care if your web app is written in Rust?