WebSocket-bench測試WebSocket


1安裝Node.js

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM