3 ms·
> They're a classic concurrency foot-gun from the dark old ways of doing things. Sure you're not thinking of threads? Actor's have only really been done in Erl
by elcritch 6y ago
> They're a classic concurrency foot-gun from the dark old ways of doing things.
Sure you're not thinking of threads? Actor's have only really been done in Erlang, and more recenetly in Akka and Orlean's. AFAIK, there aren't any other paradigms other than CSP or threads for concurrency.
Actor's can have race conditions, same as any other concurrent system but I've personally never actually had any given the design patterns in OTP and Elixir. It's really helpful (to me) that each actor is always deterministic in itself and doesn't share data, only messages. It also maps nicely onto multicore.
- chrisseaton 6y ago> Sure you're not thinking of threads? No I'm thinking of actors - stateful, non-determinstic, racey actors. A minefield of classic concurrency bugs! > Actor's can have race conditions, same as any other concurrent system Deterministic systems like fork-join don't ever have race-conditions. > is always deterministic in itself and doesn't share data But the global state of all the actors is shared. If an actor you send a message to responds differently due to its state then let's be honest you're implicitly sharing that state. > It also maps nicely onto multicore. It maps directly to multicore, right. Don't we want something higher level and safer than directly mapping to our hardware?
- dnautics 6y agoit's pretty trivial to implement a deterministic fork/join[0] in actors, mostly by using the strategy "ignore messages". Elixir does this with the Task.async/1 function. https://hexdocs.pm/elixir/Task.html#module-async-and-await https://hexdocs.pm/elixir/Task.html#module-async-and-await [0] determinism can go out the window once there's an error. Can you safely say you know what happens in ruby if you are running async and one of your concurrently running async functions throws? The nice thing in elixir there is zero ambiguity as to what happens if you have (N) async functions running and one of them crashes -- it brings down all of the other threads and triggers their respective resource cleanups in exactly the way that they do as actors, since Task is a fairly trivial wrapping of erlang's actors. (Or you have choices!!, you can async_nolink if you want your async function to plow forward even if its parent dies due to the crash of one of its siblings)
- fnord123 6y agoI think when GP said "full actor system" they meant distributed actors. Of course this will mean the actors have state and message passing is nondeterministic. It's a network, afterall. I think there is still some confusion since you suggest fork/join but that's only for threads and won't work over a network.
- chrisseaton 6y ago> but that's only for threads and won't work over a network Map-reduce is fork-join and runs just fine over a network.
- elcritch 6y ago> No I'm thinking of actors - stateful, non-determinstic, racey actors. A minefield of classic concurrency bugs! Well yes systems of actors contain race conditions. However, so does Rust's or Go's concurrency primitives. The only way to completely avoid race conditions I know of would be formal methods via TLA+ or similar. From my brief looks into TLA+ it'd appear to match actor implementation models pretty well (messages to actors yield new states). > But the global state of all the actors is shared. If an actor you send a message to responds differently due to its state then let's be honest you're implicitly sharing that state. It's not really whether a program has state, but how that state is accessed and modified. In the actor model, only an actor itself can modify it's own data which makes it easier to reason about many classes of concurrency problems. Especially actions within an actor itself are deterministic (generally speaking). This makes a lot of problems become very straightforward to model without needing locks everywhere. The concurrency problem is shifted to modeling the behavior of a group of actors, which helps enforce separation of concurrency concerns from the lower level implementation details (with a good framework at least). Since I was asking and thinking about Ruby getting (preemptive) actors initially, this frame of thought seems odd to me. The entire foundation of Ruby is built on objects that contain implicit state and on those objects behaving differently based on their state even to the point of checking for unhandled "messages" via `#method_missing`. Th fork/join model can be emulated rather well as @dnautics described in a sibling comment. It's close to the model used in Elixir's Phoenix web server where each request just forks an Erlang process to handle it. At the end of the day, issues with races in the actor paradigm are little different than communicating with remote programs as either fork'ed processes or network programs. Just fork'ing a program may avoid some concurrency issues by not doing any useful work by itself. If you do use fork/join to service http requests via sockets you're now relying on implicit state from the OS to do the heavy lifting. If anything Linux's new `io_uring` works by treating a process like an actor where the process & kernel pass messages via a "messsage queue" which means your forks will just be acting as pseudo-actors anyway. Side note, on Linux doing this saves a lot of context switches by not preempting the OS process' call stack via a direct syscall every time it has something to communicate to the kernel. That gives a big speed bump to IO heavy programs. There can be significant performance benefits to making programming models work more like the hardware. I expect that actor models will grow to be a better performance match as core counts continue rising. > Don't we want something higher level and safer than directly mapping to our hardware? Certainly! ... if it makes acceptable tradeoff's in other areas. Though Actor's are really more of a base system to build higher level constructs that are easier/safer to use. Most programming shouldn't be done using your own concurrency primitives, but building on well thought out and tested libraries. Mainly though, the idea of a Ruby with preemptive actors seems fun to me. Perhaps something you could map to lego robot's for kids.