[erlang-questions] node.js vs erlang

John Kemp john@REDACTED
Tue Jun 17 15:17:54 CEST 2014


On 06/17/2014 08:41 AM, Joe Armstrong wrote:
>

[...]

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

I would note that it is possible to show that node is not as easy to 
program as Erlang without measuring performance.

It is possible to do so by reading any node code that uses nested 
callbacks (pretty much any example) vs. reading equivalent Erlang code.

In the node case, it is not easy to follow the flow of the code by 
reading it (ie. in which order the callbacks will fire) leading to many 
mistakes in programming which do not show up until a particular ordering 
of activities occurs.

By contrast with Erlang, it is usually (in my experience) easy to follow 
the flow of code by reading it. This leads to easier verification of 
"correctness" too.

Just write a piece of non-blocking event-driven node code which 
implements more than one callback function, where callbacks may be 
nested. Then write the same code in Erlang. Which is easier to read? Is 
it even possible to verify the correctness of the node code in all cases?

Regards,

- johnk

>
> Cheers
>
> /Joe
>
>
>
>
>
>     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
>
>     There are various attempts at implementing fibers and lightweight
>     threads
>     in Node.js (eg: 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!
>
>     Cheers,
>
>     Darach.
>
>
>     On Tue, Jun 17, 2014 at 12:48 PM, Joe Armstrong <erlang@REDACTED
>     <mailto:erlang@REDACTED>> wrote:
>
>
>
>
>         On Tue, Jun 17, 2014 at 1:00 PM, Greg Young
>         <gregoryyoung1@REDACTED <mailto:gregoryyoung1@REDACTED>> wrote:
>
>             Are you testing against single threaded node or one of the
>             clustered versions or multiple processes or?
>
>
>
>         Single threaded
>
>         /Joe
>
>             On Tue, Jun 17, 2014 at 1:19 PM, Joe Armstrong
>             <erlang@REDACTED <mailto:erlang@REDACTED>> wrote:
>
>
>
>                 On Tue, Jun 17, 2014 at 12:10 PM, Greg Young
>                 <gregoryyoung1@REDACTED
>                 <mailto: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 :-)
>
>                 /Joe
>
>
>
>
>
>
>                     On Mon, Jun 16, 2014 at 5:55 PM, Juan Facorro
>                     <juan.facorro@REDACTED
>                     <mailto: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.
>
>                         HTH,
>
>                         J
>
>                         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 http://127.0.0.1:8124/fib?n=2
>                             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'});
>                                  res.end(result.toString());
>                             }).listen(8124, "127.0.0.1");
>
>                             console.log('Server running at
>                             http://127.0.0.1:8124/');
>
>                             -- end
>
>                             -- now we run it
>
>                             $ node fib.js
>                             Server running at http://127.0.0.1:8124/
>                             fib(2)= 2
>
>                             /home/ejoearm/Dropbox/__experiments/hello_world/fib.__js:5
>                             function fib(n) {
>                                          ^
>                             RangeError: Maximum call stack size exceeded
>
>                             fib(2) has run out of stack space????
>
>                             $ node --version
>                             v0.8.21
>
>                             Any ideas what I'm doing wrong
>
>                             Cheers
>
>                             /Joe
>
>
>
>
>
>
>                         --
>                         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
>                         erlang-programming+unsubscribe@REDACTED
>                         <mailto:erlang-programming+unsubscribe@REDACTED>.
>                         To post to this group, send email to
>                         erlang-programming@REDACTED
>                         <mailto:erlang-programming@REDACTED>.
>                         Visit this group at
>                         http://groups.google.com/group/erlang-programming.
>                         For more options, visit
>                         https://groups.google.com/d/optout.
>
>
>
>
>                     --
>                     Studying for the Turing test
>
>
>
>
>
>             --
>             Studying for the Turing test
>
>
>
>         _______________________________________________
>         erlang-questions mailing list
>         erlang-questions@REDACTED <mailto:erlang-questions@REDACTED>
>         http://erlang.org/mailman/listinfo/erlang-questions
>
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list