Erlang processes

They are like Lemmings

Mark Nijhof
Functional Erlang
Published in
2 min readMay 7, 2013

--

Coming from a .Net world, and lately Ruby and Node, I find it hard to imagine how you can just use a single process, only to maintain a single variable. For example, to keep and update a counter. But in Erlang this is what is possible and perfectly ok.

Processes in Erlang should be small and you can have many of them, and by many this could mean tens of thousands, on a single machine.

Today I heard an interesting explanation by Steve:

you can compare a process with for example a class in C#, but purely in a way that it should be small with one responsibility and that you would use multiple classes together to accomplish a single task

This helped me understand the scope of an Erlang process, because my first thought was that a process is something like a thread, but they are nothing like that. Instead they are a encapsulation mechanism.

Nothing outside a process can touch anything inside a process, the only thing you can do to interact with a process is send it a message and wait for a reply, which is optional btw.

Oh an other thing you can do is monitor them, which means that when a process crashes you get notified, or also get taken down. It is funny that way.

Processes are cheap to create, and thus there is no need to keep them around, unless you want to preserve some state (more on that in a later post). So once you are done with it, you let them die (well I guess the better way to say this is that you stop the process).

Lemmings

So I came to conclude that a simple way to explain what Erlang processes are, is to say that they are like Lemmings.

  • Lemmings are small, they could be tiny
  • You would have many of them, almost like; the more, the better
  • You give them a simple task, and then an other simple task
  • If they don’t serve a purpose anymore you let them die
  • It is ok for a Lemming to crash, just give the task to the next one

Photo credit: http://world-of-games.co.uk/Vintage%20Computer/album/Lemmings.jpg

--

--