Live data from Hacker News

Show HN: Lightweight Threads, Channels and Actors for the JVM

blog.paralleluniverse.co

41–50 of 56 posts

Re: Show HN: Lightweight Threads, Channels and Actors for the JVM

#41
post #37

Earlier quoted context omitted.

I agree that using selective receive helps in dealing with messages that arrive out of the order of a specific state transition. Akka gives users the ability to stash messages if they want to. On the JVM, a long-running actor-based application (which is one of the reasons for using actors in the first place) can struggle with it. It's one of the reasons the original Scala Actor library is no longer in use, though the…

But how would a dangerous task affect the entire pool? Also, I don't know if there should even be "important actors". Like in Erlang, we want to let it fail. Important data should be kept in a shared data structure that supports good concurrency, not in actor state. Like I said in the post, I don't think every aspect of the application should be modeled with actors.

With a thread pool shared by actors, even yours, if one of the actors fails, that thread is gone until the pool creates a new one (as needed). That's one less available thread until the recreation occurs. To minimize the impact on other actors, you put known dangerous tasks on their own small pool so that their probable thread death has no impact on others.

What you're not seeing is the relevance of a supervisor hierarchy and OTP. Yes, you want to let it crash. But you want isolation of failure as well, and only with failures of increasing criticality do you want it to be escalated through the hierarchy. There is a difference between a database call failing because a SQL command failed and all database interactions failing due to network partition. OTP via Erlang and Akka allow you to model that in your actor tree.

Important data kept in a shared data structure? Globally visible? Managed with what, STM? That won't fly at scale - STM is great only when you're dealing with small datasets that don't change very often. Immutable, persistent data structures? Also not good at scale due to fixed size allocations constantly happening as structural sharing is enforced. Allocations are cheap and hopefully the objects are short-lived and GC-friendly, but it's still far from a free ride.

The whole point of actors is a concurrency abstraction. They are meant for isolating mutable state from being affected by multiple threads at the same time. OTP and supervision is just a nice way of organizing them and learning when failure occurs on another thread.

Should an entire app be modeled with actors? Probably not. A subsystem certainly can be. Depends on what you're doing, of course.

Re: Show HN: Lightweight Threads, Channels and Actors for the JVM

#42
post #13
post #11

Am i the only one who had to smile at the sentence "At Parallel Universe we develop complex data structures and distributed data grids, which require a lot of low-level programming, so I do most of my work in Java."? :) Also, i wish they would have some Java code on the page? As i understand it's available for Java as well? I love the actor model, but i have no intention to learn clojure.

Quasar is Java (Pulsar is a thin Clojure API to Quasar). There's no documentation yet (there will be soon), but the project page directs you to some examples. All the code examples in the post are in Clojure because I wanted to demonstrate how the Erlang model is fully implemented, and the Clojure API easily mimics Erlang's. The Java API doesn't have pattern matching, and so would make it harder to see the resemblanc…

I think the OP was smiling at the notion of Java as low-level. It's anything but.

Re: Show HN: Lightweight Threads, Channels and Actors for the JVM

#44
post #37

Earlier quoted context omitted.

But how would a dangerous task affect the entire pool? Also, I don't know if there should even be "important actors". Like in Erlang, we want to let it fail. Important data should be kept in a shared data structure that supports good concurrency, not in actor state. Like I said in the post, I don't think every aspect of the application should be modeled with actors.

With a thread pool shared by actors, even yours, if one of the actors fails, that thread is gone until the pool creates a new one (as needed). That's one less available thread until the recreation occurs. To minimize the impact on other actors, you put known dangerous tasks on their own small pool so that their probable thread death has no impact on others. What you're not seeing is the relevance of a supervisor hier…

How would a failed actor (huh :)) take down the thread? All exceptions thrown by the FJTasks tasks are caught.

The shared data structure was a reference to my previous post, not to STM: http://blog.paralleluniverse.co/post/44146699200/spaceships.

Re: Show HN: Lightweight Threads, Channels and Actors for the JVM

#46
post #28

Earlier quoted context omitted.

We intend to provide distribution on top of Galaxy ( http://puniverse.github.io/galaxy/ ).

Is Pulsar + Galaxy + Zookeeper + presumably some new code/project still simpler than Akka? It sounds kind of complicated.

Galaxy doesn't require Zookeeper (it's an optional dependency). And Galaxy isn't there just to support Quasar/Pulsar. It's there to support a distributed, concurrent, consistent in-memory database. Actors are just part of the story.

To simplify, Quasar/Pulsar + Galaxy is, in Erlang parlance, like Erlang + Mnesia or Erlang + Riak (only with a consistent database that assists in parallelization)

Re: Show HN: Lightweight Threads, Channels and Actors for the JVM

#47
post #6

How does this compare with http://code.google.com/p/jetlang/ ? How does this work with garbage collection? Is the GC per-process ("fiber"), like in Erlang?

Jetlang is most analogous to Go's goroutines - typed unbuffered channels backed by a pool of OS threads, where a channel send always "happens before" the corresponding channel receive.

Re: Show HN: Lightweight Threads, Channels and Actors for the JVM

#48
post #8
post #6

How does this compare with http://code.google.com/p/jetlang/ ? How does this work with garbage collection? Is the GC per-process ("fiber"), like in Erlang?

Jetlang doesn't offer lightweight-threads. It uses an event-driven processing of messages (like Akka), so fibers can't block and you can't do selective receives. The JVM's GC isn't per actor (I know actors are called processes in Erlang, but let's keep the nomenclature consistent), but its GC is extremely advanced, and some implementations work on a per-thread basis. The ramifications are that we can't offer the same…

You can do selective receives by creating and disposing channel subscriptions according to actor state. And a fiber can always spawn a conventional thread to block and publish a message when done.

Re: Show HN: Lightweight Threads, Channels and Actors for the JVM

#49
post #46

Earlier quoted context omitted.

Is Pulsar + Galaxy + Zookeeper + presumably some new code/project still simpler than Akka? It sounds kind of complicated.

Galaxy doesn't require Zookeeper (it's an optional dependency). And Galaxy isn't there just to support Quasar/Pulsar. It's there to support a distributed, concurrent, consistent in-memory database. Actors are just part of the story. To simplify, Quasar/Pulsar + Galaxy is, in Erlang parlance, like Erlang + Mnesia or Erlang + Riak (only with a consistent database that assists in parallelization)

Cool, thanks for clarifying pron. Looking forward to giving it a spin!

Re: Show HN: Lightweight Threads, Channels and Actors for the JVM

#50

I am newbie to go, but running the go version took about 186.053167ms, wonder how to explain this behavior http://play.golang.org/p/flK5QV-mDC Go Version : devel +740d244b2047 Thu May 02 18:59:39 2013 -0700

What was MAXPROCS set to? It's a lot faster to run this particular benchmark with only one thread.
Post reply on HN