首先,我对JMeter很新。 我正在尝试对websocket服务进行负载测试,但是在收到对前一条消息的响应后,我无法弄清楚如何在一个连接中顺序发送多条消息(而不是与其他线程并行),数量有限并发连接。
如果找不到响应模式,我的连接也不会被关闭,因为无法识别关闭模式。
修改WebSocketSampler代码后,两个特定于消息的匹配模式和匹配&关闭做工作;代码最终改变了。
实际应用程序最多可为每条消息发送4个响应。但即使使用WS echo服务,我也无法找到一种方法。 我正在使用https://github.com/maciejzaleski/JMeter-WebSocketSampler作为JMeter的插件。
我的CSV文件内容:
{"messageType":0,"messageIx":1,"action":"None"};"messageIx":1
{"messageType":0,"messageIx":2,"action":"None"};"messageIx":2
{"messageType":0,"messageIx":3,"action":"None"};"messageIx":3
{"messageType":0,"messageIx":4,"action":"None"};"messageIx":4
{"messageType":0,"messageIx":5,"action":"Close"};"messageIx":5
针对SimpleWebSocketServer(python)实现输出运行此配置是
52682 : connected
52682 <-- {"messageType":0,"messageIx":1,"action":"None"}
52691 : connected
52691 <-- {"messageType":0,"messageIx":1,"action":"None"}
52700 : connected
52700 <-- {"messageType":0,"messageIx":1,"action":"None"}
52682 <-- {"messageType":0,"messageIx":2,"action":"None"}
52691 <-- {"messageType":0,"messageIx":2,"action":"None"}
52700 <-- {"messageType":0,"messageIx":2,"action":"None"}
52682 <-- {"messageType":0,"messageIx":3,"action":"None"}
52691 <-- {"messageType":0,"messageIx":3,"action":"None"}
52700 <-- {"messageType":0,"messageIx":3,"action":"None"}
52682 <-- {"messageType":0,"messageIx":4,"action":"None"}
52691 <-- {"messageType":0,"messageIx":4,"action":"None"}
52700 <-- {"messageType":0,"messageIx":4,"action":"None"}
52682 <-- {"messageType":0,"messageIx":5,"action":"Close"}
52691 <-- {"messageType":0,"messageIx":5,"action":"Close"}
52700 <-- {"messageType":0,"messageIx":5,"action":"Close"}
52682 <-- <EOF>
52691 <-- <EOF>
52700 <-- <EOF>
52682 <-- <EOF>
52691 <-- <EOF>
52700 <-- <EOF>
52691 : closed
52682 : closed
52700 : closed
从查看结果树监听器获取我得到的每个线程的第一条消息
[Execution Flow]
- Opening new connection
- Using response message pattern ""messageIx":1"
- Using disconnect pattern "Close"
- Waiting for the server connection for 5000 MILLISECONDS
- WebSocket conection has been opened
- Connection established
- Waiting for messages for 5000 MILLISECONDS
- Received message #1 (47 bytes); matched response pattern
- Leaving streaming connection open
但是对于以下消息没有匹配
[Execution Flow]
- Reusing exising connection
- Waiting for messages for 5000 MILLISECONDS
- Received message #2 (47 bytes); didn't match any pattern
- Leaving streaming connection open
对于线程数据的最后一条消息是相同的,除了客户端关闭连接(流连接仍然打开)
- WebSocket conection has been successfully closed by the server
- WebSocket session closed by the client
- Leaving streaming connection open
但是,如果我将响应模式修改为通用\“messageIx \”:所有消息都匹配但是Close Connection与“messageIx”不匹配:5或关闭模式;
Response data:
[Message 5]
{"messageType":0,"messageIx":5,"action":"Close"}
Sampler request:
[Execution Flow]
- Reusing exising connection
- Waiting for messages for 5000 MILLISECONDS
- Received message #5 (48 bytes); matched response pattern
- Leaving streaming connection open
最后,线程化。如果我设置12个线程,他们将在开始时开始加速延迟。 添加循环控制器只会将相同连接的消息相乘,并且增加线程组中的循环(并在csv reader中使用循环)将失败,因为连接已经关闭(如果关闭连接模式匹配)。
如果我在这里问一些非常愚蠢的事情,请原谅我,因为我对JMeter很新:)
从Sampler的GitHub页面我发现类似于我的邮件匹配问题的问题:https://github.com/maciejzaleski/JMeter-WebSocketSampler/issues/19
我下载了1.0.2-SNAPSHOT源代码,添加了上述问题的第二个回复修改以及ServiceSocket.java文件更改代码(来自第68行),如下所示:
boolean matchFound = false;
if (responseExpression == null || responseExpression.matcher(msg).find()) {
logMessage.append("; matched response pattern");
closeLatch.countDown();
matchFound = true;
}
if (!disconnectPattern.isEmpty() && disconnectExpression.matcher(msg).find()) {
logMessage.append("; matched connection close pattern").append("\n");
closeLatch.countDown();
matchFound = true;
close(StatusCode.NORMAL, "JMeter closed session.");
}
if (!matchFound)
{
logMessage.append("; didn't match any pattern").append("\n");
} else {
logMessage.append("\n");
}
我以前从未编写过Java - 如果我应用的更改合理,我会非常感谢有经验的人发表评论。
现在我可以单独匹配消息并关闭连接。仍在寻找有关限制并发线程数量的帮助,而无需为消息重复使用相同的连接。
保持并发数量的用户(连接)受限的一种方法是使用CSV文件作为源并将EOF上的循环设置为true,将线程设置为并发目标,将循环计数设置为每个线程的连接数乘以消息数在CSV文件中。
在1.0.2上,这不会直接起作用,因为connectionId不会更改,插件会尝试使用旧的,已关闭的连接。在WebSocketSamples.java上,第69行:
if (isStreamingConnection()) {
if (connectionList.containsKey(connectionId)) {
socket = connectionList.get(connectionId);
if (socket.isConnected()){
socket.initialize(this);
return socket;
}
connectionList.remove(connectionId, socket);
}
修改似乎可以解决问题。消息似乎仍然是并行发送和性能相比,例如基于Node.JS的Thor似乎很差:(