Erlang Doesn’t Fit The JVM
Hypothetical Labs - kevin - April 03, 2009There’s been a lot of talk recently about why Erlang should (must?) be ported to the JVM. I happen to think this is a bad idea for several reasons.
But before we get to my list, let me present my Java and Erlang bona fides.
In the not too distant past I spent almost 10 years developing nearly exclusively in Java. I hopped on the Java train when JDK 1.1.8 was released and rode it thru the early JDK 1.5 (aka Java 5) days. I worked on projects both small and large. I was even responsible for implementing two Java standards: JSR-168 and WSRP.
I’ve done extensive performance testing and tuning for entire application suites (think IBM-scale application suites and you’re not far off the mark). I consider myself very familiar with the major parts of the JVM including the JIT and garbage collectors (in all their many forms).
In 2004 I discovered Erlang and toyed with it a bit. Back then there wasn’t much in the way of docs and none of my friends or colleagues were interested in trying out Erlang so I set it aside. A couple of years later, in 2006, the Prags published Programming Erlang and I was hooked. I dove into Erlang and never looked back.
Since 2006 I’ve produced a popular series of Erlang screencasts and put on a training class designed to help developers quickly climb Erlang’s learning curve. Along the way I’ve scored some nice full-time paid Erlang positions, first with the Rails hosting company Engine Yard and now with my own company, Hypothetical Labs.
And now, The List:
- The JVM has poor support for distributed programming.
Erlang’s ability to elegantly extend the actor model across VM boundaries is extremely compelling. With very few caveats you can take code which originally ran on a single VM, break it apart, and run it across many nodes with no code changes.
There’s nothing even close to this on the JVM. Oh, you can get close using third party libraries but it’s not the same as having the feature baked into the language and runtime. With external libraries there are tradeoffs to be made, configuration to fuddle with, and integration issues to conquer. You could make the argument that these libraries would be subsumed into the Erlang4J runtime and, thus, become transparent to developers but I think you’d wind up with a compromised implementation at best as you deal with the inevitable tradeoffs and integration issues.
The JVM has no credible support for distributed data.
I can take any Erlang term and serialize it to a binary form using the function
term_to_binary/1. I can take that binary form and squirt it across a network to another node. On the receiving node I can callbinary_to_term/1on the binary blob and turn it back into Erlang. Well, that’s not quite true. There’s a very small subset of data, such as file descriptors and sockets, which make little sense to serialize. So I can’t serialize any Erlang term but I can serialize most of ‘em.The JVM has the
Serializableinterface,ObjectInputStream,ObjectOutputStream, and friends which try to do the same thing. I think they fail utterly. Why? Because developers have to incorporate serialization into the design of their classes from the beginning to make it work. It’s been my experience the vast majority of Java developers think about serialization rarely, if at all. Which means they’re left with tons of classes which cannot easily be serialized. Hacking serialization onto established classes is definitely Not Good Times.Even if Erlang4J could provide transparent serialization for Erlang terms the problem would still crop up at the integration boundaries between Java and Erlang code. Non-serializable objects are the rule rather than the exception.
I don’t want to single out a particular project but I’ve seen enough people suggest Terracotta as a possible solution I want to take a second and explain why it’s a poor substitute, at least as compared to Erlang.
One, Terracotta is an external library and will force certain tradeoffs to be made. See here for an example of the work required to get Clojure running on a Terracotta cluster. Erlang’s serialization and distribution is seamless and deeply integrated into the language.
Two, Terracotta requires configuration in order to work. See here for an example of the configuration required. I guess Terracotta could be baked into a language runtime but I don’t see how without requiring lots of configuration. Erlang requires minimal configuration — a single cookie value and a call to
net_adm:ping/1to set up a reliable and distributed network. Erlang’s message passing semantics also simplifies inter-node communication and dealing with inevitable node failures. I’m not sure the same claims could be made for Terracotta.Three, Terracotta’s “network memory” model represents a shared everything approach which is the opposite of Erlang’s shared nothing model. Once again this is a case of a library creating a hurdle to overcome at best or forcing a compromise in the overall design at worst.
Observation: Supporting concurrency without also supporting distributed programming diminishes the usefulness of the system overall. In other words, it’s interesting to be able to painlessly deal with lots of threads on a single machine but it’s vastly more interesting to deal with lots and lots of threads and data running across many machines.
The JVM doesn’t support first class closures.
Period. End of sentence. An implementation of Erlang on the JVM will need to provide closures so the only alternative is to simulate them in the language runtime. This will result in a definite performance hit. See the various JVM Scheme implementations and the hoops they jump thru to implement closures to get an idea of the magnitude of the problem.
The JVM lacks tail recursion.
See previous point and multiply the impact by 1000. Erlang uses tail recursion all the time. Halfway measures, like Clojure’s
recurkeyword, will not suffice. Erlang4J will have to implement its own call stack to provide proper tail recursion which means seamless Java interop just got loads harder.
At it’s heart the JVM is designed to run OO languages very efficiently. This is why languages like Ruby and Python are (mostly) easily
ported to the platform. It should also be no surprise these languages also see significant performance improvements on the JVM due to the platform’s maturity and overall high quality.
However, the JVM is less suited to running non-OO languages. Languages like Erlang, Haskell, and Scheme provide features, like tail recursion, closures, and continuations, which are not prominent in the mainstream OO world the JVM targets. They depart far enough from the OO model to make the JVM a poor platform choice.
I believe we are at the cusp of a major shift in our industry. FP is in the beginning stages of its ascendancy. It seems only natural to me for new platforms to increase in popularity as new languages come to the fore.
Categories: Blogs Hypothetical Labs
Comments
I agree with you. Why would anyone even want that? The Erlang VM is extremely stable and proven.
Besides there’d be a lot to change on the JVM to get the same benefits the Erlang VM already offers. For example, how about garbage collection. In the JVM you have shared memory, which means there’s a possibility your application can grind to a halt if the GC has a lot to clean-up ( not to mention all the other problems associated with shared memory and parallel programming ). In the Erlang VM, GC is done at the process level - *much* smaller and less of a chance the GC will slow your application.
I can’t think of a compelling reason to port Erlang to the JVM.
Posted by Dave Bryson on 03 Apr 2009 at 14:58I’m still fairly new to the Erlang community, but going through the tutorials in Joe’s book seem to indicate that there is no real security layer between TCP/IP connected Erlang nodes. I see some people talking about ssh tunneling it, but wouldn’t this be a strike against the idea of distributed communication in the runtime?
Posted by Pat on 03 Apr 2009 at 20:34Pat,
You are correct but within the context of applications running on a cluster within the confines of a hosting facility, that is behind some DMZ, the cookie is sufficient. If you are planning on distributing across TCP/IP, lib_chan style, then security needs to be layered over the top.
I don’t see this as the responsibility of the runtime more a gateway responsibility, once I am into the cluster I sort of expect the nodes to trust each other implicitly.
Posted by Justin on 06 Apr 2009 at 16:19> 1.The JVM has poor support for distributed programming.
So build one. At the root of every distributed system is the TCP/IP network stack, which the JVM does support.
> 2.The JVM has no credible support for distributed data.
Again, just build one.
> 3.The JVM doesn’t support first class closures.
Neither does the CLR. And yet VB and C# do have closures. So what’s the problem?
> 4. The JVM lacks tail recursion.
An annoyance sure, but it isn’t hard to transform tail recursion into iteration at the compiler level.
Posted by Jonathan Allen on 06 Apr 2009 at 17:03You are not interested in porting Erlang to the JVM and that’s just fine. But why do you insist on overstating the problems as you do?
Argument 1 boils down to “the JVM wasn’t written with Erlang in mind, so we’ll have to do stuff and compromise to make it behave like the Erlang VM”. To which I respond: well, yes, that’s exactly what ‘porting’ entails. And yes, instead of the trade-offs the designers of the Erlang VM *chose*, there will be some trade-offs forced upon you. However, you are prematurely judging these trade-offs as bad, without providing any reasons to assume they will be bad.
And what’s with the ‘oh noes, we have to do configuration’? Provide a proper default configuration and proper documentation on the options and there is no problem. I doubt the Erlang VM is ‘one size fits all’: it will also require configuration for specific purposes. If it isn’t configurable, it probably isn’t suited for many purposes. I don’t believe it is the silver bullet that fixes all the problems that required you to do your JVM tuning.
Argument 2: Qua trade-offs and configuration: see above. Qua serialization: Scala does it, without requiring Serializable.
Argument 3: Scala and other JVM languages have closures. Claims of performance issues require evidence.
Argument 4: Other FP languages work just fine without tail recursion and without the performance hit you claim. Moreover, this is a case of premature optimization. Many real world applications aren’t CPU bound. The interop with Java libraries may well be worth some performance.
Posted by Ivo on 06 Apr 2009 at 17:03Thank you Kevin. I think the key point is how little the JVM has to offer over Erlang’s VM. Yes, you _could_ eventually make it all work, but why? Like you mentioned, languages like Python and others benefit greatly from a highly real-world-stress-tested VM and see big speed and stability improvements with the JVM. The Erlang VM is at least as mature, if not more so in highly concurrent environments. So, again, what would the payoff be?
Posted by Joseph Wecker on 06 Apr 2009 at 18:27The payoff would be access to all the libraries available on the JVM.
There is also a lot to be said about the built-in support for profiling and monitoring modern-day VMs. I don’t know about the JVM specifically, but all the performance counters for .NET applications are avaialble without so much as a single line of code.
Posted by Jonathan Allen on 07 Apr 2009 at 00:41The high cost of threads on the JVM is another huge obstacle.
Posted by Neal Gafter on 03 May 2009 at 21:55From a newbies perspective it seems great to be able to for example mix ruby and erlang (and java libraries) in one VM. Why wouldn’t you want to do that? Assuming you want say web front end and efficient/scaling event processing at the back.
As for the general point on “too hard to do” I have no idea except JRuby does closures, doesn’t it?
Posted by gunnar on 25 May 2009 at 23:15dont critize it too much, i think erlang is awesome
gelinlik
yarış oyunları
Thanks Josh. I would always visit this site for more information on stuffs that you do.
RevAbs
Has erlang been ported to JVM yet? I’m curious, it would be like a light went on in my head. e
Posted by Gary on 25 Nov 2009 at 21:58Fantastic work dude i really like the matter discussed in the post.
Posted by Jackson on 18 Aug 2010 at 10:15It can be done and it has: http://wiki.github.com/krestenkrab/erjang/
Posted by Rjang on 21 Aug 2010 at 04:52Nice read and a great blog!
wholesale fishing tackle
I don’t believe it is the silver bullet that fixes all the problems that required you to do your JVM tuning….Nissan Frontier Superchager
Posted by Nissan Frontier Superchager on 30 Aug 2010 at 12:56It is important to keep comparing the various prices of different lightning fixtures, furniture, flooring, paints etc to keep yourself satisfied of choosing the best.
Posted by Angelina Merle on 07 Nov 2010 at 17:28Steel is classified as iron that has .2 to 2.1% carbon by weight. Cast Iron is classified as iron that has 2.1% to ~4% carbon by weight.Stainless means that it will not rust under normal conditions, cast means that it is poured into a mold.
Today, most of the businesses have set up their web presence. Hence, to concentrate your endeavors on running your business online you need to seek the pertinent help of a SEO solutions expert. Thanks of a SEO Services India
In mild steel there are negligeble alloying elements which has no effect on physical & chemical properties of MS. On the other hand due to alloying elements [ Ni & Cr ] oxidation is avoided.stainless steel forged fittings
stainless steel pipe fittings
stainless steel flanges
Add comment
Erlang on Twitter
» erlang (Andreas Åkre Solberg): RT @SaraJChipps: Node.js is like taking a bubble bath in JavaScript.
» trabajosit (Empleos en IT): argentina Desarrolladores - iOS, Ruby, Erlang: Estamos buscando un líder de desarrollo que quiera hacer una gran… http://t.co/zhTLpGI1
» erlang (Andreas Åkre Solberg): jQuery Scroll Path Plugin http://t.co/DHZ0W36c via @JoelBesada
» martyns (martynas): fighting with load bursts. probably its time to deploy https://t.co/xJxKcRmQ. #erlang
» Louellaoqk (Louella Delaroca): Informationsmanagement in Hochschulen (German Edition): Die Informations- und Kommunikationstechnik (IuK) erlang… http://t.co/95UJGZS3
» fgtrjhyu (アスパラガー): 多分「どうでもいい」だと思うんだ。 Smalltalk→Obj…C erlang→node.jsと同じで。
» zbyszek (Zbyszek Żółkiewski): RT @michalptaszek: Going to give #ejabberd tutorial on @erlangfactory in SF this March :) Anyone?
http://t.co/0bnFtIKf #xmpp #erlang
» jeedee (jeedee): Erlang, y u so fast?
» michalptaszek (Michal Ptaszek): Going to give #ejabberd tutorial on @erlangfactory in SF this March :) Anyone?
http://t.co/0bnFtIKf #xmpp #erlang
» FrancescoC (Francesco Cesarini): Woot! RT @valdo404: Practical Erlang Programming at #QConLondon I want to go there
Statistics
Number of aggregated posts: 10456
Number of comments: 1445
Most recent article: February 06, 2012
Latest comments
» simple smile on Scale means Skills: Very informative article. Pretty sure people would love to go to that place for shopping. Specially to those who are…
» simplesmile on 27 January 2012: Erlang Solutions embarks on an Erlang Embedded KTP: Your article will make the world better. Thanks again and good luck to you in your life. See you next time.simplesmile
» tandblekning easewhite on 08 February 2012: Erlang Express 3-day Course in San Francisco on 8 February: ncomprehensible to me now, but in general, the usefulness and significance is overwhelmingtandblekning easewhite