Erlang
by Paul O'Rorke on Nov.19, 2008, under Meeting Notes
At the monthly meeting of the San Francisco Bay Area Chapter of the ACM in Cupertino on 11/19/2008, Francesco Cesarini, CTO and Founder of Erlang Training and Consulting Ltd. and co-author of the book “Erlang Programming“ presented “Erlang Concurrency, What’s the Fuss?.” Yariv Sadan from Facebook presented “Erlang Explained by Example.”
Erlang was invented around 1990 by Ericsson in Sweden. It is a functional language like Haskell and Lisp but it runs on a virtual machine like Java. Ericsson is developing Erlang and is releasing it as open source under a Mozilla-style license. A nice introductory short article on Erlang is here and the Erlang open source project website is at http://www.erlang.org.
Erlang is used in fault tolerant, highly concurrent, high traffic systems. It was originally used in the switches phone companies use to route calls. The Madrid subway software is written in Erlang. Recently, Erlang was used in the U.K. to process TV votes coming in from mobile phones from hundreds of thousands of people. ejabberd, an open source instant messaging (XMPP) server, is written in Erlang, as is Tsung, a distributed load testing tool (used to test ejabberd). Facebook (Yariv) uses Erlang for the back-end of their chat service supporting 70 million users.
Martin Stein, the meeting organizer, is using Erlang in experiments on Cloud Computing at SAP Research. He said that SAP hired a trainer from Erlang Training and Consulting for a week to learn OTP.
Francesco’s company is the only one in the world offering training in OTP (an acronym that was originally supposed to mean “Open Telecommunications Platform”). OTP was developed at Ericsson and brings the following to Erlang:
- applications;
- behaviors;
- design patterns, principles and rules;
- libraries;
- and tools.
OTP has been thoroughly field tested over more than a decade and contributes to Erlang’s high reliability and robustness. There is a very high-performance web server written in Erlang called Yaws. In a comparison at the Swedish Institute of Computer Science of Apache versus Yaws, Apache tended to die at around 4,000 connections per second while Yaws supported around 80,000. A distributed database for Erlang called Mnesia was developed by Ericsson.
Yariv mentioned Facebook’s chat service uses around 100 servers. Facebook tested Erlang against Ruby and RAILS and found Erlang to be six times faster than Ruby. Yariv has a thoughtful comparison of Erlang versus Scala. Yariv has started an open-source web application framework called ErlyWeb. Facebook uses “thrift“, an open-source framework that was developed in-house, to communicate across programming languages in all of their applications.
There is no shared memory in the Erlang virtual machine. This contributes to performance but is an issue when processes really need to communicate (but see Yariv’s Blog). Erlang is only recently adapting to the emergence of multi-core and multi-cpu machines. The first SMP version of Erlang came out in 2007. Different scheduling and thread allocation schemes are being tried, for example: one thread per scheduler with multiple schedulers. There is a notion of priorities but Francesco said their use is strongly discouraged since they only tend to mess up scheduling.
Some of Erlang’s features are:
- message sending is asynchronous: ”send and pray”;
- Erlang doesn’t have built-in synchronous message passing although it does provide infrastructure that can support it;
- there can be a huge number of processes and it is very important to keep track of them;
- a name-server or registry can be used to keep track of process ids;
- process creation time is very fast in Erlang as compared to Java or C# (but this is in part because Erlang does not create new threads when creating new processes)
- there are low level hooks that support integration with code in C and Java;
Strengths:
- Erlang is good for highly concurrent applications with typical throughputs of tens of thousands of transactions per second;
- Erlang can support very large numbers of simultaneous processes (e.g., Yariv mentioned that he has seen 8-9 million processes running at one time);
- applications involving extensive inter-process communication are another sweet spot;
- distribution over machines is very easy in Erlang (there is no distinction at the language level between processes running on different machines);
- Erlang supports hot code swapping. (Code can be updated during run-time.)
Weaknesses:
- Erlang is not good for number crunching
- the VM is large so Erlang is not appropriate for many client-side applications
Questions:
- I wonder how Mnesia compares with databases used in cloud computing platforms?
- Is there anything comparable to Azul and Terracotta’s Java-based offerings for Erlang?
Action Items:
- check out open source Erlang, Mnesia, Yaws, ejabberd, and Tsung
- check out Francesco’s and Yariv’s websites above;
- read Francesco’s book when it comes out;
Leave a Reply
You must be logged in to post a comment.