websocket-压力测试

websocket 长连接数、 websocket压力测试

  • JMeterPlugins-Standard
  • serverAgent

JMeter webscoket 分布式压力测试

  • master:司令
  • slave(server):奴隶
  • target:目标

Jmeter分布式压测原理

  1. 总控机器的节点master,其他产生压力的机器叫“肉鸡” server
  2. master会把压测脚本发送到 server上面
  3. 执行的时候,server上只需要把jmeter-server打开就可以了,不用启动jmeter
  4. 结束后,server会把压测数据回传给master,然后master汇总输出报告

  1. 在master和slaves机器上分别按照相同版本的jdk和jmeter
  2. 在master机器上
    1) 修改配置文件,进入jmeter/bin目录下

vim jmeter.properties

remote_hosts=192.168.0.102:8899,192.168.0.101:8899(slaves机器的ip和端口)
server.rmi.ssl.disable=true(禁用ssl)

如果master即作为master也作为slaves

remote_hosts=192.168.0.102:8899,192.168.0.101:8899,master的ip:8899

server_port=8899

server.rmi.ssl.disable=true(禁用ssl)

2) 启动jmeter服务

./jmeter-server(linux)

jmeter-server.bat(windows)

3) 检查是否启动成功

ps -ef|grep jmeter-server

  1. 在slaves机器上
    1) 修改配置文件,进入jmeter/bin目录下
vim jmeter.properties

remote_hosts=127.0.0.1

server_port=8899

server.rmi.ssl.disable=true(禁用ssl)

2) 启动jmeter服务

./jmeter-server(linux)

jmeter-server.bat(windows)

3) 检查是否启动成功

ps -ef|grep jmeter-server

  1. 分布式执行
    GUI模式 :运行——》远程启动、远程启动全部

non-GUO模式:命令行增加-r参数

jmeter -n -t /Users/jack/Desktop/remote.jmx -r -l /Users/jack/Desktop/jtl/result.jtl -e -o /Users/jack/Desktop/result

JMeter分布式部署遇到的报错问题

Error in rconfigure() method java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: eu.luminis.jmeter.wssampler.OpenWebSocketSampler (no security manager: RMI class loader disabled)
  • 情况1
    自己配置上禁用ssl了
  • 情况2
    控制机器和被控制机器插件、或jmeter版本不一致.
Connection refused to host: 192.168.3.156; nested exception is: 
    java.net.ConnectException: Connection refused: connect

奴隶机器启动防火墙了-关闭就好了

non-JRMP server at remote endpoint

端口被占用了 windows netstat -ano | findstr "1099"

error during JRMP connection establishment; nested exception is: 
    javax.net.ssl.SSLHandshakeException: PKIX path validation failed: java.security.cert.CertPathValidatorException: signature check failed

生成的SSL文件不一致

Found ApacheJMeter_core.jar 


Server failed to start: java.rmi.server.ExportException: Listen failed on port: 0; nested exception is:
        java.io.FileNotFoundException: rmi_keystore.jks (系统找不到指定的文件。)
An error occurred: Listen failed on port: 0; nested exception is:
        java.io.FileNotFoundException: rmi_keystore.jks (系统找不到指定的文件。)
errorlevel=1

需要配置环境变量 %JMETER_HOME%\lib\ext\ApacheJMeter_core.jar;

Exception creating connection to: 192.168.3.156; nested exception is: 
    java.io.FileNotFoundException: rmi_keystore.jks (系统找不到指定的文件。)

Server failed to start: java.rmi.server.ExportException: Listen failed on port: 0; nested exception is:
        java.io.IOException: java.security.UnrecoverableKeyException: Cannot recover key
An error occurred: Listen failed on port: 0; nested exception is:
        java.io.IOException: java.security.UnrecoverableKeyException: Cannot recover key
errorlevel=1
Server failed to start: java.rmi.server.ExportException: Listen failed on port: 0; nested exception is:
        java.io.IOException: Keystore was tampered with, or password was incorrect
An error occurred: Listen failed on port: 0; nested exception is:
        java.io.IOException: Keystore was tampered with, or password was incorrect
errorlevel=1

python websocket 压力测试

import websocket
import time
import threading

SERVER_URL = "ws://192.168.3.51:9501/"
def on_message(ws, message):
    print(message)


def on_error(ws, error):
    print(error)


def on_close(ws):
    print("### closed ###")


def on_open(ws):

    def send_trhead():
        send_info = 'PING'
    while True:
        time.sleep(5)
        ws.send('PING')


    t = threading.Thread(target=send_trhead)
    t.start()




def on_start(a):
    time.sleep(a%20)
    websocket.enableTrace(True)
    ws = websocket.WebSocketApp(SERVER_URL + str(a),
                on_message=on_message,
                on_error=on_error,
                on_close=on_close)
    ws.on_open = on_open
    ws.run_forever()




from threadpool import ThreadPool, makeRequests
if __name__ == "__main__":
    #init_logging()
    pool = ThreadPool(20000)
    test = list()
    for ir in range(20000):
        test.append(ir)
    requests = makeRequests(on_start, test)
    [pool.putRequest(req) for req in requests]
    pool.wait()

相关资料

高并发websocket客户端测试代码
pip安装加速

WebSocket进行压力测试
jmeter分布式压测—-windows
ServerAgent-2.2.3
Jmeter分布式压测和监控实践

JMeter安装

Jmeter 安装 (win10 下)
Jmeter的下载安装和环境变量配置(Windows10系统)

JMeter分布式部署

Jmeter分布式的坑
Jmeter分布式测试的各种坑之jmeter-server修改ip
JMeter 4使用SSL密钥库在云中进行远程测试 已创建rmi_keystore.jks,请将其master复制到slave的bin目录中。之后你可以重启jmeter-server.bat奴隶
基于JMeter进行分布式测试
传输机制将使用SSL
server.rmi.ssl.disable=true

发表评论