node.js很火,性能如何如何。
确实,在使用简单的例子:
var http =require('http');
http.createServer(function(req,res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(1337,"127.0.0.1");
返回个Hello World.
然后我用AB测试一下。我累了个去的。
ab -n 1000 -c 100 http://localhost:1337/
...
Requests per second: 4923.08 [#/sec] (mean)
Time per request: 20.313 [ms] (mean)
Time per request: 0.203 [ms] (mean, across all concurrent requests)
Transfer rate: 543.27 [Kbytes/sec] received
OH MYGOD!!!! ,rps将近 5000。这还是只用到了一个核心的单线程例子。
八核心岂不是能上4W?
一台小电脑足够支撑一个大型医院的了吧(不考虑数据库和其他的)。
但是真正在生产环境下呢?比如一个使用最简单的 Express框架,最简单的MVC模式
====routes/index.js=======
exports.index = function(req, res){
res.render('index', { title: 'Express' });
};
====view/index.jade=======
extends layout
block content
h1 #{title}
p Welcome to [#{title}]
结果呢????
ab -n 1000 -c 100 http://localhost:3000/
Requests per second: 149.53 [#/sec] (mean)
rps 也就 150了。显然照JSP比差得很多。。。