码迷,mamicode.com
首页 > Web开发 > 详细

WebSocket-bench测试WebSocket

时间:2017-06-30 20:54:13      阅读:637      评论:0      收藏:0      [点我收藏+]

标签:-o   enable   逻辑   执行   local   r文件   npm   his   one   

CentOS6.5环境下安装

检查是否安装了epel

yum repolist

如果没有在结果中看到epel则通过yum命令安装

yum install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

安装好以上环境后开始安装node.js

sudo yum install nodejs npm --enablerepo=epel

 

2安装WebSocket-bench

使用npm以全局方式安装

npm install -g websocket-bench --registry=http://registry.npm.taobao.org

 

3WebSocket-bench使用

修改文件打开数

ulimit -n 60000

使用generator来自定义测试逻辑

技术分享
module.exports = {
       //可选,在建立连接之前会执行
       beforeConnect : function(client) {
}, //必选,建立连接后要做的事情 onConnect : function(client, done) { //向服务器发送消息
//client为客户端的连接实例
client.emit(‘GetMessageList‘,‘{"channelID": "1609"}‘); //回调函数 done(); }, //必选,向服务器发送消息时运行的代码 sendMessage : function(client, done) { client.emit(‘GetMessageList‘,‘{"channelID": "1609"}‘);
done(); }, options : { // realm: ‘chat‘ } };
技术分享

编写完成后,在运行websocket-bench时,使用-g参数指定generator文件

有时需要修改socket.io协议,位置在/usr/lib/node_modules/websocket-bench/lib/workers/socketioworker.js第18行

var client = io.connect(this.server, { ‘force new connection‘ : true,‘transports‘: [‘websocket‘, ‘polling‘]});

运行websocket-bench

websocket-bench -a 10 -c 1 -g generator.js -k  http://localhost:20001/  -o opt.log

-a 参数用于指定总共的测试次数, -c 参数指定并发连接数,使用 -o 参数可以将报告保存到单独的文件中

更多使用请查看https://github.com/M6Web/websocket-bench

4测试报告

Launch bench with 10 total connection, 1 concurent connection
0 message(s) send by client
1 worker(s)
WS server : socket.io

技术分享

WebSocket-bench测试WebSocket

标签:-o   enable   逻辑   执行   local   r文件   npm   his   one   

原文地址:http://www.cnblogs.com/yecao8888/p/7100397.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!