6 ms·
Nice exemplar. Back when Java was being created, James Gosling was pretty insistent that concurrency be lightweight and scalable. When I ported it from SunOS 4
by ChuckMcM 13y ago
Nice exemplar. Back when Java was being created, James Gosling was pretty insistent that concurrency be lightweight and scalable. When I ported it from SunOS 4 so Solaris 2.0 I had to move from the really light weight setjump()/longjmp() threads that he had implemented, into the thread system that Solaris had defined. There was a huge negative impact on performance (as I recall about 15x slower). That sucked because one of the coolest demos at the time had a little world in it where 'Fang' (the Java mascot) lived and a bunch of things in that world were all animated with threads. Looking at the 'fiber' model for threads I think they are much closer to what we should have done in the first place.
The thought was to have a billion threads on a SPARCStation 10 (that is like an old Pentium machine now). We never got close but it was a great goal. Definitely going to have to go back and revisit this topic now. Thanks for the excellent demo to play with!
- justinsb 13y agoI also remember user-space threading in Java (where N threads would be multiplexed onto M kernel threads), although my understanding was that we moved to the 1:1 threading model because it was faster and had fewer pathological edge cases. It sounds like you're saying that it wasn't faster? Can you explain a bit more about the motivation if so? Any thoughts on whether we should have user-space threading in the JVM today? Maybe it could be implemented in RoboVM as an experiment (rather than wrestling with the JVM immediately)?
- ChuckMcM 13y agoSo the "original" move to native threads was motivated by the fact that Sun didn't want Java to be SunOS only (there were a number of SunOSism's in it when it was Oak). That the system threading system would improve independently of the language and have fewer edge cases were put forth as good reasons to do that. Initially it was slower because context switches are slower, and anything that had to context switch into and out of the kernel was thus slower. Later there were other reasons. "User level" or as I prefer "Single Context" [1] threads have the ability to be very fast because they have extra knowledge about what is going on and access to other address spaces (so you don't have to save something if you know how it's used). There has been lots of great work on this since the early 90's when this decision was made so I suspect the issue would be significantly less. [1] At the time kernel threads were 'single context' and quite fast. Fast enough to be used for interrupts. There is a great paper on the threading system in Solaris which describes them. -- http://dl.acm.org/citation.cfm?id=202217 http://dl.acm.org/citation.cfm?id=202217
- pron 13y agoNaturally, we've experimented a lot measuring context-switch cost. While pretty bad on OS X, on Linux it's quite good in many circumstances (sleep, IO interrupt) but not so good when a thread waits to be woken up by another application thread (as opposed to being woken up by some kernel event). Aside from consuming less memory, Quasar fibers shine exactly in that last scenario: when fibers wait on other fibers (they could be waiting for an actor or channel message, a condition variable, or an in-memory DB transaction). Fibers use Doug Lea's awesome fork/join thread pool for scheduling. I hope to write about our context-switch results some day.
- rdtsc 13y agoI got to about 500K processes on Erlang's VM on an i7 with lots of memory. These people people got up to 2M concurrent TCP connections http://blog.whatsapp.com/index.php/2012/01/1-million-is-so-2011/ http://blog.whatsapp.com/index.php/2012/01/1-million-is-so-2... And on top of it, it is using isolated heaps. That is beautiful I think. Completely concurrent GC is beautiful. I know Erlang syntax is not to for everyone's taste (I do like it though). There is also Elixir (http://elixir-lang.org/ http://elixir-lang.org/). But the underlying BEAM VM is an awesome piece of technology. > The thought was to have a billion threads on a SPARCStation 10 There are some green-thread C libraries I've been playing with, like Protothreads ( http://dunkels.com/adam/pt/index.html http://dunkels.com/adam/pt/index.html ) and libconcurrency ( https://code.google.com/p/libconcurrency/ https://code.google.com/p/libconcurrency/ ) I think they use setjump/longjump trick. Some use setcontext()/getcontext() POSIX call. I still like Erlang VM best.
- HowardMei 13y agoErlang is really good, especially for engineers with hardware background, who may find FP & Message Passing are more intuitive than OOP & Context Switching. But it's quite difficult to hire.
- reginaldjcooper 13y agoDifficult as in you are looking for Erlangers but cannot find them? I haven't seen many postings looking for Erlang programmers.
- yapcguy 13y agoSeems to be the same thing with Haskell and other languages, including Golang, that many groups on HN are passionate about. There aren't many people hiring for skills in these languages. Some start-up founders I know who have built their company on Python and Javascript, when I ask them if they have looked at Golang, they reply 'What's that?'.
- 13y ago
- tieTYT 13y agoIsn't the Java mascot named Duke?
- Keyframe 13y agoHe looks like a fang though. Maybe that's what they've nicknamed him internally.
- ChuckMcM 13y agoThe guy who drew him (Joe Palrang) called him 'Fang' and most of the rest of the folks in the Java group did as well. When we went public with Java Sun PR didn't like the name we'd given him so they picked Duke. I think Wayne Rosing suggested that name but my memory of that is quite fuzzy.
- ww520 13y agoPeople have been using Netty (Java) to handle over 500K connections with NIO on one server. http://urbanairship.com/blog/2010/08/24/c500k-in-action-at-urban-airship/ http://urbanairship.com/blog/2010/08/24/c500k-in-action-at-u... That's 3 years ago. I'm sure more can be handled now, with more memory and more cores. Bundled Netty with a distributed system like Hazelcast, you can easily scale out to more machines.
- cnlwsu 13y agoI've setup 1m connections to a Netty service we host a couple years back, its kinda a fun exercise. I would avoid something like hazelcast if want to do something that palatalized. We used terracotta and the entire concept of a shared memory in a distributed system becomes a major headache.
- ww520 13y agoCan you give some insights on why to avoid Hazelcast or friends for distributed system? I can give my sample usages. I mainly used it for organizing the cluster automatically, like managing membership, server joining or leaving, maintaining the master server address list. With a distributed hash scheme like Soda, any member server can accept work from any client. Scaling out is very simple, just boot up a machine from an image. It would use Hazelcast to join the cluster and become available. I also used it for distributing jobs, nice to able to say - queue these jobs and the distributed workers pick them up automatically. I avoid using it for shared memory stuff, using it like Memcached. That's what Memcached, Redis, and friends are for.
- jeremyjh 13y agoYes but you're dealing with callbacks then. In the context of the SP, Netty is an example of what they wanted to escape from.
- pron 13y agoQuasar is distributed on top of our own IMDG called Galaxy. Our goal is not to give you scalability, but to give you scalability while keeping familiar and simple programming models. There is absolutely no reason not to use Netty with Quasar. In fact, we're doing exactly that in an internal project.