<p dir="ltr">Thanks for the explanation. I like this.<br>
How would a single-threaded process take advantage of muti- CPU?</p>
<div class="gmail_quote">On 2 Jul 2016 5:49 PM, "Erez D" <<a href="mailto:erez0001@gmail.com">erez0001@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>doing some research on servers i found out that i can handle more connections simultaneously as single threaded.<br></div>on thread per connection i have a huge overhead, just think of the default 2MB stack per connection - 1000 connections is 2GB ram just for stack.<br>however as single threaded, i can server connections by the 10,000s(or even a million). <br><br></div><div>later to my surprise, i found out that that was exactly one of the main considerations behind node.js<br><br></div><div>but node.js requires code in js. and i am more of a c++ guy<br></div><div>(and of course c++ is more efficient than js)<br></div><div><br>C++ did a long way and now modern c++ (i.e. c++11 / c++14 ) is on par with other modern languages.<br></div><div>the idea behind c++11/14 was to make it simple for beginners, while still keeping the option to control every bit for advanced users.<br>one thing i hear people hate about c and c++ is its memory handling (malloc/free or new/delete), however in forgot about it years ago using shared_ptr ( now in c++11 and before that, use boost instead).. you can still control when it is freed if you want (in countrary to garbage-disposal-thread languages). as a matter of fact, i use this a lot - i create an object that cleans up,. and no matter how i exit the function it gets cleaned up. <br><br></div><div>so i wanted a node.c++ instead of writing my own<br><br></div><div>in theory simple single threaded web server usage code could look something like:<br><br></div><div><span style="font-family:monospace,monospace">int main()<br>{<br></span></div><div><span style="font-family:monospace,monospace">  auto server=HttpServer::create(80,[](Request &request)<br>    {<br></span></div><div><span style="font-family:monospace,monospace">      if (request.header=="HelloWorld")<br>      {<br></span></div><div><span style="font-family:monospace,monospace">         HttpResponse(200,"<H1>Hello, world</h1>");<br></span></div><div><span style="font-family:monospace,monospace">      } else {<br></span></div><div><span style="font-family:monospace,monospace">        File::Read(request,header,[](bool success, string body)<br>          {<br></span></div><div><span style="font-family:monospace,monospace">             if (success)<br></span></div><div><span style="font-family:monospace,monospace">               HttpResponse(400,body); </span></div><div><span style="font-family:monospace,monospace">          } else {<br></span></div><div><span style="font-family:monospace,monospace">               HttpResponse(404);<br>          }<br>        );<br></span></div><div><span style="font-family:monospace,monospace">      }<br></span></div><div><span style="font-family:monospace,monospace">    }<br>  );<br>}</span><br></div><div><br></div><div><br></div><div><br></div><div><div><div> </div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 1, 2016 at 4:58 AM, Amos Shapira <span dir="ltr"><<a href="mailto:amos.shapira@gmail.com" target="_blank">amos.shapira@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">I'm curious - what's the background of this question? What's the original goal that led you to ask this?<div class="gmail_extra"><br><div class="gmail_quote"><div><div>On 28 June 2016 at 18:04, Erez D <span dir="ltr"><<a href="mailto:erez0001@gmail.com" target="_blank">erez0001@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"><div>i tried searching the web but got no result<br><br></div><div>what web servers other than node.js are single threaded ?<br></div><div>anyone has experience with one ?<br></div><div>is there one in which the cgi is in c++ ?<br></div><div><br></div><div><br></div><br></div>
<br></div></div><span>_______________________________________________<br>
Linux-il mailing list<br>
<a href="mailto:Linux-il@cs.huji.ac.il" target="_blank">Linux-il@cs.huji.ac.il</a><br>
<a href="http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il" rel="noreferrer" target="_blank">http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il</a><br>
<br></span></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div data-smartmail="gmail_signature"><div dir="ltr"><a href="http://au.linkedin.com/in/gliderflyer" target="_blank"><img src="https://static.licdn.com/scds/common/u/img/webpromo/btn_viewmy_160x25.png"></a><br></div></div>
</font></span></div></div>
</blockquote></div><br></div>
</blockquote></div>