News for hackers. Stuff that matters.
Re:The Piston image library is now pure Rust by bsaul on Sunday January 08, 2017 @08:04AM (#13349536)
If only rust had concurrency / parallel programming primitives or library as nice as golang or elixir,i think i'll move to this language right away. For now i'm still holding my breath before developping with it on the server side.
Re:The Piston image library is now pure Rust by ekidd on Sunday January 08, 2017 @10:09AM (#13349941)
I think some of issue here is that when you ask for "concurrency / parallel programming primitives", you're actually talking about more than one problem. We can divide things up as follows:

- Data parallelism. This is where you have (for example) a giant array of data to process and want to use as many cores as possible. For this, rayon is gorgeous: https://github.com/nikomatsakis/rayon Seriously, I can just not say enough good things about programming with rayon, and how nice Rust's "no mutable aliasing" makes coding. Also at some point, Rust will also need good libraries for talking to the GPU.

- I/O concurrency. This is where you have a server that needs to respond quickly to 10,000+ sockets, for example. For this, it looks like everyone is standardizing on futures and tokio: https://github.com/alexcrichton/futures-rs https://github.com/tokio-rs/tokio

But it seems like you're most interested in Erlang-style actors with M:N green threads? The issue here is that—as best I remember the history of Rust—the Rust maintainers decided that green threads were simply too high a level of abstraction for Rust. I think Rust will eventually move back in that direction, first using futures+tokio+async I/O, and then by eventually adding async/await sugar on top. That way, you'll only pay for coroutines/green threads when you explicitly opt in. But it will take a year or so for all this to start maturing, I think.

In the meantime, tokio's method-chaining syntax should actually be somewhat tolerable, especially because Rust has a `#[must_use]` attribute that prevents you from forgetting to use a future. If you're lazy, just run everything through rustfmt to get the indentation right.

Re:The Piston image library is now pure Rust by steveklabnik on Sunday January 08, 2017 @10:20AM (#13349996)
> as best I remember the history of Rust

There's an RFC for that! https://github.com/rust-lang/rfcs/blob/master/text/0230-remo... (A reminder that this was written in 2014, so statements are about Rust at that time period)

> I think Rust will eventually move back in that direction

Note that tokio is not "green threads" as they're conventionally thought of, though they are similar if you squint, kinda.

Re:The Piston image library is now pure Rust by ekidd on Sunday January 08, 2017 @10:26AM (#13350032)
> Note that tokio is not "green threads" as they're conventionally thought of, though they are similar if you squint, kinda.

Well, I'm leaping ahead to the end of the story, here, and speaking far too loosely about technical details. ;-) Futures + tokio + a possible future async/await proposal would provide a reasonable enough syntax for actors/coroutines in Rust, I suspect.

Re:The Piston image library is now pure Rust by steveklabnik on Sunday January 08, 2017 @10:27AM (#13350045)
Re:The Piston image library is now pure Rust by GolDDranks on Sunday January 08, 2017 @11:05AM (#13350293)
From the author of the mioco coroutine library, there is a new attempt to implement coroutines on top of tokio: https://github.com/dpc/tokio-fiber/ (still under construction, it seems)
Re:The Piston image library is now pure Rust by Manishearth on Sunday January 08, 2017 @08:29AM (#13349613)
Tokio/futures is going to be the "blessed" way of doing async IO (the way its done in server side apps). That should be ready sometime this year. It won't be in the stdlib but it will be integrated with most of the I/O related libraries in the ecosystem and the Rust team is involved in making it happen.

It seems like you're talking specifically about async I/O here? Because Rust does have parallel programming primitives both in the stdlib and in the form of libraries like rayon and crossbeam. Rayon, in particular, is amazing for parallel programming.

Re:The Piston image library is now pure Rust by tupshin on Sunday January 08, 2017 @08:20AM (#13349593)
while it's still in early days, keep you eye on the tokio project https://github.com/tokio-rs/tokio which looks to be the foundation for higher level activity in this area
Re:The Piston image library is now pure Rust by bsaul on Sunday January 08, 2017 @08:27AM (#13349603)
I did have a look at it. I think the initiative is great, but i don't like the idea of basing concurrency on async io primitives. I like the idea of actors or coroutine better, because it lets you code in a synchronous manner, and make concurrency block a little coarser and more manageable...

Maybe i didn't understand everything on this project though, so please correct me if i'm wrong.

Re:The Piston image library is now pure Rust by Manishearth on Sunday January 08, 2017 @08:42AM (#13349651)
Rust may eventually get async/await syntax that works with futures so coroutine-based programming would be easy to do, regardless of whether or not it is backed by an event loop like tokio or something else.

I'm not sure I get your point here, from other comments it seems like you're annoyed that Rust didn't choose a solution, and when tokio (which is the "chosen" solution for server side async stuff) is talked about you wish it had chosen a different one.

As I mentioned in my other comment I'm also not sure what you mean by "concurrency primitives" here, from your mention of server-side programming it would appear that you want something that handles async I/O, but this comment seems to indicate otherwise, and Rust does have pretty nice primitives (in the stdlib, and in rayon/crossbeam) for general parallel programming.

Re:The Piston image library is now pure Rust by stymaar on Sunday January 08, 2017 @09:26AM (#13349780)
> As I mentioned in my other comment I'm also not sure what you mean by "concurrency primitives" here, from your mention of server-side programming it would appear that you want something that handles async I/O, but this comment seems to indicate otherwise, and Rust does have pretty nice primitives (in the stdlib, and in rayon/crossbeam) for general parallel programming.

Since he mention Go and Erlang, I think what the gp just wishes Rust had a built-in solution for M:N threading.

Whether M:N threading is nicer than async APIs is highly subjective though. (I'm talking about ergonomics here. I think it's widely accepted that async is more efficient when performance really matters)

Re:The Piston image library is now pure Rust by Manishearth on Sunday January 08, 2017 @09:32AM (#13349801)
> I think what the gp just wishes Rust had a built-in solution for M:N threading.

Yeah, but then they say that they doesn't want concurrency to be based on async io primitives, which is exactly what Go does IIRC.

Re:The Piston image library is now pure Rust by lobster_johnson on Monday January 09, 2017 @03:17AM (#13354820)
Both Go and Erlang are based on blocking, synchronous I/O primitives combined with asynchronous communication between the green threads that use them. It's a lot easier to reason about than event-based I/O.
Re:The Piston image library is now pure Rust by stymaar on Sunday January 08, 2017 @10:05AM (#13349921)
> which is exactly what Go does IIRC.

Under the hood, I guess yes. But in Go, the developer always use blocking API and the runtime does the magic with the async stuff. Some people find it easier to reason about code written this way.

Re:The Piston image library is now pure Rust by bsaul on Sunday January 08, 2017 @10:08AM (#13349938)
My point is that i wished rust made the choice to favor actor style concurrency officially. Which means autonomous entities communicating by message passing, having a single "run loop" ( thread, coroutine whatever), and encapsulating a state.

I mentionned async io but i should have added "+ event loop", because they can be used for different things indeed.

Now maybe the rust team could officialy endorse one programming model for the server side, but keep the language itself agnostic, so that other people could try and do different things in the future. But i don't think leaving it all to the community to decide is good for the very beginning. You need everyone to go in the same direction because there isn't enough talented people to run multiple races at the same time ( but honestly i don't have that,much experience running communities, so it's just my feeling).

Re:The Piston image library is now pure Rust by ekidd on Sunday January 08, 2017 @10:23AM (#13350015)
> My point is that i wished rust made the choice to favor actor style concurrency officially.

I think you're asking Rust to be a high-level language like Erlang or Go, and not a near-the-metal systems programming language that may (someday) have an "official" story about using actors for people writing servers.

Rust's threads are raw OS-level threads, because using green threads by default (or as an option) imposed serious overhead elsewhere:

http://stackoverflow.com/questions/29428318/why-did-rust-rem... https://github.com/rust-lang/rfcs/blob/0806be4f282144cfcd55b... https://aturon.github.io/blog/2016/08/11/futures/

From the third link:

> The problem is that green threads were at odds with Rust’s ambitions to be a true C replacement, with no imposed runtime system or FFI costs: we were unable to find an implementation strategy that didn’t impose serious global costs.

Re:The Piston image library is now pure Rust by Manishearth on Sunday January 08, 2017 @02:10PM (#13351337)
tokio+mio is "async io + event loop". I think tokio-fiber tries to build coroutines on top of it.

This is (or, will be) the "officially endorsed" async model for the server side. All the libraries you'll be using *hyper, etc) are going to be integrated with it. It's not yet finished, but when it is it will be.

In the future if we get async/await that would be an even more ergonomic thing that can be used with futures (and hence, tokio), but most of the machinery is already planned for tokio itself.

Re:The Piston image library is now pure Rust by tupshin on Sunday January 08, 2017 @09:56AM (#13349884)
I believe the idea is that tokio, because of its zero-cost abstractions will be able to be efficiently be the foundation of those styles.

Check out https://github.com/dpc/tokio-fiber/ for co-routines being re-envisioned on tokio, and https://github.com/rust-lang/rfcs/issues/613 acknowledges that the actor story is still a work-in-progress.

I have seen no indication that either coroutines or futures will be less ergonomic or performant due to being built on top of tokio's futures.

Re:The Piston image library is now pure Rust by bsaul on Sunday January 08, 2017 @03:01PM (#13351639)
This whole discussion regarding concurrency/parallelism stacks made me think that there's probably a good blog post to write:

Start with low-level OS system calls and show what pieces one needs to write to reach higher level abstractions like futures, coroutines , async / await, nodejs style event loop, or full blown actors.

That would also make for a nice roadmap to whoever would like to build OTP or Akka style framework in Rust.

Re:The Piston image library is now pure Rust by Ar-Curunir on Sunday January 08, 2017 @08:17AM (#13349582)
Isn't the point of Rust to enable easy concurrency?
Re:The Piston image library is now pure Rust by bsaul on Sunday January 08, 2017 @08:19AM (#13349588)
I think it's to enable safe concurrency. The problem is they decided to let others build the primitives for concurrency, on top of the stdlib. Which means the language didn't decide between actor vs futures vs coroutine vs event loop, etc..
Re:The Piston image library is now pure Rust by mtanski on Sunday January 08, 2017 @01:40PM (#13351180)
Problem?

The goal of Rust is to be a general system programing language.

In fact, Rust in the past had a runtime that included green threads a primitives; that ended up being a problem. The runtime and stdlib was only usable in some system programing task (defeating the whole goal).

Re:The Piston image library is now pure Rust by Lev1a on Sunday January 08, 2017 @08:31AM (#13349617)
If I remember right, Rusts approach for their stdlib is that the bare minimum is actually in there and everything else is to be supplied by libraries, like the getopts crate that was split from the stdlib AFAIK.
Re:The Piston image library is now pure Rust by steveklabnik on Sunday January 08, 2017 @09:59AM (#13349893)
Generally speaking, yes. This is driven by three things, largely: Rust has a very wide variety of use-cases, we don't want to stabilize a poor API forever, and Cargo exists and works well.
Re:The Piston image library is now pure Rust by pcwalton on Sunday January 08, 2017 @11:58AM (#13350612)
> Which means the language didn't decide between actor vs futures vs coroutine vs event loop, etc..

Having the language decide on one method of concurrency would make it useless for lots of people's purposes (including ours).

Re:The Piston image library is now pure Rust by stshine on Sunday January 08, 2017 @12:26PM (#13350792)
On the other hand, since these methods are not compatible it will create certain split in the ecosystem.
Re:The Piston image library is now pure Rust by msbarnett on Sunday January 08, 2017 @02:57PM (#13351615)
Those splits are inevitable. There is no One Size Fits All concurrency primitive. Embedded devs and web devs have vastly different requirements.

Either the split is "every use-case finds the primitive that works best for it" (Rust), or the split is "here's the blessed primitive, other use-cases can pound sand" (Go)

Re:The Piston image library is now pure Rust by Manishearth on Sunday January 08, 2017 @03:16PM (#13351726)
Must it? In fact, I'd expect the reverse -- choosing a model for the language will make the ecosystem tied to that model

For example, while tokio is being integrated with hyper, it does not affect the "usual" users of hyper at all, both in terms of API and in terms of what's going on under the hood, cost-wise.

Having a blessed solution for async like tokio that is not in the stdlib seems to encourage folks to integrate with it, but not in an irrevocable manner; the core library stays intact and able to support potential other models in the future.

Re:The Piston image library is now pure Rust by stshine on Sunday January 08, 2017 @09:30PM (#13353530)
Sure, I do hope we can focus on one concurrency primitive, but the possibility that we may have async/await and coroutine at the same time seems kind of unfortunate to me.
Re:The Piston image library is now pure Rust by Manishearth on Sunday January 08, 2017 @10:09PM (#13353704)
AFAICT async/await the way Rust intends to have it (plans are rough right now) basically coroutines with extra sugar to specialize it with futures. The core language won't know about event loops, it will just know about futures, and you wire up your async/await or whatever to the event loop yourself. As both in the context of concurrency will involve futures they will probably work well together.
Re:The Piston image library is now pure Rust by stshine on Monday January 09, 2017 @05:35AM (#13355354)
I'd love to see this goes well with highest performance.
Re:The Piston image library is now pure Rust by Manishearth on Monday January 09, 2017 @08:52AM (#13356271)
AFAICT It's all going to be a generator-like abstraction which is pretty zero-cost.
Re:The Piston image library is now pure Rust by stshine on Monday January 09, 2017 @06:14PM (#13360800)
The real world is always more complicated, since cps carries stack in its arguments.
Re:The Piston image library is now pure Rust by Ar-Curunir on Sunday January 08, 2017 @08:25AM (#13349598)
Hmm. I guess the community will eventually decide on one particular primitive, hopefully soon.
Re:The Piston image library is now pure Rust by Manishearth on Sunday January 08, 2017 @08:33AM (#13349623)
I don't think it's a good idea for Rust to choose a particular kind of concurrency primitive. Rust is pretty broad in its use cases, and choosing a primitive may end up restricting other fields. Remember that Rust used to have a libuv based green threading model, and it was removed for precisely this reason -- it affected some use cases in major ways.

Rather, it is important for subcommunities to rally around particular sets of libraries. E.g. the web and I/O related libraries seem to all be going in the direction of integrating with tokio. This means a web programmer can use tokio and it will work smoothly. OTOH, a different subcommunity that uses a different set of libs may use stuff built on rayon and crossbeam.

Re:The Piston image library is now pure Rust by Ar-Curunir on Sunday January 08, 2017 @01:34PM (#13351154)
That's fair; it allows for lots of flexibility.
Re:The Piston image library is now pure Rust by camus2 on Sunday January 08, 2017 @08:57AM (#13349684)
> Hmm. I guess the community will eventually decide on one particular primitive, hopefully soon.

Ultimately you'll get libraries or frameworks that are not compatible with each other because they use different concurrency models. That's a mistake Rust will pay in the future.

Re:The Piston image library is now pure Rust by fredsir on Sunday January 08, 2017 @09:20AM (#13349763)
You get that anyways. The question is how popular something like tokio will get. Since its blessed by the core team and the language designers, I think it will get popular, and therefore many will use it. But there will inevitably be someone who doesn't like it, or for whom it doesn't fit, and they will use something else. But that happens no matter if tokio is in the stdlib or not.
Re:The Piston image library is now pure Rust by stymaar on Sunday January 08, 2017 @09:36AM (#13349813)
That's obviously a threat. But so far this is not what's happening: since tokio and future-rs were announced we've seen most library authors ditching their old stuff to use tokio instead.
Re:The Piston image library is now pure Rust by Jweb_Guru on Sunday January 08, 2017 @11:15PM (#13353957)
Not really. People in the Rust community have shown a great deal of willingness to standardize on a handful of traits, so things tend to be intercompatible. That might change, I guess. In any case, there's no point in using an async I/O model for the majority of use cases many of the people using Rust are interested in, so people standardizing on something else for those usecases isn't a problem.
Re:The Piston image library is now pure Rust by bsaul on Sunday January 08, 2017 @08:34AM (#13349630)
I hope the same, but i don't have great hopes. For a community to adopt a library as fundamental as this one would be, it would need to be of such a high level that i think only the language designer can create it ( or other really big names in the field).

If you think of something like OTP, i don't see any equivalent anywhere else. Even akka isn't unanimously used as the foundation for server side dev on the jvm.

Re:The Piston image library is now pure Rust by steveklabnik on Sunday January 08, 2017 @09:59AM (#13349897)
Two of the three Tokio core team members are on the core team of Rust, and one of them is on the language design team.

EDIT: to be clear, that means one is on both. The third member is very well-known as well; having built the async primitives that this is built on, as well as initially implementing Cargo. Bona fides aren't an issue here.

Re:The Piston image library is now pure Rust by bsaul on Sunday January 08, 2017 @10:13AM (#13349960)
Didn't know that. That's clearly a good thing.