in HTTP mode, does node.js have substantial performance advantage over Java?
http, java, node.js, performance, sockets
Solution
As far as my experience(though brief) goes with node.js, i agree the performance of node.js server can not be compared with other webservers like tomcat etc as stated in node.js doc somewhere
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:
So we used it not as alternative to full fledged webserver like tomcat but just to distrubute some load from tomcat where we can take of single thread model. So it has to be trade-off somewhere
Also see http://www.sitepoint.com/node-js-is-the-new-black/ Thats the beautiful article about node.js
Problem
I just started to code in node.js for a little while. Now here is one of my questions about it: In HTTP apps, given the request-response model, the single app thread 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. (Well, this improvement matters when it comes to many heavy and independent 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.) If that is true, how could it produce superior performance than those frameworks based on Java (or PHP, python, etc.) do? I also referred to an article Understanding the node.js event loop, which also explains that situation: 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: ``` while(new Date().getTime() < now + 1000) { // do nothing } ``` …however, everything runs in parallel except your code. 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. So, does it imply that only in socket 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? I'm a little confused about that. Any comment or advice is welcome. Thanks! update I ask this question because some performance evaluation cases are reported, for instance Node.js is taking over the Enterprise – whether you like it or not, and LinkedIn Moved from Rails to Node: 27 Servers Cut and Up to 20x Faster. Some radical opinion claims that J2EE will be totally replaced: J2EE is Dead: Long-live Javascript Backed by JSON Services.