88

I really like these tools when it comes to the concurrency level it can handle.

Erlang/OTP looks like much more stable solution but requires much more learning and a lot of diving into functional language paradigm. And it looks like Erlang/OTP makes it much better when it comes to multi-core CPUs (correct me if I am wrong).

But which should I choose? Which one is better in the short and long term perspective?

My goal is to learn a tool which makes scaling my Web projects under high load easier than traditional languages.

2240
  • 1,547
  • 2
  • 12
  • 30
user80805
  • 6,088
  • 5
  • 28
  • 31
  • You can use JavaScript as a functional language with http://underscorejs.org/ – Todd Moses Nov 04 '13 at 15:02
  • 2
    @ToddMoses are you sure you commented the right question ? – Flavien Volken Dec 27 '14 at 22:10
  • 2
    Apples and Oranges. Node.JS (at its core) is libevent (C) + Javascript interop. Erlang is a totally custom IO implementation. Node.JS is made for single threaded apps. Your delema is do you want a job at Facebook/Google, or do you want to make kickass software. – Vans S Feb 15 '16 at 22:27
  • @VansS Kickass, of course. But I'm not so sure if Erlang would be as fast as a JS based backend. An Erlang process works on a copy of data it's passed, to play it safe. And copying takes time (relative to references). Can an Erlang-based Electronic Medical Record application (basically, an enterrprise app) handle 1000 concurrent users in a hospital? If yes, I'd like to recommend to my boss to start porting our legacy, JavaEE based EMR app to Erlang :-) – Harry May 25 '21 at 08:26

9 Answers9

87

I would give Erlang a try. Even though it will be a steeper learning curve, you will get more out of it since you will be learning a functional programming language. Also, since Erlang is specifically designed to create reliable, highly concurrent systems, you will learn plenty about creating highly scalable services at the same time.

Justin Ethier
  • 131,333
  • 52
  • 229
  • 284
  • 10
    I don't think Erlang is a bit more complex than Javascript. There is no any type of inheritance in Erlang, so you are always sure what function you call. There is no implicit type conversion in Erlang, so you are always sure what types of data you use. There is no destructive assignment so you are always sure you won't have some old piece of code broken because some new code in callback changed your internal state. – Dmitry Belyaev Mar 02 '13 at 00:06
51

I can't speak for Erlang, but a few things that haven't been mentioned about node:

  • Node uses Google's V8 engine to actually compile javascript into machine code. So node is actually pretty fast. So that's on top of the speed benefits offered by event-driven programming and non-blocking io.
  • Node has a pretty active community. Hop onto their IRC group on freenode and you'll see what I mean
  • I've noticed the above comments push Erlang on the basis that it will be useful to learn a functional programming language. While I agree it's important to expand your skillset and get one of those under your belt, you shouldn't base a project on the fact that you want to learn a new programming style
  • On the other hand, Javascript is already in a paradigm you feel comfortable writing in! Plus it's javascript, so when you write client side code it will look and feel consistent.
  • node's community has already pumped out tons of modules! There are modules for redis, mongodb, couch, and what have you. Another good module to look into is Express (think Sinatra for node)

Check out the video on yahoo's blog by Ryan Dahl, the guy who actually wrote node. I think that will help give you a better idea where node is at, and where it's going.

Keep in mind that node still is in late development stages, and so has been undergoing quite a few changes—changes that have broke earlier code. However, supposedly it's at a point where you can expect the API not to change too much more. So if you're looking for something fun, I'd say node is a great choice.

Jarsen
  • 7,432
  • 6
  • 27
  • 26
  • 26
    I think the V8 engine compile JavaScript to machine code and not to assembly. – Jonas Apr 12 '11 at 12:08
  • 11
    Having so much work done around Javascript doesn't make the language even a bit suited for solving complex problems. The language itself is awful with all those special cases in types conversion. And callback style where variables are changed in hundreds of different places and the hell with looking for the place where some assignment has occured. – Dmitry Belyaev Mar 01 '13 at 23:55
15

I'm a long-time Erlang programmer, and this question prompted me to take a look at node.js. It looks pretty damn good.

It does appear that you need to spawn multiple processes to take advantage of multiple cores. I can't see anything about setting processor affinity though. You could use taskset on linux, but it probably should be parametrized and set in the program.

I also noticed that the platform support might be a little weaker. Specifically, it looks like you would need to run under Cygwin for Windows support.

Looks good though.


Edit

Node.js now has native support for Windows.

dsmith
  • 1,978
  • 10
  • 16
  • 5
    This answer is a little bit old. Right now Node is cross-platform, no need to have Cygwin for windows. And Node has built-in support for clustering in one machine, sharing the TCP sockets. – Farid Nouri Neshat Jul 15 '12 at 05:06
9

I'm looking at the same two alternatives you are, gotts, for multiple projects.

So far, the best razor I've come up with to decide between them for a given project is whether I need to use Javascript. One existing system I'm looking to migrate is already written in Javascript, so its next version is likely to be done in node.js. Other projects will be done in some Erlang web framework because there is no existing code base to migrate.

Another consideration is that Erlang scales well beyond just multiple cores, it can scale to a whole datacenter. I don't see a built-in mechanism in node.js that lets me send another JS process a message without caring which machine it is on, but that's built right into Erlang at the lowest levels. If your problem isn't big enough to need multiple machines or if it doesn't require multiple cooperating processes, this advantage isn't likely to matter, so you should ignore it.

Erlang is indeed a deep pool to dive into. I would suggest writing a standalone functional program first before you start building web apps. An even easier first step, since you seem comfortable with Javascript, is to try programming JS in a more functional style. If you use jQuery or Prototype, you've already started down this path. Try bouncing between pure functional programming in Erlang or one of its kin (Haskell, F#, Scala...) and functional JS.

Once you're comfortable with functional programming, seek out one of the many Erlang web frameworks; you probably shouldn't be writing your app directly to something low-level like inets at this late stage. Look at something like Nitrogen, for instance.

Warren Young
  • 40,875
  • 8
  • 85
  • 101
  • 1
    It often goes unmentioned that the "Erlang scales to a whole datacenter" point has some very important catches to consider (security is a big one). Check out the chapter on this here: http://learnyousomeerlang.com/distribunomicon – jocull Jan 14 '15 at 16:09
9

While I'd personally go for Erlang, I'll admit that I'm a little biased against JavaScript. My advice is that you evaluate few points:

  1. Are you reusing existing code in either of those languages (both in terms of source code, and programmer experience!)
  2. Do you need/want on-the-fly updates without stopping the application (This is where Erlang wins by default - its runtime was designed for that case, and OTP contains all the tools necessary)
  3. How big is the expected traffic, in terms of separate, concurrent operations, not bandwidth?
  4. How "parallel" are the operations you do for each request?

Erlang has really fine-tuned concurrency & network-transparent parallel distributed system. Depending on what exactly is the project, the availability of a mature implementation of such system might outweigh any issues regarding learning a new language. There are also two other languages that work on Erlang VM which you can use, the Ruby/Python-like Reia and Lisp-Flavored Erlang.

Yet another option is to use both, especially with Erlang being used as kind of "hub". I'm unsure if Node.js has Foreign Function Interface system, but if it has, Erlang has C library for external processes to interface with the system just like any other Erlang process.

p_l
  • 1,179
  • 8
  • 17
  • According to the docs, Node.js can leverage C and C++ for external addons. http://nodejs.org/docs/v0.3.1/api/addons.html – Evan Plaice Jan 24 '12 at 21:13
  • Looks like Reia has died, but in its place is [elixir](https://github.com/elixir-lang/elixir)... it reminds me of Groovy and Java; here it would be Elixir and Erlang. – stommepoes Mar 06 '12 at 14:28
  • @EvanPlaice - That doesn't impress me much. The thing is, you're basically coding a problematic thing in C++ and add them as built-ins. Not much of a FFI is what you're actually doing is extending the emulator. (Okay, personal preference ;)) The mentioned external library in erlang's case is to make async processes in other languages that show up as nodes OR that talk over an open port (think bi-directional pipe, with structured data). All that fits nicely into async mode of operation. There are also NIFs, which is essentially what Node.js has, but are discouraged. – p_l Mar 08 '12 at 22:48
  • 1
    @p_l From what I understand, the node approach is slightly different. While node is very good at handling async IO calls (ie web requests) it runs in a single-threaded environment. So it's great at dispatching but not so good at CPU-intensive processing. To cover that ground you can fork off another process/thread that runs native C/C++ code. If all you're doing is async IO calls (ex IPC | bi-directional pipes) then node.js should be able to handle the load. As long as it isn't coded to spend a lot of time waiting on synchronous calls. – Evan Plaice Mar 08 '12 at 23:59
5

There is one more language on the same VM that erlang is -> Elixir

It's a very interesting alternative to Erlang, check this one out.

Also it has a fast-growing web framework based on it-> Phoenix Framework

NoDisplayName
  • 15,246
  • 12
  • 62
  • 98
5

It looks like Erlang performs better for deployment in a relatively low-end server (512MB 4-core 2.4GHz AMD VM). This is from SyncPad's experience of comparing Erlang vs Node.js implementations of their virtual whiteboard server application.

adib
  • 8,285
  • 6
  • 52
  • 91
  • 2
    Yes, node.js seems to be having a nasty memory leak problem. Node is rather new and experimental and neither JavaScript nor the V8 engine was designed for such server scenarios. Erlang, on the other hand was designed just for that from the bottom up and had many years to refine itself and mature. – Rolf Nov 17 '11 at 18:32
  • 2
    That link seems dead but here it is on WayBackMachine http://web.archive.org/web/20120902014555/http://blog.mysyncpad.com/post/2073441622/node-js-vs-erlang-syncpads-experience – jocull Nov 10 '13 at 19:55
3

whatsapp could never achieve the level of scalability and reliability without erlang https://www.youtube.com/watch?v=c12cYAUTXXs

Henry H.
  • 901
  • 8
  • 11
0

I will Prefer Erlang over Node. If you want concurrency, Node can be substituted by Erlang or Golang because of their light weight processes.

Erlang is not easy to learn so requires a lot of effort but its community is active so can get help from that, this is only the reason why people prefer Node .