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