[erlang-questions] node.js vs erlang

Ivan Carmenates García co7eb@REDACTED
Wed Jun 18 07:49:13 CEST 2014

Hi all, 


Paulo F. Oliveira says: “…At the moment, though, I enjoy prototyping with Node.js and implementing with Erlang. :)…”


Yes Paulo, I definely think that it is what nodejs is about, it is very nice to prototyping things because of the code, easily to understand and program; a different way of thinking (no so nice like Erlang but.. still..), but noting seriously such as what you can do with Erlang you can build with nodejs I think.








De: erlang-questions-bounces@REDACTED [mailto:erlang-questions-bounces@REDACTED] En nombre de Paulo F. Oliveira
Enviado el: martes, 17 de junio de 2014 09:07 a.m.
Para: Joe Armstrong
CC: Greg Young; Juan Facorro; Erlang; erlang-programming@REDACTED
Asunto: Re: [erlang-questions] node.js vs erlang


"Node is very popular so I'm trying to understand what it is about node that is attractive."


Having recently moved from Node.js (JavaScript really) to Erlang, a few things come to mind:

1. a lot of browser frontend (i.e. JavaScript) developers almost don't have to learn anything new to develop server-side code using Node.js

2. npm (for sure) is one of the best package management systems I've used... really simple (oh, and the fact that you can use specific versions of deps in your app and not be restricted by a previous choice, sure helps a lot)

3.  <http://npmjs.org> npmjs.org :D

4. the debugger (node-inspector): I miss this :(

5. you can share server-side and browser-side code


On the other hand, for high concurrency, I wouldn't recommend it (it's heavy when you have to spawn a few thousand processes to do _parallel_ and then the OS can't easily cope with this), as it's single threaded (ok, there's Cluster, but...). And also, the fact that tail recursion is non-existing...


At the moment, though, I enjoy prototyping with Node.js and implementing with Erlang. :)


- Paulo F. Oliveira


On 17 June 2014 13:41, Joe Armstrong < <mailto:erlang@REDACTED> erlang@REDACTED> wrote:


On Tue, Jun 17, 2014 at 2:05 PM, Darach Ennis < <mailto:darach@REDACTED> darach@REDACTED> wrote:

Hi all,


For this to be comparable both Erlang and Node.js need to be running

similarly. I don't see how a concurrent Erlang runtime with multiple schedulers

can be compared with a single-threaded Node.js implementation objectively or




It's actually the programming models I want to compare and not the

performance - what worries me about node is the run-to-completion

semantics of event callbacks - namely that a long-running event will block

the server preventing short computations from being performed. The

short jobs which could be done immediately have to wait until the long jobs

have finished - this should reflect in the average latencies of a request.


I made a little experiment (a fibonacci server in erlang and node) and fired off

1000 parallel requests to compute fib(N) with N a random number from 10..40.


As I suspected many of the fib(10) events are blocked by ongoing computation of

fib(40) - this reflect in the latencies.


Node is about 1.6 times faster than Erlang - but the latencies for small computations

are terrible - Erlang never blocks so the response times are more predictable.


And yes I know that fib can be offloaded to a background processor or parallelised

in JS with a bit of black magic - but manually converting a long lived computation into

a re-entrant non-blocking version is very difficult.


The node books say something like "make sure that callbacks run-to-completion quickly"

I would say that complying with this advice is extremely difficult. It's very difficult to guess

which computations will take a long time, and even if you know it's difficult to break them into

small re-entrant chunks.


Node is very popular so I'm trying to understand what it is about node that is attractive.

npm for example, looks well engineered and something we could learn from. The node

web servers are easy to setup and run, so I'd like to see if we could make equally 

easy to use Erlang servers.


Performance is not a primary concern - easy of programming and correctness are.











Using node cluster with the same number of cluster instances as erlang

schedulers might be a fairer environment for comparison. However, as

numeric computations are fairly efficient in Node.js and inefficient in Erlang

relative to Java or C it may take a few iterations to get a fair comparison

in place. Node cluster is a standard part of node.js:


 <http://nodejs.org/api/cluster.html> http://nodejs.org/api/cluster.html


There are various attempts at implementing fibers and lightweight threads

in Node.js (eg:  <https://github.com/laverdet/node-fibers/> https://github.com/laverdet/node-fibers/) but there is nothing

common here. This would approximate an erlang runtime more closely at

the cost of deviating a little from a commonly found node runtime... Ho hum.


As javascript runtimes start to adopt vectorized instructions and other

optimisations their speed relative to a C baseline has and will continue to

steadily improve and has been for a number of years, especially with V8.


Good luck with the benchmarking!






On Tue, Jun 17, 2014 at 12:48 PM, Joe Armstrong < <mailto:erlang@REDACTED> erlang@REDACTED> wrote:



On Tue, Jun 17, 2014 at 1:00 PM, Greg Young < <mailto:gregoryyoung1@REDACTED> gregoryyoung1@REDACTED> wrote:

Are you testing against single threaded node or one of the clustered versions or multiple processes or?



Single threaded




On Tue, Jun 17, 2014 at 1:19 PM, Joe Armstrong < <mailto:erlang@REDACTED> erlang@REDACTED> wrote:


On Tue, Jun 17, 2014 at 12:10 PM, Greg Young < <mailto:gregoryyoung1@REDACTED> gregoryyoung1@REDACTED> wrote:

Can you really compare the two? :) 


Yes - there are many things we can measure. Performance, Latency, memory usage and so on.


Right now I'm measuring latency - 


I set up a few thousand parallel processes which request fib(N) and measure the latency of the responses.


the results will be published when I understand them :-)









On Mon, Jun 16, 2014 at 5:55 PM, Juan Facorro < <mailto:juan.facorro@REDACTED> juan.facorro@REDACTED> wrote:

Hi Joe,


There's a semicolon missing after the declaration of fib(), which for some reason, causes the stack overflow. After adding it the error went away.





On Monday, June 16, 2014 11:22:23 AM UTC-3, Joe Armstrong wrote:

I'm trying to compare node.js with erlang. I'm a total node.js novice BTW - but I've written some JS.


Program 1 is just fibonacci - I want a web server to compute fib(N)


So requesting  <> should compute and return fib(2)


My node.js attempt crashes

Here's the code in fib.js


--- fib.js


var http = require('http');

var url  = require('url');


function fib(n) {

  if (n < 2) {

    return 1;

  } else {

    return fib(n - 2) + fib(n - 1);




http.createServer(function (req, res) {

    var q = url.parse(req.url, true).query;

    var n = q.n;

    var result = fib(n);

    console.log('fib('+ n + ')= '+result);

    res.writeHead(200, {'Content-Type': 'text/plain'});


}).listen(8124, "");


console.log('Server running at  <'>');


-- end


-- now we run it


$ node fib.js

Server running at  <>

fib(2)= 2



function fib(n) {


RangeError: Maximum call stack size exceeded


fib(2) has run out of stack space????


$ node --version



Any ideas what I'm doing wrong











Remember to send a copy to erlang (dot) questions (at) erlang (dot) org when posting.
You received this message because you are subscribed to the Google Groups "Erlang Programming" group.
To unsubscribe from this group and stop receiving emails from it, send an email to  <mailto:erlang-programming+unsubscribe@REDACTED> erlang-programming+unsubscribe@REDACTED
To post to this group, send email to  <mailto:erlang-programming@REDACTED> erlang-programming@REDACTED
Visit this group at  <http://groups.google.com/group/erlang-programming> http://groups.google.com/group/erlang-programming.
For more options, visit  <https://groups.google.com/d/optout> https://groups.google.com/d/optout.



Studying for the Turing test




Studying for the Turing test



erlang-questions mailing list
 <mailto:erlang-questions@REDACTED> erlang-questions@REDACTED
 <http://erlang.org/mailman/listinfo/erlang-questions> http://erlang.org/mailman/listinfo/erlang-questions



erlang-questions mailing list
 <mailto:erlang-questions@REDACTED> erlang-questions@REDACTED
 <http://erlang.org/mailman/listinfo/erlang-questions> http://erlang.org/mailman/listinfo/erlang-questions


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140618/e0aea9c4/attachment.htm>

More information about the erlang-questions mailing list