<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
span.hoenzb
{mso-style-name:hoenzb;}
span.EstiloCorreo19
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 3.0cm 70.85pt 3.0cm;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=ES-MX link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span lang=EN-CARRIBEAN style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hi all, <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CARRIBEAN style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-CARRIBEAN>Paulo F. Oliveira says: “…At the moment, though, I enjoy prototyping with Node.js and implementing with Erlang. :)…”<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-CARRIBEAN style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>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.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-CARRIBEAN style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Best,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Ivan.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span lang=ES style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>De:</span></b><span lang=ES style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> erlang-questions-bounces@erlang.org [mailto:erlang-questions-bounces@erlang.org] <b>En nombre de </b>Paulo F. Oliveira<br><b>Enviado el:</b> martes, 17 de junio de 2014 09:07 a.m.<br><b>Para:</b> Joe Armstrong<br><b>CC:</b> Greg Young; Juan Facorro; Erlang; erlang-programming@googlegroups.com<br><b>Asunto:</b> Re: [erlang-questions] node.js vs erlang<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>"Node is very popular so I'm trying to understand what it is about node that is attractive."<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Having recently moved from Node.js (JavaScript really) to Erlang, a few things come to mind:<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>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<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>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)<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>3. </span><a href="http://npmjs.org"><span lang=EN-CARRIBEAN>npmjs.org</span></a><span lang=EN-CARRIBEAN> :D<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>4. the debugger (node-inspector): I miss this :(<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>5. you can share server-side and browser-side code<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>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...<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>At the moment, though, I enjoy prototyping with Node.js and implementing with Erlang. :)<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>- Paulo F. Oliveira<o:p></o:p></span></p></div></div><div><p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-CARRIBEAN><o:p> </o:p></span></p><div><p class=MsoNormal><span lang=EN-CARRIBEAN>On 17 June 2014 13:41, Joe Armstrong <</span><a href="mailto:erlang@gmail.com" target="_blank"><span lang=EN-CARRIBEAN>erlang@gmail.com</span></a><span lang=EN-CARRIBEAN>> wrote:<o:p></o:p></span></p><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p><div><p class=MsoNormal><span lang=EN-CARRIBEAN>On Tue, Jun 17, 2014 at 2:05 PM, Darach Ennis <</span><a href="mailto:darach@gmail.com" target="_blank"><span lang=EN-CARRIBEAN>darach@gmail.com</span></a><span lang=EN-CARRIBEAN>> wrote:<o:p></o:p></span></p><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Hi all,<o:p></o:p></span></p><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>For this to be comparable both Erlang and Node.js need to be running<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>similarly. I don't see how a concurrent Erlang runtime with multiple schedulers<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>can be compared with a single-threaded Node.js implementation objectively or<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>fairly...<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>It's actually the programming models I want to compare and not the<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>performance - what worries me about node is the run-to-completion<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>semantics of event callbacks - namely that a long-running event will block<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>the server preventing short computations from being performed. The<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>short jobs which could be done immediately have to wait until the long jobs<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>have finished - this should reflect in the average latencies of a request.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>I made a little experiment (a fibonacci server in erlang and node) and fired off<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>1000 parallel requests to compute fib(N) with N a random number from 10..40.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>As I suspected many of the fib(10) events are blocked by ongoing computation of<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>fib(40) - this reflect in the latencies.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Node is about 1.6 times faster than Erlang - but the latencies for small computations<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>are terrible - Erlang never blocks so the response times are more predictable.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>And yes I know that fib can be offloaded to a background processor or parallelised<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>in JS with a bit of black magic - but manually converting a long lived computation into<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>a re-entrant non-blocking version is very difficult.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>The node books say something like "make sure that callbacks run-to-completion quickly"<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>I would say that complying with this advice is extremely difficult. It's very difficult to guess<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>which computations will take a long time, and even if you know it's difficult to break them into<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>small re-entrant chunks.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Node is very popular so I'm trying to understand what it is about node that is attractive.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>npm for example, looks well engineered and something we could learn from. The node<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>web servers are easy to setup and run, so I'd like to see if we could make equally <o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>easy to use Erlang servers.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Performance is not a primary concern - easy of programming and correctness are.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Cheers<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>/Joe<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN> <o:p></o:p></span></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Using node cluster with the same number of cluster instances as erlang<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>schedulers might be a fairer environment for comparison. However, as<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>numeric computations are fairly efficient in Node.js and inefficient in Erlang<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>relative to Java or C it may take a few iterations to get a fair comparison<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>in place. Node cluster is a standard part of node.js:<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><a href="http://nodejs.org/api/cluster.html" target="_blank"><span lang=EN-CARRIBEAN>http://nodejs.org/api/cluster.html</span></a><span lang=EN-CARRIBEAN><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>There are various attempts at implementing fibers and lightweight threads<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>in Node.js (eg: </span><a href="https://github.com/laverdet/node-fibers/" target="_blank"><span lang=EN-CARRIBEAN>https://github.com/laverdet/node-fibers/</span></a><span lang=EN-CARRIBEAN>) but there is nothing<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>common here. This would approximate an erlang runtime more closely at<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>the cost of deviating a little from a commonly found node runtime... Ho hum.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>As javascript runtimes start to adopt vectorized instructions and other<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>optimisations their speed relative to a C baseline has and will continue to<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>steadily improve and has been for a number of years, especially with V8.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Good luck with the benchmarking!<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Cheers,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Darach.<o:p></o:p></span></p></div></div><div><p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-CARRIBEAN><o:p> </o:p></span></p><div><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>On Tue, Jun 17, 2014 at 12:48 PM, Joe Armstrong <</span><a href="mailto:erlang@gmail.com" target="_blank"><span lang=EN-CARRIBEAN>erlang@gmail.com</span></a><span lang=EN-CARRIBEAN>> wrote:<o:p></o:p></span></p></div></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'><div><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p><div><p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-CARRIBEAN><o:p> </o:p></span></p><div><p class=MsoNormal><span lang=EN-CARRIBEAN>On Tue, Jun 17, 2014 at 1:00 PM, Greg Young <</span><a href="mailto:gregoryyoung1@gmail.com" target="_blank"><span lang=EN-CARRIBEAN>gregoryyoung1@gmail.com</span></a><span lang=EN-CARRIBEAN>> wrote:<o:p></o:p></span></p><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Are you testing against single threaded node or one of the clustered versions or multiple processes or?<o:p></o:p></span></p></div><div><div><div><p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div></div></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Single threaded<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN style='color:#888888'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN style='color:#888888'>/Joe<o:p></o:p></span></p></div><div><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN> <o:p></o:p></span></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'><div><div><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>On Tue, Jun 17, 2014 at 1:19 PM, Joe Armstrong <</span><a href="mailto:erlang@gmail.com" target="_blank"><span lang=EN-CARRIBEAN>erlang@gmail.com</span></a><span lang=EN-CARRIBEAN>> wrote:<o:p></o:p></span></p><div><div><p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-CARRIBEAN><o:p> </o:p></span></p><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>On Tue, Jun 17, 2014 at 12:10 PM, Greg Young <</span><a href="mailto:gregoryyoung1@gmail.com" target="_blank"><span lang=EN-CARRIBEAN>gregoryyoung1@gmail.com</span></a><span lang=EN-CARRIBEAN>> wrote:<o:p></o:p></span></p><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Can you really compare the two? :) <o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Yes - there are many things we can measure. Performance, Latency, memory usage and so on.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Right now I'm measuring latency - <o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>I set up a few thousand parallel processes which request fib(N) and measure the latency of the responses.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>the results will be published when I understand them :-)<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN style='color:#888888'><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN style='color:#888888'>/Joe<o:p></o:p></span></p></div><div><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN> <o:p></o:p></span></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'><div><p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-CARRIBEAN><o:p> </o:p></span></p><div><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>On Mon, Jun 16, 2014 at 5:55 PM, Juan Facorro <</span><a href="mailto:juan.facorro@gmail.com" target="_blank"><span lang=EN-CARRIBEAN>juan.facorro@gmail.com</span></a><span lang=EN-CARRIBEAN>> wrote:<o:p></o:p></span></p></div></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt'><div><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Hi Joe,<o:p></o:p></span></p><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>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.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>HTH,<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>J<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><br>On Monday, June 16, 2014 11:22:23 AM UTC-3, Joe Armstrong wrote:<o:p></o:p></span></p><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>I'm trying to compare node.js with erlang. I'm a total node.js novice BTW - but I've written some JS.<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Program 1 is just fibonacci - I want a web server to compute fib(N)<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>So requesting </span><a href="http://127.0.0.1:8124/fib?n=2" target="_blank"><span lang=EN-CARRIBEAN>http://127.0.0.1:8124/fib?n=2</span></a> <span lang=EN-CARRIBEAN>should compute and return fib(2)<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>My node.js attempt crashes<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Here's the code in fib.js<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal>--- fib.js<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><div><p class=MsoNormal>var http = require('http');<o:p></o:p></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>var url = require('url');<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>function fib(n) {<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN> if (n < 2) {<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN> return 1;<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN> } else {<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN> return fib(n - 2) + fib(n - 1);<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN> </span>}<o:p></o:p></p></div><div><p class=MsoNormal>}<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>http.createServer(function (req, res) {<o:p></o:p></p></div><div><p class=MsoNormal> var q = url.parse(req.url, true).query;<o:p></o:p></p></div><div><p class=MsoNormal> var n = q.n;<o:p></o:p></p></div><div><p class=MsoNormal> var result = fib(n);<o:p></o:p></p></div><div><p class=MsoNormal> <span lang=EN-CARRIBEAN>console.log('fib('+ n + ')= '+result);<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN> res.writeHead(200, {'Content-Type': 'text/plain'});<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN> res.end(result.toString());<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>}).listen(8124, "127.0.0.1");<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>console.log('Server running at </span><a href="http://127.0.0.1:8124/'" target="_blank"><span lang=EN-CARRIBEAN>http://127.0.0.1:8124/'</span></a><span lang=EN-CARRIBEAN>);<o:p></o:p></span></p></div></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>-- end<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>-- now we run it<o:p></o:p></span></p></div><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>$ node fib.js<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Server running at </span><a href="http://127.0.0.1:8124/" target="_blank"><span lang=EN-CARRIBEAN>http://127.0.0.1:8124/</span></a><span lang=EN-CARRIBEAN><o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>fib(2)= 2<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>/home/ejoearm/Dropbox/experiments/hello_world/fib.js:5<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>function fib(n) {<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN> ^<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>RangeError: Maximum call stack size exceeded<o:p></o:p></span></p></div></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>fib(2) has run out of stack space????<o:p></o:p></span></p></div><div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>$ node --version<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>v0.8.21<o:p></o:p></span></p></div></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Any ideas what I'm doing wrong<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>Cheers<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN>/Joe<o:p></o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div></div></div></div></div></div><p class=MsoNormal><span lang=EN-CARRIBEAN style='color:#888888'>-- <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 </span><span style='color:#888888'><a href="mailto:erlang-programming+unsubscribe@googlegroups.com" target="_blank"><span lang=EN-CARRIBEAN>erlang-programming+unsubscribe@googlegroups.com</span></a></span><span lang=EN-CARRIBEAN style='color:#888888'>.<br>To post to this group, send email to </span><span style='color:#888888'><a href="mailto:erlang-programming@googlegroups.com" target="_blank"><span lang=EN-CARRIBEAN>erlang-programming@googlegroups.com</span></a></span><span lang=EN-CARRIBEAN style='color:#888888'>.<br>Visit this group at </span><span style='color:#888888'><a href="http://groups.google.com/group/erlang-programming" target="_blank"><span lang=EN-CARRIBEAN>http://groups.google.com/group/erlang-programming</span></a></span><span lang=EN-CARRIBEAN style='color:#888888'>.<br>For more options, visit </span><span style='color:#888888'><a href="https://groups.google.com/d/optout" target="_blank"><span lang=EN-CARRIBEAN>https://groups.google.com/d/optout</span></a></span><span lang=EN-CARRIBEAN style='color:#888888'>.</span><span lang=EN-CARRIBEAN><o:p></o:p></span></p></blockquote></div><p class=MsoNormal><span lang=EN-CARRIBEAN style='color:#888888'><br><br clear=all><span class=hoenzb><o:p></o:p></span></span></p><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><p class=MsoNormal><span class=hoenzb><span lang=EN-CARRIBEAN style='color:#888888'>-- </span></span><span class=hoenzb><span lang=EN-CARRIBEAN><o:p></o:p></span></span></p><div><p class=MsoNormal><span lang=EN-CARRIBEAN style='color:#888888'>Studying for the Turing test</span><span lang=EN-CARRIBEAN><o:p></o:p></span></p></div></div></blockquote></div></div></div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div></div></div><p class=MsoNormal><span lang=EN-CARRIBEAN style='color:#888888'><br><br clear=all><span class=hoenzb><o:p></o:p></span></span></p><div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div><p class=MsoNormal><span class=hoenzb><span lang=EN-CARRIBEAN style='color:#888888'>-- </span></span><span class=hoenzb><span lang=EN-CARRIBEAN><o:p></o:p></span></span></p><div><p class=MsoNormal><span lang=EN-CARRIBEAN style='color:#888888'>Studying for the Turing test</span><span lang=EN-CARRIBEAN><o:p></o:p></span></p></div></div></div></div></blockquote></div></div></div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div></div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div></div><div><p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-CARRIBEAN style='color:#888888'>_______________________________________________<br>erlang-questions mailing list<br></span><span style='color:#888888'><a href="mailto:erlang-questions@erlang.org" target="_blank"><span lang=EN-CARRIBEAN>erlang-questions@erlang.org</span></a></span><span lang=EN-CARRIBEAN style='color:#888888'><br></span><span style='color:#888888'><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank"><span lang=EN-CARRIBEAN>http://erlang.org/mailman/listinfo/erlang-questions</span></a></span><span lang=EN-CARRIBEAN style='color:#888888'><o:p></o:p></span></p></div></blockquote></div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div></blockquote></div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div></div><p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-CARRIBEAN><br>_______________________________________________<br>erlang-questions mailing list<br></span><a href="mailto:erlang-questions@erlang.org"><span lang=EN-CARRIBEAN>erlang-questions@erlang.org</span></a><span lang=EN-CARRIBEAN><br></span><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank"><span lang=EN-CARRIBEAN>http://erlang.org/mailman/listinfo/erlang-questions</span></a><span lang=EN-CARRIBEAN><o:p></o:p></span></p></div><p class=MsoNormal><span lang=EN-CARRIBEAN><o:p> </o:p></span></p></div></div></body></html>