[erlang-questions] node.js compared to erlang

David Mercer dmercer@REDACTED
Thu Oct 7 16:13:23 CEST 2010

I might be the only person in the world whose two favorite languages are
Javascript and Erlang.  I had been writing full-blown server-side Javascript
applications for 5 or 6 years until I discovered Erlang in '07.  What had
attracted me to Javascript was the ability to replace code on the fly (for
instance, by loading the file into a string and eval-ing it).  For
distribution (the application was distributed over about 20 machines
internally with about 100 additional smaller-scale remote servers
communicating with the central hub), I used the file system and TCP (and
HTTP for negotiating across firewalls), depending on the requirements.  (I
had also originally used MSMQ, but we phased that out over time in favor of
more expedient methods that we developed ourselves.)  The end result was a
less robust version of an Erlang application, that worked pretty well.  We
had hot code loading, and redundancy gave us the fault-tolerance we

When I discovered Erlang in 2007 (not sure why it took me that long), I
immediately recognized that Erlang was built to handle all the problems we
had written around, but it had a longer history and was certainly better at
it.  We had required so much of our redundancy (20 machines running about 7
processes each) not only to handle the load, but also to handle failures.
Windows Script Host, which was our Javascript engine, is not as stable as
you might think, and seemed to suffer from memory leaks which manifested
itself over time.  With 20 machines times 7 processes per machine and an
MTBF of, say, a week, we had 10 or 20 failures a day (which were
automatically handled).  Honestly, the surprise for us was that WSH
performed as well as it did.  We had originally written our application in
Javascript/WSH as a prototype, intending to rewrite in C/C++/Java/something
else when we had completed our proof of concept.  But as it turned out,
processing speed wasn't really an issue for us -- network latency was
usually the limiting issue, not CPU.  However, it was surprising to us that
WSH could, at times, run for days or weeks, processing millions of
transactions before failing.  WSH's multi-threading capabilities are
nonexistent, and I tried various hacks to coax it into running multiple
threads, but they tended to cause other problems (as you can imagine), so I
wrote my own scheduler that time-sliced between various tasks.  (It was
actually a heap-based priority queue.)  We isolated blocking operations (the
main issue we had with blocking was that some asynchronous SQL queries were
not working right, so we had to do them synchronously) in their own process
so that they wouldn't block other tasks.

However, Erlang does everything we wrote, and it does it better.  Having
written an equivalent system in a non-Erlang language, I really appreciate
all the tools Erlang gives you to create manageable distributed server-side
applications.  Besides the interprocess messaging and hot code-loading, OTP
is an excellent way of thinking about and framework for building your
fault-tolerant servers.  I did not know about Erlang and OTP when I started
writing server-side Javascript, but if I had, I would have begun by
rewriting Erlang and OTP (e.g., gen_server) in Javascript.  It would have
created a much better architecture, though it is not clear why I would write
such a system in Javascript if I knew about Erlang.  Node.js is only a small
step up from WSH in that it is more portable and has better support for
multi-tasking.  I suspect you would find yourself rewriting a lot of
Erlang/OTP in Javascript if you decided to build in Node.js your own
server-side applications.

That being said, as an old Javascript warrior myself, I'd be interested to
hear how it goes.  I, too, have considered trying out Node.js as my New
Favorite Platform(TM), but haven't yet had the need.  Today, I haven't done
much programming in Javascript in a couple of years, but I gotta admit, as a
language, it is very highly capable.  I daresay, there was a time, 5-10
years ago, when I considered myself one of the best Javascript programmers
in the world, and I would sometimes log into Experts Exchange or somewhere
like that to help out, only to be dismayed that the Javascript questions
were not about the language Javascript, but about manipulating the DOM in a
web page.  No-one ever seemed to ask the tricky questions about closures or
object context, or performance of certain approaches etc. that was my
expertise.  You see more of that nowadays, as most of these concepts have
gained traction in the mainstream; now there are probably tens of thousands
of people with that knowledge, not just the hundreds of a few years ago.

Thank-you for this walk down memory lane.  Let me know how it goes with
Node.js.  I just might have to try it out...



> -----Original Message-----
> From: erlang-questions@REDACTED [mailto:erlang-questions@REDACTED] On
> Behalf Of Pablo Platt
> Sent: Sunday, October 03, 2010 10:01 AM
> To: erlang-questions@REDACTED
> Subject: [erlang-questions] node.js compared to erlang
> Hi
> I'm using erlang and I love it.
> I'm not trying to create an argument but to better understand the power of
> erlang.
> In what areas erlang dominates and what areas will you consider using
> node.js?
> For example, would you consider building something like rabbitmq or
> ejabberd in
> node.js?
> Or maybe you'll use node.js just for a simple single chat room but erlang
> for
> anything complicated than that.
> Are there a fundamental differences in performance or stability or use in
> distributed systems?
> Ulf Wiger commented on the comparison of erlang and node.js
> and said that erlang solves the problem of non blocking functions which
> might be
> very hard for other languages.
> http://journal.dedasys.com/2010/04/29/erlang-vs-node-js
> Thanks

More information about the erlang-questions mailing list