Take the same code that sits on nodejs.org home page. Serve a static file that is 1.8Mb. And do the same with Nginx, and watch the difference.<p>Code : http://pastie.org/3730760
Screencast : http://screencast.com/t/Or44Xie11Fnp<p>Please share if you know anything that'd prevent this from happening, so we don't need to deploy nginx servers and complicate our lives.<p>ps1. this test is done with node 0.6.12. out of curiosity, i downgraded to 0.4.12 just to check if it's a regression, on the contrary, it was worse. same file used 25% twice.<p>ps2. this post is not a nodejs hate - we use nodejs, and we love it, except this glitch which actually delayed our launch (made us really sad), and seemed quite serious to me. i've never read, heard, seen this mentioned before so we could prepare ourselves better.
First of all, writing bug reports to Hacker News is usually a bit like complaining about the government at a bus stop. It's fun, and you'll get lots of agreement from crazy people, and maybe start a little riot, but writing your representative is a better way to effect change.<p>We have two mailing lists, and an issue tracker on github. If someone hadn't emailed this to me, I probably would not have seen it.<p>There are three problems I see with your test.<p>1) It serves the file twice, since you don't filter out the /favicon.ico url<p>2) you're converting the file contents to a string, which needs to be converted <i>back</i> into raw bytes to send.<p>3) your gist is in JavaScript, but I see that you're actually running CoffeeScript. I'm not sure what kind of wrapper CoffeeScript is adding to the equation.<p>I ran the same test serving the ChangeLog file from node's source folder with node v0.6.15 (to be released tomorrow) <a href="https://raw.github.com/joyent/node/v0.6/ChangeLog" rel="nofollow">https://raw.github.com/joyent/node/v0.6/ChangeLog</a><p>Here's the source code of the server.js: <a href="https://gist.github.com/2338851" rel="nofollow">https://gist.github.com/2338851</a><p>It did use more CPU than nginx, but not 100x as much. Requesting the /buffer url made it spike up to about 0.2% cpu usage. Requesting the / url made it spike up to about 0.3%. Even when I disabled the /favicon.ico check, its behavior is nowhere near what you're seeing.<p>When I ran it with coffee script, it actually uses this JavaScript: <a href="https://gist.github.com/2338874" rel="nofollow">https://gist.github.com/2338874</a>. So, there's an extra Function.call in there, but otherwise, it's pretty much identical. My coffeescript version is here: <a href="https://gist.github.com/2338879" rel="nofollow">https://gist.github.com/2338879</a><p>So, something is odd with your situation, and from your test, it's not clear what. I'd love to get more details.<p>On the more general note, clearly we in the node world are perfectly fine with using nginx to serve static assets. Qv. the nodejs.org home page. But node's performance here should be within an order of magnitude, or something is broken. This is not expected or normal performance that you're seeing. We run the "serve a big string over http" benchmark quite often, and so this was very surprising to me.
You could put nginx in front of nodejs and let it handle the static files, it's far better at it.<p>This is worth reading as well:
<a href="http://engineering.linkedin.com/nodejs/blazing-fast-nodejs-10-performance-tips-linkedin-mobile" rel="nofollow">http://engineering.linkedin.com/nodejs/blazing-fast-nodejs-1...</a>
"complicate" your lives? nginx is an amazing piece of technology and it's extremely simple. It's <i>built</i> for serving static files (and doing other things) better than anything else that exists. Use the right tool for the job.