WebSocket-bench測試WebSocket

1安裝Node.js

CentOS6.5環境下安裝node

檢查是否安裝了epelgit

yum repolist

若是沒有在結果中看到epel則經過yum命令安裝github

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

安裝好以上環境後開始安裝node.jsweb

sudo yum install nodejs npm --enablerepo=epel

 

2安裝WebSocket-bench

使用npm以全局方式安裝npm

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

 

3WebSocket-bench使用

修改文件打開數服務器

ulimit -n 60000

使用generator來自定義測試邏輯websocket

複製代碼
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行socket

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

相關文章
相關標籤/搜索