Live data from Hacker News

Actors, Green Threads and CSP on the JVM

boundary.com

21–30 of 49 posts

Re: Actors, Green Threads and CSP on the JVM

#21

I can't help but wonder if the article of the author has seen Quasar: http://docs.paralleluniverse.co/quasar/ It seems to be a concrete refutation of his claims of impossibility. Quasar successfully brings green threads to the jvm. It includes both channels as are now popularized by golang, as well as higher level patterns like actors. Despite the young nature of the framework, benchmarks show it comparing reasonably…

Erlang loops will not block the OS thread because the BEAM VM implements preemptive multi-tasking at the (green) process level.

Re: Actors, Green Threads and CSP on the JVM

#23

Very interesting article and analysis, although it would be nice if it explained what exactly a "Green Thread" is. From the article, I am guessing that a "Green Thread" is related to the lightweight low-level concurrency mechanism that he is referring to as the alternative to normal threads, but it is not exactly clear what that really means.

A green thread is a "lightweight" thread, meaning a thread that is managed by a user level process, not by the OS. This main advantage is you avoid OS thread context switch time, which is comparatively very large. The disadvantages are: - you have to balance load across true OS threads to take advantage of multiple CPUs. (You often pin an OS thread per CPU.) - if you make a call to a blocking OS function you have no…

What's old is new again?

http://en.wikipedia.org/wiki/Green_threads#Green_threads_in_...

Re: Actors, Green Threads and CSP on the JVM

#24

I can't help but wonder if the article of the author has seen Quasar: http://docs.paralleluniverse.co/quasar/ It seems to be a concrete refutation of his claims of impossibility. Quasar successfully brings green threads to the jvm. It includes both channels as are now popularized by golang, as well as higher level patterns like actors. Despite the young nature of the framework, benchmarks show it comparing reasonably…

He links to quasar in the article...

And yet I don't understand why the article is FUD'ing about it!

> hopefully without altering its meaning

...What?

I'm using Quasar right now. It works as advertised. Bytecode manipulation tools are not some scary unexplored arena of JVM tooling.

Re: Actors, Green Threads and CSP on the JVM

#25

I can't help but wonder if the article of the author has seen Quasar: http://docs.paralleluniverse.co/quasar/ It seems to be a concrete refutation of his claims of impossibility. Quasar successfully brings green threads to the jvm. It includes both channels as are now popularized by golang, as well as higher level patterns like actors. Despite the young nature of the framework, benchmarks show it comparing reasonably…

For me the caveat that calling a library or existing code can block the scheduler is a non-starter. I love what everyone is doing and I don't think it means they are useless, but for certain tasks and existing projects it means they are impractical to incorporate.

I think it's fair to say that what we are being offered is not ponies. It's a useful tool, but also a leaky abstraction and not what I want to be working with in the long run.

Also the statements about Erlang and loops is odd. My understanding is loops in Erlang are preemptible and that the VM bends over backwards to provide consistent scheduling even if it means losing some performance.

Re: Actors, Green Threads and CSP on the JVM

#26

Can anyone advise please books / blogs / videos to learn the theory behind concurrency, threading, Green Threads, how they are implemented?

To see the earlier work by Rob Pike on the ideas that would eventually turn into golang take a look at this paper:

http://www.cs.bell-labs.com/who/rsc/thread/newsquimpl.pdf

A good overview (of CSP) document is written by Russ Cox:

http://swtch.com/~rsc/thread/

Both the above articles are more focused on implementation as opposed to theory.

Re: Actors, Green Threads and CSP on the JVM

#27

Earlier quoted context omitted.

A green thread is a "lightweight" thread, meaning a thread that is managed by a user level process, not by the OS. This main advantage is you avoid OS thread context switch time, which is comparatively very large. The disadvantages are: - you have to balance load across true OS threads to take advantage of multiple CPUs. (You often pin an OS thread per CPU.) - if you make a call to a blocking OS function you have no…

What's old is new again? http://en.wikipedia.org/wiki/Green_threads#Green_threads_in_...

Yes, in some ways. Usually you get a new concurrency model in addition to a new threading model, and more control than the original JVM green threads gave you.

Re: Actors, Green Threads and CSP on the JVM

#28
post #26

Can anyone advise please books / blogs / videos to learn the theory behind concurrency, threading, Green Threads, how they are implemented?

To see the earlier work by Rob Pike on the ideas that would eventually turn into golang take a look at this paper: http://www.cs.bell-labs.com/who/rsc/thread/newsquimpl.pdf A good overview (of CSP) document is written by Russ Cox: http://swtch.com/~rsc/thread/ Both the above articles are more focused on implementation as opposed to theory.

Thanks!

Re: Actors, Green Threads and CSP on the JVM

#29

I can't help but wonder if the article of the author has seen Quasar: http://docs.paralleluniverse.co/quasar/ It seems to be a concrete refutation of his claims of impossibility. Quasar successfully brings green threads to the jvm. It includes both channels as are now popularized by golang, as well as higher level patterns like actors. Despite the young nature of the framework, benchmarks show it comparing reasonably…

Quasar is an amazing piece of engineering work, and I really don't understand how pron has been able to do so much in such a relatively short period of time (including insights into the ideas and implementation).

Re: Actors, Green Threads and CSP on the JVM

#30

I can't help but wonder if the article of the author has seen Quasar: http://docs.paralleluniverse.co/quasar/ It seems to be a concrete refutation of his claims of impossibility. Quasar successfully brings green threads to the jvm. It includes both channels as are now popularized by golang, as well as higher level patterns like actors. Despite the young nature of the framework, benchmarks show it comparing reasonably…

Author of Quasar here and apparently the target of the criticism in the article. It's kind of hard to make out the main claim the author has, but let me respond to the few more specific claims:

1. ForkJoin is not "notorious for its overhead". In fact, it is among the best implemented, best performing work stealing schedulers out there. Scheduling a task with ForkJoin takes a few nanos, and is almost as cheap as a plain method call. Don't take my word for it: go ahead and benchmark it.

2. Like Go, Quasar doesn't constrain the running code from mutating shared state -- if you're using Quasar from Java, that is. But it's still just as useful as Go, and when used from Clojure, it's even more flexible than Erlang, and actually quite safe.

3. My macbook isn't cruddy.

4. The stuff possible with Quasar, like running a plain Java RESTful service on fibers to gain a 4x increase in server capacity -- without changing the code and without even starting to parallelize the business logic with actor/CSP -- speaks for itself.

5. I'm not spreading FUD on threads -- you can watch my talk at JVMLS (linked in the article) to see my precise point: kernel threads cannot be used to model, one-to-one, domain concurrency, because the concurrency requirements of modern application (and the capabilities of modern hardware) exceed by several orders of magnitude the number of threads supported by the kernels. Fibers keep the (excellent) abstraction provided by threads as the unit of software concurrency, while making the implementation more suitable for modern soft-realtime workloads. When your average programmer can spawn up a (lightweight) thread without thinking about it -- say one for each request, and even many more, concurrency becomes a lot easier.

6. The linked Paul Tyma slide are completely irrelevant. I've got nothing against doing kernel-thread-blocking IO. The problem becomes writing simple, yet scalable code to process incoming requests. Modern hardware can support over a million open TCP sockets, but not nearly as many active kernel threads. Asynchronous libraries give you the scalability but fail on the simplicity requirement; fiber-blocking IO gives you both the performance and the simplicity of blocking code.

7. As to the "strawman benchmark" with "too many threads", the author is welcome to repeat the experiment using a thread pool with as few or as many treads as he'd like -- the result would be the same: switching kernel threads costs about 10-20us, while task-switching fibers costs 0.5us (and can be improved).

> few existing libraries understand what your application is trying to do with green threads

That's exactly the purpose of the Comsat project, which integrates existing third-party libraries with Quasar fibers. You're right, integrating "inverted" frameworks does require more work, but so far Comsat integrates, servlets, JAX-RS services and Dropwizard.

[1]: http://blog.paralleluniverse.co/2014/05/29/cascading-failure...

Post reply on HN