nodejs response speed and nginx

Posted by user1502440 on Stack Overflow See other posts from Stack Overflow or by user1502440
Published on 2012-07-04T21:14:01Z Indexed on 2012/07/04 21:15 UTC
Read the original article Hit count: 204

Filed under:
|

I'm just started testing nodejs, and wanted to get some help in understanding following behavior:

Example #1:

var http = require('http');
http.createServer(function(req, res){
    res.writeHeader(200, {'Content-Type': 'text/plain'});
    res.end('foo');
}).listen(1001, '0.0.0.0');

Example #2:

var http = require('http');
http.createServer(function(req, res){
    res.writeHeader(200, {'Content-Type': 'text/plain'});
    res.write('foo');
    res.end('bar');
}).listen(1001, '0.0.0.0');

When testing response time in Chrome:

example #1 - 6-10ms
example #2 - 200-220ms

But, if test both examples through nginx proxy_pass

server{
    listen 1011;
    location / {
        proxy_pass http://127.0.0.1:1001;
    }
}

i get this:

example #1 - 4-8ms
example #2 - 4-8ms

I am not an expert on either nodejs or nginx, and asking if someone can explain this?

nodejs - v.0.8.1
nginx - v.1.2.2

© Stack Overflow or respective owner

Related posts about node.js

Related posts about nginx