workerman和nodejs自测性能对比
2016-12-28 00:00
288 查看
根据目前的项目要求,需要找一个合适的框架做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...");
} 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也不差,毕竟很多大型企业都开始使用。
本来做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也不差,毕竟很多大型企业都开始使用。
相关文章推荐
- workerman和nodejs自测性能对比
- 2017年的golang、python、php、c++、c、java、Nodejs性能对比
- ASP.NET Core 性能对比评测(ASP.NET,Python,Java,NodeJS)
- python、nodejs和java性能对比
- 2017年的golang、python、php、c++、c、java、Nodejs性能对比[续]
- Golang, Swift, Nodejs 和 Rust 性能对比
- C#、PHP与NodeJs性能测试对比
- nodejs与golang的http模块性能对比
- ASP.NET Core 性能对比评测(ASP.NET,Python,Java,NodeJS)
- tomcat、netty以及nodejs的helloworld性能对比 3ff8
- [nodejs]Javascript模板引擎性能对比及几点优化
- golang、python、php、c++、c、java、Nodejs性能对比
- GO,NODEJS,.NetCore性能对比
- 2017年的golang、python、php、c++、c、java、Nodejs性能对比(golang python php c++ java Nodejs Performance)
- Struts2、SpringMVC、Servlet(Jsp)性能对比 测试
- java连接memcached,并对比从数据库中查询数据与从memcached查询的性能
- 性能对比
- ArrayList和LinkedList的几种循环遍历方式及性能对比分
- LevelDB、TreeDB、SQLite3 性能对比
- 几种I/O模型功能和性能对比