Jump to content

Programming Erlang


bascule

Recommended Posts

Erlang is slowly gaining in popularity. This will hopefully speed up soon, because the Pragmatic Programmers are releasing a book on it:

 

http://www.pragmaticprogrammer.com/titles/jaerlang/

 

What makes Erlang so awesome?

 

The Actor Model - Like objects, but they all run at the same time... across multiple CPU cores or multiple computers. Think of a language where every object is also a thread. Implicit parallelism!

 

Hot swappable code - Need to update one small part of a large application? Particularly a network service that a lot of people are connected to? Drop it in on-the-fly!

 

Network transparency - Throwing more CPUs at a program was never easier. Erlang can seamlessly distribute itself over a computing cluster.

 

I'm really excited about Erlang. I think concurrent programming is the future.

Link to comment
Share on other sites

Erlang programs consist of multiple "processes" which all run concurrently. These "processes" aren't OS processes or OS threads. They exist internally within Erlang's scheduler, which runs within a single thread.

 

However, recently Erlang gained the ability to run multiple schedulers at once. This means Erlang will start a seperate scheduler which runs inside an OS thread for each CPU core. Erlang processes can easily move between OS threads (because each one is shared-nothing), so if a single process starts monopolizing a CPU the other processes can move to a different core, just like how an OS scheduler schedules threads.

 

Essentially, it's a M:N threading model.

 

But it doesn't stop there! You can attach to Erlang interpreters on completely different computer systems and use those to automatically run processes. This idea is similar to an idea in Linux called Mosix where OS processes could transparently move to different computer systems. Erlang can do this with networked computer clusters, but the "processes" it's moving are substantially lighter weight than an actual OS process. Mosix's main problem was the cost of serializing an entire OS process to move it over the network, and then unserializing and restoring it on the other side.

 

With Erlang, the penalty is substantially reduced.

 

All-in-all, this approach means that using massively multicore computer systems, or even clusters, is all abstracted away. The approach to writing your Erlang program does not change. Erlang simply finds the best way to use the available resources. Furthermore, the problems that surround threads, like synchronization of shared resources (and the ensuing deadlocks that occur when this doesn't occur properly) are completely eliminated.

Link to comment
Share on other sites

And the lack of deadlocks and shared-nothing benefit are all due to the fact that cross-thread communication is done via message passing rather than explicitly shared memory? (not that on the same system message passing might not be facilitated by shared memory but that the concept may be abstracted so when things are moved onto different computers the same concept can be applied with sockets etc)

Link to comment
Share on other sites

And the lack of deadlocks and shared-nothing benefit are all due to the fact that cross-thread communication is done via message passing rather than explicitly shared memory?

 

Yep, but also some different programming conventions built around those ideas.

Link to comment
Share on other sites

Erlang bundles a fully distributed, production quality database called Mnesia. This can be used in lieu of a traditional RDBMs. Mnesia seems like the ideal way of handling globally shared mutable state in Erlang, and is apparently already being used for large telcom databases. (I haven't mentioned this earlier, but Erlang was originally designed to meet the needs of the telecommunications industry)

 

I'm sort of reluctant to talk about this because I know so little about Mnesia, such as whether it supports transactions/two-phase commit (or if this concept is even applicable to the way it's implemented)

 

Once I know a little more about it I can get back to you on this.

Link to comment
Share on other sites

Heh, the Erlang movie is hilarious. I remember reading that one of the people in it (I think the main "host" guy) absolutely loathed it and wish they never made it.

 

The guy committing the horrible fashion faux paus by wearing that striped sweater is Erlang's principal creator, iirc

 

However, if you can stand their stuttering and weird accents, it's a good introduction to Erlang's capabilities.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.