154 points · by nathansizemore · 10y ago · 46 comments
Why not Hyper?
Why not Mio?
Don't misunderstand, I'm all for competing implementations. I just feel like it would be helpful to lay out a comparison for everyone else's understanding/decision making process.
Well, hyper is a lib for dealing with the HTTP protocol. If being cross platform did not matter, hyper could be build atop of this.
I did not go the route of mio because I wanted to learn the entire process of working with epoll by doing it myself. I've learned a lot, and would not have that knowledge if I just built atop of mio. Mio must also provide a unified abstraction across platforms, where I was free to experiment and change at will during the building process.
Why not EventMachine? / Why not Celluloid?
Why not Twisted? / Why not gevent?
This is a really sad situation unfortunately. I was hoping Rust wouldn't head down this road.
To preempt: a systems language shouldn't dictate these high-level matters, but there certainly should be one "blessed solution" vs. a sea of incompatible libraries.
Go doesn't have this problem, Node.js doesn't have this problem, Elixir doesn't have this problem. Sad deal.
But you cited a whole bunch of languages that do dictate this. Those languages don't have those problems because you can't write competing implementations of low-level async I/O in those languages.
And there certainly are competing, incompatible implementations of relatively low-level functionality in Golang, for example fasthttp: https://github.com/valyala/fasthttp
I'm all for standardizing on one solution when the time comes. Rust will have an async I/O story. But right now nothing is mature enough yet to begin that process. Rushing to standardize something that is not yet ready is the worst of all possible options.
I don't believe the language needs to dictate something. It might help, sure, but there's no reason that is a requirement.
For the sake of compatibility, a blessed option should be offered.
The AIO situation today in Rust looks identical to Ruby, Python, and C++.
I wanted to use Rust and learn epoll through working with it directly.
> I was hoping Rust wouldn't head down this road.
To my knowledge, Rust does not have a std async story. I hope it will, and I believe libs like mio will help flush out platform agnostic ideas and a tested API.
> To preempt: a systems language shouldn't dictate these high-level matters
All of your cited example languages are _not_ systems language? Node.js isn't even a language? It could be listed above with the rest of your async I/O options across several languages.
The send API lets me wonder how it copes when the socket only allows to send half a frame and then returns EAGAIN/WOULDBLOCK? There is not a number of bytes that were really sent returned, and the ownership of the data to send was given up, so it can't be retried later on.
On the receiving side it looks like the framework is allocating the memory and then pushing the received bytes instead of the user allocating the memory and fetching it (after readiness notification). That gives up some potential for memory reuse.
So, the framework itself does not implement any of that, it is on the consumer. It just calls the proper methods on the trait object provided.
https://nathansizemore.github.io/hydrogen/hydrogen/trait.Str...
In the README example, I'm using it combined with another streaming crate I made, which does provide all of the internal buffering and state management for non-blocking I/O.
Hydrogen: advanced drum machine for GNU/Linux
And a very good one, with a long road in the back.Just kidding, I'd also welcome if more projects came up with sensible names that hint at what the program/library does.
It's happened way too many times to me that I saw a cool project with a generic name, and wanted to use it at a later time to make my own cool stuff. Of course, I'm then unable to look it up because the names get all mixed up, and I only rediscover it a few months later when it gets posted on HN again.
We especially like the way that Rust code is simultaneously high-level, strongly-typed and fast. The code feels "crisp", and if the compiler doesn't return any errors, the program will almost always work correctly on the first try. The code refactors easily. Plus the tooling (cargo, unit testing, etc.) is well thought out. And we like the ability to build static binaries against musl-libc and copy them into an Alpine Linux container.
I would happily use Rust again, at least if I wanted C++-level performance and most of the right libraries were already available for a given task. (I can find most basic, useful libraries on crates.io, but if I'm looking for something like an HTTP proxy server using async I/O, I may not necessarily find a mature implementation yet.)
mio is a crate that offers more platform agnostic async I/O.
Reinventing c/cpp? ಠ_ಠ
String literals are an interesting case for the reason mentioned in the earlier comment: they reference memory that no code "owns", as in-place mutation of the executable would be unsafe.
Some languages have mutable strings but these are usually unsafe if used concurrently, or require locks. In Rust this is modeled in the type/borrow system.