zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    函数的定义
    函数加载的过程
    js中的return
    快速排序
    冒泡排序
    数组的案例
    正睿暑期培训day3考试
    bzoj2115 Xor
    luogu4570 元素
    bzoj4827 Hnoi2017 礼物
  • 原文地址:https://www.cnblogs.com/yecao8888/p/7100397.html
Copyright © 2011-2022 走看看