您的位置:首页 > Web前端 > Node.js

workerman和nodejs自测性能对比

2015-01-29 16:07 92 查看
根据目前的项目要求,需要找一个合适的框架做api/rpc服务,以前做web项目选型的ci框架,经测试发现使用web框架做api/rpc并不实际;原因是,框架中调用了很多的model,其实在api/RPC中并不真正需要,加载的model一多而且很影响性能;

本来做php开发的,想从php中选型一个好的socket框架的程序来实现。后来查找资料发现php中确实存在这种框架:swoole,workman ,两个框架都进行了下载和测试,发现还是workerman 文档,案例,测试工具和代码规范度等都比较齐全,而且性能比较优越,有图表分析功能,加载框架能跑到1w以上的并发每秒。

后有同事建议采用nodejs 说nodejs性能高,开始对nodejs测试了下做了下对比,刚开始使用nodejs单进程跑helloword,能跑到5000每秒,后觉得性能应该不止这样后代码进行调整成使用多进程方式,并发提升了一杯 ,这里要说明下,我采用的测试服务器为双核服务器

nodejs 测试代码:

var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
console.log("master start...");

// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}

cluster.on('listening',function(worker,address){
console.log('listening: worker ' + worker.process.pid +', Address: '+address.address+":"+address.port);
});

cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
});
} else {
http.createServer(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(0);

}
~
~
~


以下是测试结果:

[root@localhost ~]# webbench -c 1000 -t 30 http://xxx.xx.xx.xxx:44354/ Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://xxx.xx.xx.xxx:44354/ 1000 clients, running 30 sec.

Speed=666260 pages/min, 966068 bytes/sec.
Requests: 333130 susceed, 0 failed.


值得注意的是: 服务器的计算能力和cpu的核心有关,我提升进程的个数,其实没有达到什么作用,并发一直保持 66w 每分钟左右

---------------

workerman 我同样进行压测:

[root@localhost ~]# webbench -c 1000 -t 30 http://xxx.xx.xx.xxx:2015/ Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://xxx.xx.xx.xxx:2015/ 1000 clients, running 30 sec.
Speed=675500 pages/min, 1640655 bytes/sec.
Requests: 337750 susceed, 0 failed.
可以看出,在性能差不多,在直接抛出helloword的情况下。当然以上测是是对框架进行测试并没有实际对程序代码性能进行测试。

不过可以看出一点,如果你在使用php开发workerman框架,是一个不错的选择,当然nodejs也不差,毕竟很多大型企业都开始使用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: