12191210
系统:Joyent smartmachine
nodejs:0.6.6
nginx+nodejs测试hello world
nginx反向代理配置
upstream nodejs {
server 127.0.0.1:9880 fail_timeout=10s;
}
server
{
listen 80;
server_name test.nodejs;
index index.php index.html index.htm;
location / {
#try_files $uri /index.php;
proxy_pass http://nodejs;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 30s;
proxy_read_timeout 2s;
}
location ~ \.(php|php5)$ {
fastcgi_pass unix:/tmp/fastcgi.socket;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~* \.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~* \.(js|css)$ {
expires 1h;
}
location ~* \.(ini|inc)$ {
deny all;
}
}
测试代码
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('death', function(worker) {
console.log('worker ' + worker.pid + ' died');
});
} else {
http.Server(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(9880);
}
云服务上是24个cpu,所以查看nodejs进程得到了24个进程数,测试并发请求的网络环境是8M。 LoadRunner测试的结果,400个并发,响应的平均时间是0.78s,TPS只有400多。nginx+php的应用测试结果远远高于以上nodejs的值,能到1000多TPS,平均响应时间在0.1s。
请问这里的nodejs性能瓶颈在哪里,关键还没有带业务测试,业务需要ssl和mysql,响应就更加慢了。