<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt"><div class="" style=""><span class="" style=""><br style=""></span></div><div class="" style=""><div class="" style=""><span class="" style="">A couple of years ago, I had a BSc student implement a simple but realistic web service (realistic enough to be a replacement for one we were using in production), in Ruby, Node and Erlang. Ruby was slowest, as expected. Overall, Erlang beat Node. In particular, while they were roughly the same "best" performance, Node had a much greater variation in response latency.</span></div><div class="" style="background-color: transparent;"><br clear="none" class="" style=""></div><div class="" style="background-color: transparent;"><span class="" style="">Best,</span></div><div class="" style="background-color: transparent;"><span class=""
style="">Thomas</span></div><div class="" style=""><span class="" style=""><br class="" style=""></span></div><br class="" style=""></div> <div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 10pt;" class=""> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt;" class=""> <div dir="ltr" class="" style=""> <font size="2" face="Arial" class="" style=""> On Tuesday, June 17, 2014 10:06 PM, Thomas Lindgren <thomasl_erlang@yahoo.com> wrote:</font></div><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;" class=""><div class="" style=""><div id="yiv0018815628" class="" style=""><div class="" style=""><div style="color:#000;background-color:#fff;font-family:HelveticaNeue,
Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt;" class=""><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="display:block;"> <div style="font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:10pt;" class=""> <div style="font-family:HelveticaNeue, 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;font-size:12pt;" class=""> <div class="" id="yiv0018815628yqt33335" style=""><div dir="ltr" class="" style=""> <font size="2" face="Arial" class="" style=""> On Tuesday, June 17, 2014 2:41 PM, Joe Armstrong <erlang@gmail.com> wrote:<br clear="none" class="" style=""> </font> </div>
<blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;margin-top:5px;padding-left:5px;" class=""> <br clear="none" class="" style=""><br clear="none" class="" style=""> <div class="" style=""><div id="yiv0018815628" class="" style=""><div class="" style=""><div dir="ltr" class="" style=""><div class="" style=""><br clear="none" class="" style=""><div class="" style="">On Tue, Jun 17, 2014 at 2:05 PM, Darach Ennis <span dir="ltr" class="" style=""><<a rel="nofollow" shape="rect" ymailto="mailto:darach@gmail.com" target="_blank" href="mailto:darach@gmail.com" class="" style="">darach@gmail.com</a>></span> wrote:<br clear="none" class="" style="">
<blockquote class="" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div dir="ltr" class="" style="">Hi all,<div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">For this to be comparable both Erlang and Node.js need to be running</div><div class="" style="">
similarly. I don't see how a concurrent Erlang runtime with multiple schedulers</div><div class="" style="">can be compared with a single-threaded Node.js implementation objectively or</div>
<div class="" style="">fairly...</div><div class="" style=""><br clear="none" class="" style=""></div></div></blockquote><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">It's actually the programming models I want to compare and not the</div><div class="" style="">performance - what worries me about node is the run-to-completion</div>
<div class="" style="">semantics of event callbacks - namely that a long-running event will block</div><div class="" style="">the server preventing short computations from being performed. The</div><div class="" style="">short jobs which could be done immediately have to wait until the long jobs</div>
<div class="" style="">have finished - this should reflect in the average latencies of a request.</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">I made a little experiment (a fibonacci server in erlang and node) and fired off</div><div class="" style="">1000 parallel requests to compute fib(N) with N a random number from 10..40.</div>
<div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">As I suspected many of the fib(10) events are blocked by ongoing computation of</div><div class="" style="">fib(40) - this reflect in the latencies.</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">Node is about 1.6 times faster than Erlang - but the latencies for small computations</div>
<div class="" style="">are terrible - Erlang never blocks so the response times are more predictable.</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">And yes I know that fib can be offloaded to a background processor or parallelised</div><div class="" style="">in JS with a bit of black magic - but manually converting a long lived computation into</div>
<div class="" style="">a re-entrant non-blocking version is very difficult.</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">The node books say something like "make sure that callbacks run-to-completion quickly"</div><div class="" style="">I would say that complying with this advice is extremely difficult. It's very difficult to guess</div>
<div class="" style="">which computations will take a long time, and even if you know it's difficult to break them into</div><div class="" style="">small re-entrant chunks.</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">Node is very popular so I'm trying to understand what it is about node that is attractive.</div>
<div class="" style="">npm for example, looks well engineered and something we could learn from. The node</div><div class="" style="">web servers are easy to setup and run, so I'd like to see if we could make equally </div><div class="" style="">easy to use Erlang servers.</div>
<div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">Performance is not a primary concern - easy of programming and correctness are.</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">Cheers</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">/Joe</div><div class="" id="yiv0018815628yqtfd15904" style=""><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""><br clear="none" class="" style="">
</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""> </div><blockquote class="" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div dir="ltr" class="" style=""><div class="" style=""></div><div class="" style="">Using node cluster with the same number of cluster instances as erlang</div><div class="" style="">schedulers might be a fairer environment for comparison. However, as</div><div class="" style="">numeric computations are fairly efficient in Node.js and inefficient in Erlang</div>
<div class="" style="">relative to Java or C it may take a few iterations to get a fair comparison</div><div class="" style="">in place. Node cluster is a standard part of node.js:</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""><a rel="nofollow" shape="rect" target="_blank" href="http://nodejs.org/api/cluster.html" class="" style="">http://nodejs.org/api/cluster.html</a><br clear="none" class="" style="">
</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">There are various attempts at implementing fibers and lightweight threads</div><div class="" style="">in Node.js (eg: <a rel="nofollow" shape="rect" target="_blank" href="https://github.com/laverdet/node-fibers/" class="" style="">https://github.com/laverdet/node-fibers/</a>) but there is nothing</div>
<div class="" style="">common here. This would approximate an erlang runtime more closely at</div><div class="" style="">the cost of deviating a little from a commonly found node runtime... Ho hum.</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">As javascript runtimes start to adopt vectorized instructions and other</div>
<div class="" style="">optimisations their speed relative to a C baseline has and will continue to</div><div class="" style="">steadily improve and has been for a number of years, especially with V8.</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">Good luck with the benchmarking!</div>
<div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">Cheers,</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">Darach.</div></div><div class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style=""><div class="" style=""><div class="" style=""><div class="" style="">On Tue, Jun 17, 2014 at 12:48 PM, Joe Armstrong <span dir="ltr" class="" style=""><<a rel="nofollow" shape="rect" ymailto="mailto:erlang@gmail.com" target="_blank" href="mailto:erlang@gmail.com" class="" style="">erlang@gmail.com</a>></span> wrote:<br clear="none" class="" style="">
</div></div><blockquote class="" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="" style=""><div class="" style=""><div dir="ltr" class="" style=""><br clear="none" class="" style=""><div class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style=""><div class="" style="">On Tue, Jun 17, 2014 at 1:00 PM, Greg Young <span dir="ltr" class="" style=""><<a rel="nofollow" shape="rect" ymailto="mailto:gregoryyoung1@gmail.com" target="_blank" href="mailto:gregoryyoung1@gmail.com" class="" style="">gregoryyoung1@gmail.com</a>></span> wrote:<br clear="none" class="" style="">
<blockquote class="" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div dir="ltr" class="" style="">Are you testing against single threaded node or one of the clustered versions or multiple processes or?</div>
<div class="" style=""><div class="" style=""><div class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style=""></div></div></div></blockquote><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">Single threaded</div><span class="" style=""><font color="#888888" class="" style=""></font></span><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">/Joe</div><div class="" style=""><div class="" style="">
<div class="" style=""> </div><blockquote class="" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="" style=""><div class="" style=""><div class="" style=""><div class="" style="">On Tue, Jun 17, 2014 at 1:19 PM, Joe Armstrong <span dir="ltr" class="" style=""><<a rel="nofollow" shape="rect" ymailto="mailto:erlang@gmail.com" target="_blank" href="mailto:erlang@gmail.com" class="" style="">erlang@gmail.com</a>></span> wrote:<br clear="none" class="" style="">
<blockquote class="" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div dir="ltr" class="" style=""><div class="" style=""><br clear="none" class="" style=""><br clear="none" class="" style=""><div class="" style=""><div class="" style="">On Tue, Jun 17, 2014 at 12:10 PM, Greg Young <span dir="ltr" class="" style=""><<a rel="nofollow" shape="rect" ymailto="mailto:gregoryyoung1@gmail.com" target="_blank" href="mailto:gregoryyoung1@gmail.com" class="" style="">gregoryyoung1@gmail.com</a>></span> wrote:<br clear="none" class="" style="">
<blockquote class="" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div dir="ltr" class="" style="">Can you really compare the two? :) </div></blockquote><div class="" style=""><br clear="none" class="" style=""></div></div><div class="" style="">Yes - there are many things we can measure. Performance, Latency, memory usage and so on.</div>
<div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">Right now I'm measuring latency - </div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">I set up a few thousand parallel processes which request fib(N) and measure the latency of the responses.</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">the results will be published when I understand them :-)</div>
<span class="" style=""><font color="#888888" class="" style="">
</font></span><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">/Joe</div><div class="" style=""><div class="" style=""><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""> </div><blockquote class="" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="" style="">
<br clear="none" class="" style=""><br clear="none" class="" style=""><div class="" style=""><div class="" style=""><div class="" style="">On Mon, Jun 16, 2014 at 5:55 PM, Juan Facorro <span dir="ltr" class="" style=""><<a rel="nofollow" shape="rect" ymailto="mailto:juan.facorro@gmail.com" target="_blank" href="mailto:juan.facorro@gmail.com" class="" style="">juan.facorro@gmail.com</a>></span> wrote:<br clear="none" class="" style="">
</div></div><blockquote class="" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="" style=""><div class="" style=""><div dir="ltr" class="" style="">Hi Joe,<div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">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.</div>
<div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">HTH,</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">J</div><div class="" style=""><br clear="none" class="" style="">On Monday, June 16, 2014 11:22:23 AM UTC-3, Joe Armstrong wrote:<blockquote class="" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div dir="ltr" class="" style=""><div class="" style="">I'm trying to compare node.js with erlang. I'm a total node.js novice BTW - but I've written some JS.</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">Program 1 is just fibonacci - I want a web server to compute fib(N)</div>
<div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">So requesting <a rel="nofollow" shape="rect" target="_blank" href="http://127.0.0.1:8124/fib?n=2" class="" style="">http://127.0.0.1:8124/fib?n=2</a> should compute and return fib(2)</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">My node.js attempt crashes</div><div class="" style="">Here's the code in fib.js</div>
<div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">--- fib.js</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""><div class="" style="">var http = require('http');</div><div class="" style="">var url = require('url');</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">function fib(n) {</div><div class="" style=""> if (n < 2) {</div><div class="" style="">
return 1;</div><div class="" style=""> } else {</div><div class="" style=""> return fib(n - 2) + fib(n - 1);</div><div class="" style=""> }</div><div class="" style="">}</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">http.createServer(function (req, res) {</div><div class="" style=""> var q = url.parse(req.url, true).query;</div>
<div class="" style=""> var n = q.n;</div><div class="" style=""> var result = fib(n);</div><div class="" style=""> console.log('fib('+ n + ')= '+result);</div><div class="" style=""> res.writeHead(200, {'Content-Type': 'text/plain'});</div><div class="" style=""> res.end(result.toString());</div>
<div class="" style="">}).listen(8124, "127.0.0.1");</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">console.log('Server running at <a rel="nofollow" shape="rect" target="_blank" href="http://127.0.0.1:8124/'" class="" style="">http://127.0.0.1:8124/'</a>);</div></div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">
-- end</div><div class="" style="">
<br clear="none" class="" style=""></div><div class="" style="">-- now we run it</div><div class="" style=""><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">$ node fib.js</div><div class="" style="">Server running at <a rel="nofollow" shape="rect" target="_blank" href="http://127.0.0.1:8124/" class="" style="">http://127.0.0.1:8124/</a></div><div class="" style="">fib(2)= 2</div><div class="" style=""><br clear="none" class="" style=""></div>
<div class="" style="">/home/ejoearm/Dropbox/<u class="" style=""></u>experiments/hello_world/fib.<u class="" style=""></u>js:5</div>
<div class="" style="">function fib(n) {</div><div class="" style=""> ^</div><div class="" style="">RangeError: Maximum call stack size exceeded</div></div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">fib(2) has run out of stack space????</div><div class="" style=""><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">$ node --version</div>
<div class="" style="">v0.8.21</div></div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">Any ideas what I'm doing wrong</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">Cheers</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style="">/Joe</div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""><br clear="none" class="" style=""></div><div class="" style=""><br clear="none" class="" style=""></div>
<div class="" style=""><br clear="none" class="" style=""></div></div><span class="" style=""><font color="#888888" class="" style="">
</font></span></blockquote></div></div></div></div><span class="" style=""><font color="#888888" class="" style=""><span class="" style=""><font color="#888888" class="" style="">
</font></span></font></span>
-- <br clear="none" class="" style="">
Remember to send a copy to erlang (dot) questions (at) erlang (dot) org when posting.<br clear="none" class="" style="">
--- <br clear="none" class="" style="">
You received this message because you are subscribed to the Google Groups "Erlang Programming" group.<br clear="none" class="" style="">
To unsubscribe from this group and stop receiving emails from it, send an email to <a rel="nofollow" shape="rect" ymailto="mailto:erlang-programming+unsubscribe@googlegroups.com" target="_blank" href="mailto:erlang-programming+unsubscribe@googlegroups.com" class="" style="">erlang-programming+unsubscribe@googlegroups.com</a>.<br clear="none" class="" style="">
To post to this group, send email to <a rel="nofollow" shape="rect" ymailto="mailto:erlang-programming@googlegroups.com" target="_blank" href="mailto:erlang-programming@googlegroups.com" class="" style="">erlang-programming@googlegroups.com</a>.<br clear="none" class="" style="">
Visit this group at <a rel="nofollow" shape="rect" target="_blank" href="http://groups.google.com/group/erlang-programming" class="" style="">http://groups.google.com/group/erlang-programming</a>.<br clear="none" class="" style="">
For more options, visit <a rel="nofollow" shape="rect" target="_blank" href="https://groups.google.com/d/optout" class="" style="">https://groups.google.com/d/optout</a>.<br clear="none" class="" style="">
</blockquote></div><span class="" style=""><font color="#888888" class="" style=""><br clear="none" class="" style=""><br clear="all" class="" style=""></font></span><div class="" style=""><br clear="none" class="" style=""></div>-- <br clear="none" class="" style=""><div dir="ltr" class="" style="">Studying for the Turing test</div>
</div>
</blockquote></div></div></div><br clear="none" class="" style=""></div></div>
</blockquote></div><br clear="none" class="" style=""><br clear="all" class="" style=""><div class="" style=""><br clear="none" class="" style=""></div>-- <br clear="none" class="" style=""><div dir="ltr" class="" style="">Studying for the Turing test</div>
</div>
</div></div></blockquote></div></div></div><br clear="none" class="" style=""></div></div>
<br clear="none" class="" style=""></div></div><div class="" style="">_______________________________________________<br clear="none" class="" style="">
erlang-questions mailing list<br clear="none" class="" style="">
<a rel="nofollow" shape="rect" ymailto="mailto:erlang-questions@erlang.org" target="_blank" href="mailto:erlang-questions@erlang.org" class="" style="">erlang-questions@erlang.org</a><br clear="none" class="" style="">
<a rel="nofollow" shape="rect" target="_blank" href="http://erlang.org/mailman/listinfo/erlang-questions" class="" style="">http://erlang.org/mailman/listinfo/erlang-questions</a><br clear="none" class="" style="">
<br clear="none" class="" style=""></div></blockquote></div><br clear="none" class="" style=""></div>
</blockquote></div></div><div class="" id="yiv0018815628yqtfd82162" style=""><br clear="none" class="" style=""></div></div></div></div></div><br clear="none" class="" style=""><div class="" id="yiv0018815628yqtfd34185" style="">_______________________________________________<br clear="none" class="" style="">erlang-questions mailing list<br clear="none" class="" style=""><a rel="nofollow" shape="rect" ymailto="mailto:erlang-questions@erlang.org" target="_blank" href="mailto:erlang-questions@erlang.org" class="" style="">erlang-questions@erlang.org</a><br clear="none" class="" style=""><a rel="nofollow" shape="rect" target="_blank" href="http://erlang.org/mailman/listinfo/erlang-questions" class="" style="">http://erlang.org/mailman/listinfo/erlang-questions</a><br clear="none" class="" style=""></div><br clear="none" class="" style=""><br clear="none" class="" style=""></div> </blockquote></div> </div> </div> </div> </div></div></div><br class=""
style=""><br class="" style=""></div> </blockquote> </div> </div> </div> </div></body></html>