10 ms·
The Safety Boat: Kubernetes and Rust
- shock 7y ago> One of the biggest ones to point out is that async runtimes are still a bit unclear. There are currently two different options to choose from, each of them with their own tradeoffs and problems. Also, many of the implementation details are tied to specific runtimes, meaning that if you have a dependency that uses one runtime over another, you’ll often be locked into that runtime choice. My understanding of how async/await works in Rust is that you can have multiple async runtimes in one Rust program. Is that not the case?
- roblabla 7y agoThat is the case, but it's super awkward to use. Basically, you cannot await a tokio future on an async-std runtime, or an async-std future on a tokio runtime. You can, however, have both runtimes running at the same time, and use some form of message-passing to bridge them. It's definitely easier to only deal with one runtime. Ideally, we should have some kind of abstraction to allow crates to support both runtimes (e.g. a trait that'd allow creating an async TcpSocket of the right "kind" for your runtime), but AFAIK this is not currently done.
- steveklabnik 7y ago> AFAIK this is not currently done. That's correct; we're still working on these abstractions. It's the end goal that most folks have in mind, though.
- jeffdavis 7y agoCan you explain and/or link to the issues? I thought Futures were the abstraction that lets you choose a runtime?
- Rusky 7y agoFutures are part of the answer, and more specifically the way that the Wakers passed to Future::poll use dynamic dispatch to re-schedule the task. Other major abstractions that are missing so far include async versions of the Read and Write traits, a Stream trait for the async equivalent of the Iterator trait, and perhaps a way to spawn new tasks. This series of interviews covers these in more depth: http://smallcultfollowing.com/babysteps/blog/2020/04/30/async-interviews-my-take-thus-far/ http://smallcultfollowing.com/babysteps/blog/2020/04/30/asyn...
- empath75 7y agoI was looking at smol and it seems to have a good pattern for working with all the other run times.
- deleted 7y ago[deleted]
- Matthias247 7y ago> That is the case, but it's super awkward to use. That's really the case for any language where an eventloop is not part of a builtin runtime (like it e.g. is with Javascript or Dart). E.g. in C++ we also have boost asio, libuv, libevent, wagle, seastar,GUI framework eventloops in GTK, QT, etc. The thing is once you are in async land, nothing is interoperable anymore in most environments. Whether that's ideal or not is a separate discussion. What I experience however somehow is that Rust users raise a lot more concerns about interoperability than I've seen so far in other ecosystems. I might stem from the fact that those users often never used another native async environment.
- wwright 7y agoIMO it’s more that the Rust community has fostered a culture of doing things carefully and doing them well whenever possible (I mean, it’s the language that will argue with you for hours over reference lifetimes, after all).
- Matthias247 7y agoThere are certainly high expectations in the Rust community about doing things perfectly. But I don't think those "async ecosystem" discussions are a good example of productive discussions. I think e.g. in C++ there had been far more expert talk on standarization, within expert groups - like for the standarization of executors or the networking TS. And yet after 5 years or so nothing had been standardized yet. In Rust the amount of people that actually work on the low level details and try to make things better is likely < 5. But there are a lot of expectations from everyone else about having perfect interoperability.
- xrd 7y agoDoes anyone here have any experience using Kotlin and can compare concurrency (with coroutines) to either Go or Rust? When I was doing more Java I really liked the approach Kotlin took with concurrency, but reading the comments here I'm sure I didn't understand the issues at the depth that is needed.
- gas9S9zw3P9c 7y agoIn theory you can, but in practice it would make your code very messy. If your dependency is using runtime A and you are using runtime B - how would they interact? Runtimes like tokio also provide convenience macros for you main mehtod, kind of locking you into them (I think), at least for that codepath. If your application has two parts or binaries that are completely separate you could potentially use two different runtimes, but otherwise I don't think it would make sense. And even then, it would just be a mess. Right now, your runtime is essentially picked for you by your dependencies.
- Rusky 7y agoIt's possible, the downsides are a bit silly when you look at how the Future trait was designed to allow tasks to be runtime-agnostic. There is ongoing work to standardize more runtime interfaces so that more libraries can be runtime-agnostic.
- mappu 7y agoGoing off on a tangent, but this exact problem would be a worst-case scenario for Go getting user-defined generic types instead of only the current blessed ones. t. C++ developer with a mixed std::string/QString/BSTR codebase.
- comex 7y agoBut strings are not generic types...
- zxcmx 7y agoSo much this. Have seen apps where there were 4 diff string types brought by external dependencies and then like 3 or 4 more to deal with from diff Windows APIs.
- monocasa 7y agoWell, that's the current state of Go if the half dozen blessed versions don't fit your use case. Everyone just writes their own slightly incompatible versions.
- adev_ 7y ago> t. C++ developer with a mixed std::string/QString/BSTR codebase. This has absolutely nothing to do with generics. None of std::string or QString are generics. They are just an example of historical alternative implementations for 'reasons' ( portability/speed) that create a lesson the long term
- slavik81 7y agoIt's also unavoidable. It's not like you can pass UTF-8 Go strings to UTF-16 COM interfaces. Somebody wrote code to convert a Go string to a BSTR and vice versa. You can do the exact same thing for std::string if you want.
- conroy 7y agoI looked into WASM / WASI last week but couldn't find an answer to this anywhere: can I write a network service in Rust and compile it to WASM / WASI? I know that wasmtime can execute a WASM module and give it access to a file system. Can that filesystem contain a socket that the WASM module can interact with?
- empath75 7y agohttps://wascc.dev/ https://wascc.dev/ Has done some work there.
- mappu 7y agoYou could speak FastCGI (or plain HTTP) over stdin/stdout, although that won't get you accept(2) semantics without some other kind of layering.
- whb07 7y agoThere’s a version of NGINX that’s compiled to WASM. Conceivably you could compile all of the CPython runtime into WASM, just that you’d be left with a big binary that gets passed around all the time over the wire.
- jononor 7y agoVery curious as to why you would want to do that? If you want a network service, WASM does not seem to help with much, only complicate things?
- zozbot234 7y agoIt's a bit weird to see "several weeks" of effort being described as a problematic learning curve. At least the blogpost makes it clear that the effort pays out hugely but still, "several weeks" is not rocket surgery. It's not learning Haskell or category theory! ISTM that they're just running with an assumption that most devs wouldn't be professional and committed to this, which strikes me as an unwitting gatekeeping attitude.
- ashtonkem 7y agoLearning a new framework in a familiar language might take a few weeks. A few weeks for a new language is really fast!
- alvarelle 7y agoBut with rust you have to re-learn the language every six weeks as it changes so fast. (/s)
- steveklabnik 7y agoGo has a shorter time, and that’s the measuring stick in this area.
- wrs 7y agoGo appears to have a shorter time, because you don't realize how much higher-level stuff you're just expected to do The Right Way, with no support from the language or libraries. So you're free to think you've finished learning Go, but then the actual learning begins.
- rvz 7y ago> For comparison, last week we caught a significant race condition in another Kubernetes-related project we maintain called Helm (written in Go) that has been there for a year or more, and which passed the race checker for Go. That error would never have escaped the Rust compiler, preventing the bug from ever existing in the first place While the possible security benefits of Rust is interesting in software like Kubernetes, it seems like this whole blog-post is an implicit RIIR proposal for the Kubernetes ecosystem from a Microsoft software engineer which isn’t going to happen anytime soon. > Rust has made great progress in the past year with its async story, but there are still some issues that are being worked out. On top of that, there are still many crates that aren’t using async-await yet and most are not even 1.0, thus are not stable. I would not touch such crates if they are still immature or even unsafe. Realistically, a Rust Kubernetes is possible but practically the effort of a production ready version is measured in years.
- steveklabnik 7y agoKubernetes is an ecosystem. It doesn’t need to be written in Rust for Rust components to play a part. Helm is not Kubernetes, for example, though your comment seems to blur the two. There are folks writing stuff to interact with the broader ecosystem in Rust. That’s one of the interesting bits of networked systems! You can be heterogeneous with languages more easily when the network/api is the boundary.
- dilyevsky 7y agoDoesn’t microsoft own helm now? Nothing is stopping them rewriting it in rust since it can easily interact with kubernetes via rest api
- Thaxll 7y agoI don't believe for one second that it takes just a couple of weeks to an average SE to be proficient in Rust.
- steveklabnik 7y agoIt really depends on so many factors it’s extremely hard to tell. We’ve brought folks at Cloudflare up to speed roughly that fast. “average” and “proficient” are both very variable in that statement, imho.
- sitkack 7y agoThey started with >1 Klabnik units and every person you bring up, it creates a larger pool of folks to lean on for support.
- steveklabnik 7y agoI can’t take credit here, while I am around to answer questions, getting folks going is not my job. It is true that we have a chat room with a bunch of folks, of which I’m part.
- e12e 7y agoI wouldn't discount what gp is saying though - having an (or a few) experts on hand from the start, can help training the first new convert "the right way" and they can then mentor the next one and so on. Even just by being availabletto answer questions or help with code review. Doing some pair programming sessions would probably be useful too.
- steveklabnik 7y agoOh yeah, it’s helpful for sure. I just don’t want to take too much credit!
- amrx101 7y ago
- melling 7y ago“For comparison, last week we caught a significant race condition in another Kubernetes-related project we maintain called Helm (written in Go) that has been there for a year or more, and which passed the race checker for Go. That error would never have escaped the Rust compiler, preventing the bug from ever existing in the first place.” I’ve heard people brag that Haskell is a great language because it’s supposedly easier to write correct code. Rust has this same reputation?
- tybit 7y agoYes, though I believe Rust has already proven this more in practice than Haskell has. Rust has many advocates now at places like Mozilla, Amazon and Microsoft that have delivered critical software in Rust that they believe has made it safer.
- yongjik 7y agoI think the common saying is that once your Haskell code compiles, it's usually correct. The fine print is that nobody claimed it's easy to write Haskell code that compiles.
- sitkack 7y agohttps://youtu.be/DdR9q69se-I?t=1329 https://youtu.be/DdR9q69se-I?t=1329
- Falell 7y agoYes. The common blurb is: In safe rust the borrow checker encourages 'fearless concurrency' by statically preventing all data races.
- exdsq 7y agoIt’s harder to formally prove Rust code compared to Haskell, the company I work at prototyped in Rust and then used domain information gained to improve the parallel implementation in Haskell.
- lmm 7y agoYes, for much the same reasons. Pretty much any ML-family language has the same effect; just having proper sum types, polymorphism and first class functions (and not having null) goes a long way to preventing huge classes of bugs.
- boulos 7y agoThe bug they caught [1] is one of the reasons some languages require you to explicitly name your captured variables. You still could have typed that code in, especially if you started with a for loop and then made it parallel (fwiw, perform should have been named something clearly suggesting it was parallel), but you'd at least be confronted with "oh, you went from serial, local state to a capture. Still think it's okay to explicitly borrow that state from this scope?". Then again, that's the point of Rust here :). Fwiw, it's too bad the commit message didn't say something like "Since we're doing delete on many resources in parallel, we need to hold a lock while updating errs/res.Deleted". The reviewer was also obviously confused at first. [1] https://github.com/helm/helm/pull/7820/commits/edb2b7511bcb9dc3c03bad3da1099b7ebffefd0b https://github.com/helm/helm/pull/7820/commits/edb2b7511bcb9...
- ronlobo 7y agoIt is exciting to see Microsoft is pushing so many efforts into Rust and WASM. The Rust onboarding experience is incredibly explicit and once things start to click and code compiles, you're on the train.
- ernado 7y ago> we caught a significant race condition It is a data race, not a race condition. > and which passed the race checker for Go No, it is not. https://github.com/helm/helm/pull/7820#issuecomment-604360627 https://github.com/helm/helm/pull/7820#issuecomment-60436062... There is a comment by issue author which is literally a go data race detector warning. Like "WARNING: DATA RACE".
- gtkspert 7y agoAlso, to be clear, by “we” they really mean “a contributor”
- Rusky 7y agoData races are a kind of race condition, no?
- sa46 7y agoI wasn't sure. After a bit of research, this seems to be a debate [1]. Using the common definitions, it's possible to have a data race that doesn't cause a race condition. [2] It's also possible to have a race condition without a data race. [1] https://en.wikipedia.org/wiki/Race_condition#Data_race https://en.wikipedia.org/wiki/Race_condition#Data_race [2] https://blog.regehr.org/archives/490 https://blog.regehr.org/archives/490
- Rusky 7y agoI would argue that "a data race that doesn't cause a race condition" is still, itself, a tiny race condition- just a contained one. But you're right, this is just choice of terminology. :)
- jrockway 7y agoI can convince myself that data races need not be a race condition. Consider this simple program: var i int doneCh := make(chan struct{}) go func() { i = 1; doneCh <- struct{}{} }() // a go func() { i = 1; doneCh <- struct{}{} }() // b <-doneCh <-doneCh At the end of the program, i is always equal to 1 no matter which order a or b wrote to i. But it's a race because you are assigning to a shared variable without synchronization. A small modification to the program creates a race condition: var i int doneCh := make(chan struct{}) go func() { i = 1; doneCh <- struct{}{} }() // a go func() { i = 2; doneCh <- struct{}{} }() // b <-doneCh <-doneCh Is i 1 or 2? It depends. It is correct for the race checker to complain about the first program, because after a bit of hacking the first program can very easily change into the second program. (And I tried it, and it does complain.)
- xrd 7y agoAfter reading this article, I'm excited about finding a reason to write a component in Rust and WASM. Can anyone recommended the best getting started guide for dipping your toes in the water? This article didn't have a link to anything that seemed appropriate for that goal.
- Klasiaster 7y agoGood article but it somehow suggests that because there is no garbage collection you would need to fight the borrow checker. This is not fully true because you could put your data in a Box (so that it is stored on heap instead of the function's stack) and you can wrap it in a mutex with reference counting (Arc+Mutex or Rc+RefCell), which roughly gives you what garbage collection does. Also cloning can avoid solving the borrow-check puzzle if you don't need a shared state. Of course you would not want to pack your code with Arc+Mutex or data copying if performance matters, but it's fine for a beginner to start with when writing Rust and then learn to do the optimized borrow version a bit later when needed.
- pjmlp 7y agoIt doesn't give the productivity that GC allows for writing GUI code and UI designers. Imagine having JetPack Composer, SwiftUI, Qt designer, or WPF/UWP Blend in Rust.
- wwright 7y agoQt is actually a good example because C++ has a similar memory model to Rust (at least with respect to GC). The Qt solution was basically to give everything a “Cow” (copy on write) wrapper, and to use an event loop-based, somewhat manually-annotated GC for objects that want it. Rust could totally do the same thing, and you could probably make it way easier to use than the mess that is Qt.
- pjmlp 7y agoHaving dealt with Gtk-rs, and their current solution being the clone! macro, I am not so sure. Remember that not only is GUI development with proper tooling very interacting, instead of the FOSS alternatives of code-compile-check visually, there is also the whole eco-system of third parties selling component libraries, with no control how they get integrated into the component toolbox. So whatever solution one comes up with,it needs to be more productive than forcing users to scatter Rc<RefCells<>>, or fix their code that broke compilation, just because moving a widget on the GUI tree invalidated the borrow checker assumptions.
- sittingnut 7y agorust and kubernetes - post with mostly useless hype monsters united.
- klitze 7y agoIt has a weird taste that Microsoft is preferring Rust over Golang considering that Golang is a Google thing. Don’t get me wrong, all technical arguments are correct and rust does have advantages for cloud software. But this also comes quite handy for MS. :)
- pjmlp 7y agoVSCode support for Go, and some Delve improvements, were actually developed by Microsoft.
- deleted 7y ago[deleted]