|
@ -30,7 +30,7 @@ |
|
|
} |
|
|
} |
|
|
#toc a { color: #777; } |
|
|
#toc a { color: #777; } |
|
|
|
|
|
|
|
|
h1, h2, h3 { color: #9a2; } |
|
|
h1, h2, h3 { color: inherit; } |
|
|
|
|
|
|
|
|
h1 { |
|
|
h1 { |
|
|
margin: 2em 0; |
|
|
margin: 2em 0; |
|
@ -39,6 +39,7 @@ |
|
|
line-height: 44px; |
|
|
line-height: 44px; |
|
|
font-weight: bold; |
|
|
font-weight: bold; |
|
|
} |
|
|
} |
|
|
|
|
|
h1 a { color: inherit; } |
|
|
|
|
|
|
|
|
h2 { |
|
|
h2 { |
|
|
margin: 2em 0; |
|
|
margin: 2em 0; |
|
@ -87,11 +88,11 @@ |
|
|
<h1><a href="http://tinyclouds.org/node">Node</a></h1> |
|
|
<h1><a href="http://tinyclouds.org/node">Node</a></h1> |
|
|
|
|
|
|
|
|
<p id="introduction"> Node is a purely evented I/O framework for <a |
|
|
<p id="introduction"> Node is a purely evented I/O framework for <a |
|
|
href="#">V8 javascript</a>. Its goal is to enable easy development of |
|
|
href="#">V8 javascript</a>. It enables easy development of |
|
|
highly concurrent, small footprint programs. For example, this is a |
|
|
highly concurrent, efficent network programs. For example, this is a |
|
|
simple web server which responds with "Hello World" after waiting two |
|
|
simple web server which responds with "Hello World" after waiting two |
|
|
seconds: |
|
|
seconds: |
|
|
<pre> |
|
|
<pre class="sh_javascript"> |
|
|
node.http.server(function (msg) { |
|
|
node.http.server(function (msg) { |
|
|
setTimeout(function () { |
|
|
setTimeout(function () { |
|
|
msg.sendHeader(200, [["Content-Type", "text/plain"]]); |
|
|
msg.sendHeader(200, [["Content-Type", "text/plain"]]); |
|
@ -102,11 +103,10 @@ node.http.server(function (msg) { |
|
|
</pre> |
|
|
</pre> |
|
|
|
|
|
|
|
|
<p> While one request is waiting the server will continue to accept and |
|
|
<p> While one request is waiting the server will continue to accept and |
|
|
serve other requests. This is accomplished without threads and is quite |
|
|
serve other requests. This little server can handle hundreds of |
|
|
efficient: handling hundreds of concurrent requests while using |
|
|
concurrent requests while using little CPU or memory—<a |
|
|
little CPU or memory—<a href="#benchmarks">see benchmarks</a>. |
|
|
href="#benchmarks">see benchmarks</a>. The example demonstrates |
|
|
The example might seem esoteric but similar behavior |
|
|
efficency that is needed for handling long held "comet" requests. |
|
|
is required to implement, for example, "comet" servers. |
|
|
|
|
|
|
|
|
|
|
|
<p> Node is free to <a href="#download">download</a>, <a |
|
|
<p> Node is free to <a href="#download">download</a>, <a |
|
|
href="#api">use</a>, and <a href="#modules">build upon</a>.</p> |
|
|
href="#api">use</a>, and <a href="#modules">build upon</a>.</p> |
|
@ -123,6 +123,8 @@ node.http.server(function (msg) { |
|
|
<li>Evented programs are more efficient |
|
|
<li>Evented programs are more efficient |
|
|
<ol> |
|
|
<ol> |
|
|
<li>pthread stack size |
|
|
<li>pthread stack size |
|
|
|
|
|
2mb default stack size on linux (1mb on windows, 64kb on FreeBSD) |
|
|
|
|
|
of course this is adjustable |
|
|
<li>context switching benchmark |
|
|
<li>context switching benchmark |
|
|
<li>Apache vs. Nginx |
|
|
<li>Apache vs. Nginx |
|
|
<li>event machine vs mongrel (neverblock) |
|
|
<li>event machine vs mongrel (neverblock) |
|
@ -174,7 +176,7 @@ node.http.server(function (msg) { |
|
|
the thread scheduler, a blocking server can make function calls which |
|
|
the thread scheduler, a blocking server can make function calls which |
|
|
preform full network requests. |
|
|
preform full network requests. |
|
|
|
|
|
|
|
|
<pre>var response = db.execute("SELECT * FROM table"); |
|
|
<pre class="sh_javascript">var response = db.execute("SELECT * FROM table"); |
|
|
// do something</pre> |
|
|
// do something</pre> |
|
|
|
|
|
|
|
|
<p> An evented server manages its concurrency itself. All connections |
|
|
<p> An evented server manages its concurrency itself. All connections |
|
@ -184,7 +186,7 @@ node.http.server(function (msg) { |
|
|
<i>blocks</i> the process. In the evented world callbacks are used |
|
|
<i>blocks</i> the process. In the evented world callbacks are used |
|
|
instead of functions |
|
|
instead of functions |
|
|
|
|
|
|
|
|
<pre>db.execute("SELECT * FROM table", function (response) { |
|
|
<pre class="sh_javascript">db.execute("SELECT * FROM table", function (response) { |
|
|
// do something |
|
|
// do something |
|
|
});</pre> |
|
|
});</pre> |
|
|
|
|
|
|
|
|