by the__alchemist · 4y ago · 0 comments
Is the Async crew mostly writing web servers and other things that operate using TCP and HTTP? Lower level (eg IP, Eth, network hardware drivers) isn't well supported by rust libs. Nor is higher - we have Flask analogs, but no Django analogs.
As Async ingresses in Embedded Rust, I seek answers to "is this worth the viral qualities, and API rift?".
For the adjacent question re generics by default, I ask "Is the flexibility and type checking worth the API complexity, and documentation dead-ends?"
Does anyone here use Async Rust in domains outside those sections of network and web programming?
I've found rust to be a great fit as a cleaner, more explicit C alternative.
Example: I have some stuff in my hobby application that is executing in a WASM virtual machine. That's not async, simple and synchronous.
But I have two other parts: one that talks to FoundationDB, and another that receives websocket connections. Both use Tokio & Async.
Now I'm in a pickle every time I want to hold or pass around some state in my WASM pieces, because the async stuff ends up pushing its constraints all the way down. Want some piece of mutability? Some piece that doesn't Send or Copy? Good luck.
There's ways around it all, but it complicates the design. The 'async' pieces at the front end up propagating all the way down.
It's hard to explain fully without you being in my code, but suffice it to say, I agree with others: async in Rust is half-baked. That should be evident enough simply from the fact that you can't even yet put async functions in traits.
I find the compiler reminding me constantly that I can't. I don't worry much about the viral nature of async, but this annoys me so much.
Something I have never understood is why people want to write web-apps in Rust. I love the language, but honestly, a managed language (like js/ruby/go) is always going to be better suited to the world of web-apps.
I feel like this imposes an undue burden on Rust to do everything for everyone which has to break down somewhere
For a relatively simple web server, where I don’t need to collaborate with anyone, I’m choosing Rust.
Given that I've been programming professionally for over a decade in Python, Perl, Ruby, C, C++, Javascript, Java, and Rust, I'll pick Rust absolutely any time that I want something running that I won't get called at 3 AM to fix. It probably took me 5 times as long to write it as if I did it in Go or Python, but I guarantee it's saved me 10 times as much time I would have otherwise spent triaging, debugging, and running disaster recovery.
But Rust is a better option when you also need one or more of the following:
a) tight control over allocations
b) deterministic performance
c) strong data race protection
d) zero overhead C interop (e.g., processing audio using ffmpeg)
The vast, vast majority of web apps are the same CRUD endpoints and background job queue processing. I would label Rust as mature enough in this regard; I've written quite a few of these and am not left wanting in any regard (short of a clone of Django's automagic admin, but few things get close to this anyway...).
When you accept the fact that you're taking in some data, shoving it into the DB, and returning a response, the rest of the Rust ecosystem becomes pretty damn nice - deployment is an absolute breeze compared to some of the other ecosystems (Ruby/Python). I don't need to mess with Docker, I don't need to deal with broken package managers, I can just replace a binary and call restart.
It's amazing.
- High-level DB migrations
- Auth
- Email
- Admin
- Templating
You get these immediately with eg Django, but not in Rust. I'm not trying to be contrarian; I'm confused, and have never heard an answer about this point.https://github.com/secretkeysio/jelly-actix-web-starter
I put all of this together some time ago, explicitly modeled after Django. This repo isn't up to date with actix-web 4 as I've been too busy with other (paying) work, but it absolutely exists. I've used this for services in production with no issues. I really do need to get time to finish and push the updates though.
Mine isn't even the first, I'm pretty sure there are others working in this space. Just needs the right people pushing it.
> High-level DB migrations
Having used Datadude[1] I can say for certain that there are few approaches worse than migrations. The problem is that, once you are stuck with a turn-key framework, you are completely stuck with their approach (which is usually horribly archaic).
Unbundling all of these things might require more work up-front, but can result in significantly improved productivity in the long run.
[1]: https://www.sqlshack.com/working-with-database-projects/
[0] https://cloak.software/blog/rust-on-nails/
[1] https://github.com/tokio-rs/axum/blob/main/ECOSYSTEM.md#proj...
Just recently I had a need for a fairly simple webapp. Whipped up the back end in Rust in, like, an hour; only had to bolt on a couple tests for the single complex bit of business logic, because I have a high degree of confidence that the compiler has me covered for everything else.
Now it sits there quietly using 4.9 MiB of physical memory and 1.5 millicores on two of my servers, primarily serving a k8s healthcheck every couple seconds.
Everything else you mentioned is out there, although I didn't love the websocket experience the one time I needed them for something.
I ended up writing something that faced external clients in rust, that had to do traditional web app things, and it was okay. The pros were that you could write idiomatic interfaces to things like auth that wouldn’t look out of place in a Django app. The cons however, was that writing these Interfaces took some non trivial rust knowledge, especially since we did a lot of async rust.
The main thing I'm finding an issue with Rust so far are things that I could find packages for in Go. The main one is having an oidc helper library that can take various oidc services (github, twitter, etc), and provide me a standardised 'account'.
Apart from that, I'm finding the experience nicer overall. Examples:
* I have better/easier control over errors in ways that don't clutter up the readability of my handlers. I can easily define global rules about how errors from different systems (database, IO, etc) should be returned to the client.
* Compile time checks for things that would fail at runtime in Go, and therefore require more extensive tests base to catch when refactoring --sqlx and askama are examples enabling this (askama is particularly nice for this -- more work to get things to the stage of compiling)
* When it finally compiles, it usually just works, due to aforementioned fewer ways for failure at runtime
* Can express/encode some functionality much more succinctly than Go
* Macros for auto-generating code (though I haven't needed this in Rust yet), where with Go I'd make a small external tool for auto generating code. I use generated code a lot in Go, and even with the new 1.18 release, I see that continuing.
With more time for the ecosystem to grow, I can see Rust being just as useful. Apart from the ecosystem and the nice fact that you don't need .await's in Go, I can see Rust being really good for this sort of thing.
At the web level the biggest pain I have is the dev workflow isn’t as nice as the Jamstacks with hot reloading so you can see visual changes immediately in the browser. If doing backend for front end this pain goes away if front end is some NodeJs / php or other app.
Why is my preference now Rust? It’s fast and low on system resources. It means I can run my apps at a fraction of the cost compared to other languages. I can package my app in a Docker container that’s single digit MB’s. It’s not that to low level to be an inconvenience and high enough level to be reasonably productive. Being strongly typed and being able to find bugs with the compiler also helps.
https://www.techempower.com/benchmarks/#section=data-r20&hw=...
What do you mean?