<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jun 17, 2014 at 2:05 PM, Darach Ennis <span dir="ltr"><<a href="mailto:darach@gmail.com" target="_blank">darach@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<div><br></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></div></div></blockquote><div><br></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></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></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></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></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></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></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></div><div>Performance is not a primary concern - easy of programming and correctness are.</div><div><br></div><div>Cheers</div><div><br></div><div>/Joe</div><div><br></div><div><br></div><div><br></div><div><br>
</div><div><br></div><div> </div><blockquote class="gmail_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></div><div><a href="http://nodejs.org/api/cluster.html" target="_blank">http://nodejs.org/api/cluster.html</a><br>


</div><div><br></div><div>There are various attempts at implementing fibers and lightweight threads</div><div>in Node.js (eg: <a href="https://github.com/laverdet/node-fibers/" target="_blank">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></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></div><div>Good luck with the benchmarking!</div>


<div><br></div><div>Cheers,</div><div><br></div><div>Darach.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Tue, Jun 17, 2014 at 12:48 PM, Joe Armstrong <span dir="ltr"><<a href="mailto:erlang@gmail.com" target="_blank">erlang@gmail.com</a>></span> wrote:<br>


</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jun 17, 2014 at 1:00 PM, Greg Young <span dir="ltr"><<a href="mailto:gregoryyoung1@gmail.com" target="_blank">gregoryyoung1@gmail.com</a>></span> wrote:<br>



<blockquote class="gmail_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="gmail_extra"><br><br></div></div></div></blockquote><div><br></div><div>Single threaded</div><span><font color="#888888"><div><br></div><div>/Joe</div></font></span><div><div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><div class="gmail_extra"><div class="gmail_quote">On Tue, Jun 17, 2014 at 1:19 PM, Joe Armstrong <span dir="ltr"><<a href="mailto:erlang@gmail.com" target="_blank">erlang@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><br><br><div class="gmail_quote"><div>On Tue, Jun 17, 2014 at 12:10 PM, Greg Young <span dir="ltr"><<a href="mailto:gregoryyoung1@gmail.com" target="_blank">gregoryyoung1@gmail.com</a>></span> wrote:<br>





<blockquote class="gmail_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></div></div><div>Yes - there are many things we can measure. Performance, Latency, memory usage and so on.</div>





<div><br></div><div>Right now I'm measuring latency - </div><div><br></div><div>I set up a few thousand parallel processes which request fib(N) and measure the latency of the responses.</div><div><br></div><div>the results will be published when I understand them :-)</div>




<span><font color="#888888">
<div><br></div><div>/Joe</div></font></span><div><div><div><br></div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div class="gmail_extra">
<br><br><div class="gmail_quote"><div><div>On Mon, Jun 16, 2014 at 5:55 PM, Juan Facorro <span dir="ltr"><<a href="mailto:juan.facorro@gmail.com" target="_blank">juan.facorro@gmail.com</a>></span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">Hi Joe,<div><br></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></div><div>HTH,</div><div><br></div><div>J</div><div><br>On Monday, June 16, 2014 11:22:23 AM UTC-3, Joe Armstrong wrote:<blockquote class="gmail_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></div><div>Program 1 is just fibonacci - I want a web server to compute fib(N)</div>







<div><br></div><div>So requesting <a href="http://127.0.0.1:8124/fib?n=2" target="_blank">http://127.0.0.1:8124/fib?n=2</a> should compute and return fib(2)</div><div><br></div><div>My node.js attempt crashes</div><div>Here's the code in fib.js</div>







<div><br></div><div>--- fib.js</div><div><br></div><div><div>var http = require('http');</div><div>var url  = require('url');</div><div><br></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></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></div><div>console.log('Server running at <a href="http://127.0.0.1:8124/'" target="_blank">http://127.0.0.1:8124/'</a>);</div></div><div><br></div><div>






-- end</div><div>
<br></div><div>-- now we run it</div><div><div><br></div><div>$ node fib.js</div><div>Server running at <a href="http://127.0.0.1:8124/" target="_blank">http://127.0.0.1:8124/</a></div><div>fib(2)= 2</div><div><br></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></div><div>fib(2) has run out of stack space????</div><div><div><br></div><div>$ node --version</div>







<div>v0.8.21</div></div><div><br></div><div>Any ideas what I'm doing wrong</div><div><br></div><div>Cheers</div><div><br></div><div>/Joe</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div>







<div><br></div></div><span><font color="#888888">
</font></span></blockquote></div></div></div></div><span><font color="#888888"><span><font color="#888888">

<p></p>

-- <br>
Remember to send a copy to erlang (dot) questions (at) erlang (dot) org when posting.<br>
--- <br>
You received this message because you are subscribed to the Google Groups "Erlang Programming" group.<br>
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:erlang-programming+unsubscribe@googlegroups.com" target="_blank">erlang-programming+unsubscribe@googlegroups.com</a>.<br>







To post to this group, send email to <a href="mailto:erlang-programming@googlegroups.com" target="_blank">erlang-programming@googlegroups.com</a>.<br>
Visit this group at <a href="http://groups.google.com/group/erlang-programming" target="_blank">http://groups.google.com/group/erlang-programming</a>.<br>
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank">https://groups.google.com/d/optout</a>.<br>
</font></span></font></span></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Studying for the Turing test</div>
</font></span></div>
</blockquote></div></div></div><br></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Studying for the Turing test</div>
</div>
</div></div></blockquote></div></div></div><br></div></div>
<br></div></div><div>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></div></blockquote></div><br></div>
</blockquote></div><br></div></div>