title: in HTTP mode, does node.js have substantial performance advantage over Java?
body: <p>I just started to code in node.js for a little while. Now here is one of my questions about it:</p>
  
  <p>In HTTP apps, given the request-response model, the <strong>single</strong> app <strong>thread</strong> is blocked until all the back end tasks are done and response is returned to the client, so the performance improvement seems to be limited only to fine-tuning back end things like parallelizing IO requests.   (<em>Well, this improvement matters when it comes to many <strong>heavy</strong> and <strong>independent</strong> IO operations being involved, but usually the condition also implies that by redesigning the data structure you could eliminate a large number of IO request and, possibly, end up with even better performance than just issuing parallelized operations.</em>) </p>
  
  <p>If that is true, how could it produce superior performance than those frameworks based on Java (or PHP, python, etc.) do?</p>
  
  <p>I also referred to an article <a href="http://blog.mixu.net/2011/02/01/understanding-the-node-js-event-loop/" rel="nofollow noreferrer">Understanding the node.js event loop</a>, which also explains that situation:</p>
  
  <blockquote>
    <p>It really is a single thread running: you can’t do any parallel code
    execution; doing a “sleep” for example will block the server for one
    second:</p>
  </blockquote>
  
  <pre><code>while(new Date().getTime() &lt; now + 1000) {
     // do nothing
  }
  </code></pre>
  
  <blockquote>
    <p>…however, everything runs in parallel except your code.</p>
  </blockquote>
  
  <p>I personally verified that by putting exact the "sleep" code into one IO callback closure, and tried submitting a request leading to this callback, then submitted another one. Both requests will trigger a console log when it is processed. And my observation is that the later was blocked until the former returned a response.</p>
  
  <p>So, does it imply that only in <strong>socket</strong> mode, where both sides can emit events and push messages to each other at any time, would the full power of its asynchronous processing capability be utilized?</p>
  
  <p>I'm a little confused about that. Any comment or advice is welcome. Thanks!</p>
  
  <p><strong>update</strong></p>
  
  <blockquote>
    <p>I ask this question because some performance evaluation cases are
    reported, for instance <a href="http://blog.appfog.com/node-js-is-taking-over-the-enterprise-whether-you-like-it-or-not/" rel="nofollow noreferrer">Node.js is taking over the Enterprise –
    whether you like it or
    not</a>,
    and <a href="http://highscalability.com/blog/2012/10/4/linkedin-moved-from-rails-to-node-27-servers-cut-and-up-to-2.html" rel="nofollow noreferrer">LinkedIn Moved from Rails to Node: 27 Servers Cut and Up to 20x
    Faster</a>.
    Some radical opinion claims that J2EE will be totally replaced: <a href="http://java.dzone.com/articles/j2ee-dead-long-live-javascript" rel="nofollow noreferrer">J2EE
    is Dead: Long-live Javascript Backed by JSON
    Services</a>.</p>
  </blockquote>