|
@ -42,28 +42,30 @@ Server running at http://127.0.0.1:8000/ |
|
|
<p> Node's goal is to provide easy, scalable concurrency. In the above example, |
|
|
<p> Node's goal is to provide easy, scalable concurrency. In the above example, |
|
|
the 2 second delay does not prevent the server from handling new requests. |
|
|
the 2 second delay does not prevent the server from handling new requests. |
|
|
|
|
|
|
|
|
Node notifies the operating system (through <code>epoll(7)</code>) that it |
|
|
Node tells the operating system (through <code>epoll</code> or |
|
|
should be notified when the 2 seconds are up, or if a new connection is |
|
|
<code>kqueue</code> or <code class="sh_none">/dev/poll</code> or <code>select</code>) that it |
|
|
|
|
|
should be notified when the 2 seconds are up or if a new connection is |
|
|
made—then it goes to sleep. If someone new connects, then it executes |
|
|
made—then it goes to sleep. If someone new connects, then it executes |
|
|
the callback again. Each connection is only a small allocation on the heap. |
|
|
the callback, if the timeout expires, it executes the inner callback. |
|
|
|
|
|
Each connection is only a small heap allocation. |
|
|
|
|
|
|
|
|
<p>This is in contrast to most scripting languages (and all other |
|
|
<p>This is in contrast to most scripting languages where OS threads are employed for |
|
|
server-side javascript systems) where OS threads are employed to have |
|
|
|
|
|
concurrency. But thread-based networking |
|
|
concurrency. But thread-based networking |
|
|
<a href="http://www.sics.se/~joe/apachevsyaws.html">is</a> |
|
|
<a href="http://www.sics.se/~joe/apachevsyaws.html">is</a> |
|
|
<a href="http://www.kegel.com/c10k.html">relatively</a> |
|
|
<a href="http://www.kegel.com/c10k.html">relatively</a> |
|
|
<a href="http://bulk.fefe.de/scalable-networking.pdf">inefficient</a> |
|
|
<a href="http://bulk.fefe.de/scalable-networking.pdf">inefficient</a> |
|
|
<!-- TODO needs links --> |
|
|
<!-- TODO needs links --> |
|
|
and |
|
|
and |
|
|
|
|
|
very |
|
|
difficult |
|
|
difficult |
|
|
to |
|
|
to |
|
|
use. |
|
|
use. |
|
|
Node will show much better memory performance under high-loads |
|
|
Node will show much better memory efficency under high-loads |
|
|
<!-- TODO benchmark --> |
|
|
<!-- TODO benchmark --> |
|
|
than other systems (i.e. all other javascript server-side systems) |
|
|
than other systems |
|
|
which allocate 2mb thread stacks for each connection. |
|
|
which allocate 2mb thread stacks for each connection. |
|
|
|
|
|
|
|
|
<p>For networking, Node is similar to systems like |
|
|
Node is similar to systems like |
|
|
Ruby's <a href="http://rubyeventmachine.com/">Event Machine</a> |
|
|
Ruby's <a href="http://rubyeventmachine.com/">Event Machine</a> |
|
|
or |
|
|
or |
|
|
Python's <a href="http://twistedmatrix.com/">Twisted</a>. |
|
|
Python's <a href="http://twistedmatrix.com/">Twisted</a>. |
|
@ -74,6 +76,9 @@ Node blocks, a Node programmer is going to find it difficult to write slow |
|
|
servers—even if they don't understand how the concurrency system |
|
|
servers—even if they don't understand how the concurrency system |
|
|
works. |
|
|
works. |
|
|
|
|
|
|
|
|
|
|
|
<p>Notice in the above example the <code>puts()</code> call is made |
|
|
|
|
|
immediately. |
|
|
|
|
|
|
|
|
<p>Node's HTTP API has grown out of my difficulties while developing for |
|
|
<p>Node's HTTP API has grown out of my difficulties while developing for |
|
|
Merb and Ebb. Because of limiting low-level design choices, streaming data |
|
|
Merb and Ebb. Because of limiting low-level design choices, streaming data |
|
|
through Rack-based frameworks is difficult or impossible. Streaming is |
|
|
through Rack-based frameworks is difficult or impossible. Streaming is |
|
|