Parallella and Erlang: An Introduction

We at Erlang Solutions are very excited about our partnership with the Parallella Project and have formed a small task force to explore what can be done to make it easier to utilise the multicore processing power Parallela board has within Erlang.

In this post, Torben (a.k.a The Erlang Priest) will provide a brief overview of the language and explain why we think Erlang and Parallella are a good match.

What is Erlang?

Erlang is a concurrency oriented programming language created by Ericsson back in the 80′s for the telecommunications domain. Due to problems with time-to-market, productivity and maintenance, Ericsson wanted a better way of developing their telecommunication systems.

The new language/technology had met –amongst others– the following requirements:

  • Support a large number of concurrent activities
  • Systems distributed over several computers
  • Fault tollerance both to hardware and software errors

In order to meet these requirements, the actor programming model based on processes that could only communicate using message passing was employed.

Maintaining strong isolation between processes is key in such a setting and the failure of one process should not affect others. In Erlang this works really well due to pure message passing instead of shared memory.

You cannot avoid making errors in software so you need a way for a process to know if another processes has failed and why, but must not cause the other process to fail. Such a cascade of failure should only occur if it was explicitly programmed that way.

Another key philosophical stance Erlang takes is fail fast – if a process does not know what to do it should just die and let some other process take care of the problem. This is possible because processes can link or monitor other processes and thereby know if they have failed. This has two major benefits:

  1. The failing code and the error-handling code runs in different threads of control
  2. The code which deals with the error is not weaved into the code that solves the real problem

This makes the code a lot cleaner and easier to maintain.

Erlang comes with a library called OTP that is a set of generic components built on these principles. The main benefit of using OTP is that it separates the concurrent parts of the code from the sequential parts, which are often easier to code and understand.

What is Erlang good for?

Apart from the telecommunications domain, Erlang is good for a lot of things as long as there is a good match with the original requirements of Erlang. Today Erlang is celebrating successes in areas such as instant messaging (ejabberd), message queues (RabbitMQ for AMQP), web servers (YAWS), gaming (Wooga, Machine Zone, Blizzard) as well as NoSQL databases (Riak, CouchDB).

But Erlang’s heritage in distributed systems actually makes it a good technology for multi-core as well. The Erlang Virtual Machine and the language is built in a way such that it is transparent where there processes are – you just need to know the PIDs (Process Identifiers) for a process in order to send messages to it and that’s all. You don’t need to worry about where the process is – it could be on your core, a different core or on a different machine.

This is extremely powerful and makes it easier to write programs that scales well when more cores are added. The key point is that it makes it easier, not trivial. You still have to write the program so that it has good concurrency and parallelism in its structure. It is easier to get this right in Erlang then if you have to deal with threads.

The next steps

We have received an Epiphany Multicore Evaluation Kit and once we have it up and running, our intrepid hackers will start exploring the possibilities of incorporating the Epiphany chip as a co-processor to Erlang.

In the next blog post, we will delve into utilising OpenCL from within an Erlang node in the hope of helping those who are interested in trying to code applications which benefit from data parallelism.

Getting started with Erlang

You don’t need to wait for your Parallella board to arrive to get started with Erlang, head over to our downloads page to download packages for your operating system of choice and have a look at the official documentation or the wonderfully whimsical Learn You Some Erlang (for Great Good!) page to get started.

Please feel free to drop by the Erlang forum if you have any questions, we will be happy to help you get started!

Leave a Reply