8 ms·
Building a shared vision for Async Rust
- davidhyde 6y ago> "the curse of knowledge: the folks working on Async Rust tend to be experts in Async Rust. We've gotten used to the workarounds required to be productive, and we know the little tips and tricks that can get you out of a jam" I like the format of the github Rustlings repo for exposing common beginner pitfalls and pointing developers in the right direction. For the uninitiated, Rustlings is a repo containing a collection of broken code examples that the developer has to fix along their journey to enlightenment. I feel that it would be beneficial to have an "Advanced Rustlings", say Rusteenager ;), for more advanced topics like tricky borrow checker situations and async rust. These examples would be similar to the PR's mentioned in the blog post but may get better exposure imo.
- claudiojulio 6y agoThis is bullshit because of this article:[https://theta.eu.org/2021/03/08/async-rust-2.html https://theta.eu.org/2021/03/08/async-rust-2.html]. Everyone is aware of the problems of async. What we need is solutions and not those stories to distract. We want profound changes. Automatically translated.
- steveklabnik 6y agoThis was pretty heavily discussed on the reddit when it was posted: https://www.reddit.com/r/rust/comments/m1t1lk/why_asynchronous_rust_doesnt_work/ https://www.reddit.com/r/rust/comments/m1t1lk/why_asynchrono... (And, as linked to in those comments, HN as well)
- dochtman 6y agoActually, the effort that started towards this blog post started weeks ago, easily several weeks before the blog post you're referencing.
- pornel 6y agoI like the approach that steps back and looks at usage scenarios. Not everything has to be solved by changing the language itself; it may be a matter of better tooling or teaching materials. For example, the recent "async doesn't work" blog post was centered around confusion between `fn()` pointer and `Fn()` trait, and misuse of temporary `&mut` where `Arc<Mutex>` was required. If the compiler was smart enough to suggest these fixes, then the whole blog post could have been "async works fine, just needed a couple of lines changed as indicated".
- wahern 6y agoThat wasn't confusion, that was the point. If there's confusion it's in people having different conceptions of what async language constructs should provide, which color their criticisms and rationales.
- scudd 6y agoIs there any thought to including a default executor in the standard library? I think it's kind of an obstacle for beginners when the language/stdlib provide all the tools to write async code, but not to run it. I saw discussed in this talk the intent in allowing developers to provide their own executor based on the specifics of their use case: https://youtu.be/NNwK5ZPAJCk?t=1107 https://youtu.be/NNwK5ZPAJCk?t=1107 This makes sense to me; however, I feel like the defacto at this point is that most people are using tokio. Is there a possibility that a default executor could be provided, and allow developers to override it with a custom library should they chose?
- steveklabnik 6y agoIt was suggested in a PR, which was then punted into RFC territory. I’m not aware of anyone actively pursuing an RFC at this time.
- andoriyu 6y agoCorrectly if I'm wrong, but IIRC low-level futures are very dependent on executor? I think you actually told me that, but that was back in futures 0.1 era.
- steveklabnik 6y ago“Leaf” futures often are, yes. This term (coming from like, a tree) is a tad more descriptive than “low level” IMHO. We have yet to achieve a fully agnostic solution everywhere. That’s part of what work in this area is trying to figure out, as I understand it.
- ibraheemdev 6y ago> That’s part of what work in this area is trying to figure out, as I understand it. Yes, there have been a couple of ideas floating around, and a couple of older RFCs that needed more revision, such as boat's `#[global_executor]`, and discussion about an extension to task::Context that would allow futures to interact with their environment (timers, etc). There is a lot of work going on in this area, but nothing concrete yet.
- Const-me 6y agoI admire the passion, but I’m not sure why I would want Rust at all, not just async. When I want memory safety, async-await, I/O performance, easy multithreading, I write C#. When I want performance of CPU bound code, or lots of integration with native libraries/APIs, I write C++. Sometimes I want both in the same software, compile C++ code into a DLL (or shared library on Linux), and consume it from C#. I don’t have experience with Rust in production software, but based on what I know and my limited experience with the language, it’s worse than the above combo. At least for the projects I usually work on. For pieces where performance doesn’t matter too much (often 70-80% of codebase), or for I/O heavy code, or for the stuff that’s in the standard library of .NET (serialization, compression, cryptography, xml, json, zip, etc.), C# is way easier to write and debug than Rust. Tooling is awesome. Even large projects build in seconds i.e. built/test cycle is really fast. For CPU bound or native interop-heavy pieces, C++ is also way easier than Rust. Intel and ARM only support their SIMD intrinsics for C. OS vendors only support their GPU APIs for C (most of them) or C++ (Direct3D). Many libraries I use are only available for C and/or C++. Using C++ for these pieces is the path of least resistance by a large margin, i.e. saves lots of development costs. The interop between the two adds some friction, but not too much, .NET was designed for easy native interop from the very first version. When I want to expose objects instead of [in addition to] just functions, there’re COM interfaces. At least in my experience, usability of C# brings way more profits compared to the losses from the interop across languages.
- whb07 6y agoDo you have any good resources on writing dlls to consume via .net like you’re talking about ? How do you deal with the managed memory when using the gc from .net
- Const-me 6y ago> Do you have any good resources on writing dlls to consume via .net like you’re talking about? For C APIs i.e. functions, structures and strings, the good resource is Microsoft documentation, the support is built-in, see “Consuming Unmanaged DLL Functions” section: https://docs.microsoft.com/en-us/dotnet/framework/interop/ https://docs.microsoft.com/en-us/dotnet/framework/interop/ For COM APIs i.e. sharing objects around see this library + demos: https://github.com/Const-me/ComLightInterop https://github.com/Const-me/ComLightInterop It’s only really needed on Linux because the desktop version of the framework has COM support already built-in, but it can be used for cross-platform things just fine, I tested that quite well i.e. not just with these simple demos. > How do you deal with the managed memory when using the gc from .net Most of the time, automatically. When you calling C++ from C#, the runtime automatically pins arguments like strings or arrays. Pinning means until the C++ function returns, .NET GC won’t touch these things. This doesn’t normally make any copies: C++ will receive raw pointers/native references to the .NET objects. Sometimes you do want to retain C# objects from C++ or vice versa i.e. keep them alive after the function/method returns. An idiomatic solution for these use cases is COM interop. IUnknown interface (a base interface for the rest of COM interfaces) allows to retain/release things across languages.
- Animats 6y agoThe main thing I want for Async Rust is the ability to not use it. What I'm doing involves a virtual world viewer with maybe a dozen threads. Some are compute bound. Some are talking to the GPU. Some are waiting for I/O. The normal situation is about 2 or 3 CPUs of work. Sometimes more. I don't want an async model, which assumes you're I/O bound, interfering with keeping all those CPUs busy. Already I've had to switch from using "reqwest", which now seems to always bring in tokio, to "ureq", a minimal HTTP client. The way to do HTTP requests used to be with "hyper", but that became a lower level for "reqwest", and then "tokio" was slipped in underneath to make it "async". It always uses async, even if you make a blocking request. "Async" is a specialized tool for web servers with very large numbers of clients. Outside of that niche, it's seldom needed.
- songqin 6y agoYour comment touches on a few misconceptions I see a lot. Firstly, `reqwest` exposes both an async and a synchronous API, allowing the developer to choose which one to use. They are largely interchangeable code-wise. [1] Secondarily, and more broadly, async is possible to opt out of. You must understand that most web and network related libraries will be async by default for performance, because people who write in Rust and people who write web servers typically care greatly about performance. This is the intersection of those two groups. That being said, there are options outside of that ecosystem. [2] If you truly want to use an asynchronous library without migrating your application to run entirely on an async runtime like tokio, you can run it inside of a synchronous function without much trouble. I've put together a playground link for you. [3] 1. https://docs.rs/reqwest/0.11.2/reqwest/blocking/index.html https://docs.rs/reqwest/0.11.2/reqwest/blocking/index.html 2. Iron: https://github.com/iron/iron https://github.com/iron/iron Rouille: https://github.com/tomaka/rouille https://github.com/tomaka/rouille 3. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=fac87a37c5d29b3342b41d7c8ed015d3 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- Animats 6y ago"reqwest" exposes a synchronous API, but it's doing async stuff underneath. If you turn on logging, you can see 30 or so async events associated with a single HTTP client side request. It's starting up and shutting down a polling thread just to make one HTTP client request. You must understand that most web and network related libraries will be async by default for "performance". That's what scares me - async contamination of the low level Rust ecosystem. The async enthusiasts have to be kept in check to prevent breaking Rust as a systems language.
- andrewflnr 6y ago> These stories are not fiction. They are an amalgamation of the real experiences of people This claim bothers me. It might be a nitpick, but I think it's an important one. For a given amalgamation, it is fiction in a non-trivial way that there was a person who literally had all the experiences in the blog posts or tweets etc. that inspired that character. Truth values of facts are almost always dependent on the relationship to other facts. It would be perfectly respectable to simply say that your user stories are rigorously based on real-world experience, which is a good idea BTW, without claiming that they are "nonfiction". That's a needless epistemological liability.
- scoutt 6y agoWe poor embedded developers are always forgotten :( Grace, the only C/C++ dev, does stuff like "Grace has already decided to use a thread-per-core model and minimize cross-thread communication".
- steveklabnik 6y agoIn what sense? Your opinions would be wanted here too!
- scoutt 6y agoDon't worry. I've just started to explore Rust (coming from 20 years of embedded C). I was just sad I didn't see bare-metal represented in the examples and status-quo stories.
- steveklabnik 6y agoAh. We took it into account when building async generally, but it hasn't gotten as much actual usage as folks doing networking, so that's probably why it was overlooked. I'll make sure to ping them about it though... I myself am very interested in this case :)