[erlang-questions] Erlang newbie questions

Garrett Smith g@REDACTED
Tue Oct 18 00:27:14 CEST 2011

Hi Gerry,

On Mon, Oct 17, 2011 at 4:14 PM, Gerry Weaver <gerryw@REDACTED> wrote:
> I am new to Erlang and I'm trying to make the case to continue learning this language. I have read all of the books available and seen several presentations on the language. I am interested in Erlang primarily for the distributed and fault tolerant features it offers. However, I have some reservations about how useful this really is. For example, if you have a network server and the listener process fails, how do you recover? It seems that the fault tolerance is only applicable in the VM context. This is, in my mind equivalent to any other application process. If I have a network server written in C, I can have a watchdog process to kill and/or restart it in the event of failure. The C based approach actually seems more robust. In this scenario, how would one restart the Erlang VM? It has been my experience that network servers most often fail due to OS or hardware limits rather than
> bugs in the code (at least for thoroughly tested production ready code). When you factor in the amount of baggage that comes with Erlang, or any other VM based language, it's difficult to justify. Now there is also the rapid development aspect, but I'm finding that at least for now, the time savings is being eaten up by looking for documentation. I understand that this situation will improve over time, but the various posts I've seen from folks with more experience seem to indicate that this will take quite a while. I like the language (except the , ; . thing). You can do some pretty cool things with it, but when I got over that initial gee whiz, I had some trouble seeing a real world production use case. I'm not trying to be critical, I just figure I must have missed something along the way. Any perspectives or advice on this would be greatly appreciated.

You typically don't want to use Erlang's supervisory patterns across a
network. As you've observed, those are suited for a single VM.

Fail fast + watch dog patterns are indeed something you can implement
in any language. In Erlang, however, you have a finer level of
granularity of isolation. In a C program, your level of isolation is
the OS process. If that application encounters a fault, you need to
bring the entire OS process down and restart it. In Erlang, your
program can consist of hundreds of Erlang processes (or more) each
completely isolated from one another and free to crash / restart.
Because your level of isolation is more granular, a fault will have
relatively less impact on your system.

To answer your question, your don't restart the Erlang VM. Think of
the Erlang VM as an operating system for code and Erlang processes
like OS processes. It's the same basic architecture, but mapped to
application space.

Erlang's pattern matching semantics will let you write clear "happy
path" code without extra defensive or fail-fast code. In C you need to
constantly check results -- tedious and error prone. In Erlang, you
typically get the assertion for free in patterns like:

  {ok, F} = file:open(...)

Because process supervision comes with Erlang, you don't need
defensive code (e.g. gratuitous exception handlers or case statements)
-- if something unexpected happens, your code blows up, but gets
restarted in a known/clean state.

This results in much, much less code *and* improved fault tolerance!

Since you're new to Erlang, you're going to be more productive in any
other language at the moment. That will certainly change. In my
experience, Erlang is an extremely productive language -- I'll argue
more so than Python or Ruby. Sounds strange, but I've found that to be
the case.

Good luck!


More information about the erlang-questions mailing list