我们如何使用Jmeter运行多并发会话Websocket测试?

发布于 2025-02-10 00:40:06 字数 1791 浏览 0 评论 0 原文

我正在使用 jmeter noreferrer“> jmeter websocket Samplers 执行WebSocket Latence Latence Latence Latency测试。我的测试计划包含4个线程组。
首先,这是我正在生产的操作顺序,每个步骤均分组为线程组。和第一个连接。在执行第二名之前,对主持人的操作被缓存。操作是因为第三。同一主持人的操作将继续使用此连接。

def connection = sampler.threadLocalCachedConnection
props.put('presenterConnection', connection.get())

第二个&参与者的第四连接。步骤4的参与者将继续使用第2步中创建的连接。

  1. 主持人连接到WS,创建会话&保存会话ID
  2. 参与者连接到WS&订阅“保存会话”
  3. 主持人会发送命令
  4. 参与者读取主持人发送的命令,

它按照单个会话的预期工作。但是,我遇到了Websocket单读采样器的问题,这是在我运行2次并发会话时从主持人发送的第四次操作。

我将每个线程组的线程属性中的“线程数”更改为2。主持人能够在第一个创建2个会话ID。手术。我添加了“线间通信后处理器”,以将会话ID存储在队列中,以便可以将其传递给其他线程组。它在前3个操作中工作,直到读取从主持人发送的命令的最后一次操作中访问Websocket单读采样器。

我有一个JSR223预处理器,可以在步骤2使用缓存的连接。

def connection = props.get('Participant1Connection')
sampler.threadLocalCachedConnection.set(connection)

该问题是在最后一个操作的2个线程的响应主体中找到的。第一个会话ID没有使用。步骤4处的第一个用户是使用第二个会话ID,第二个响应主体是空的,因为两个用户正在使用同一会话。我该怎么办来解决此问题,让2个用户从相应地创建的两个会话中读取数据?

I was using the JMeter WebSocket Samplers to perform WebSocket latency testing. My test plan contains 4 thread groups.
Firstly, here is the order of operations I was producing, each step is grouped in a thread group. And the connection for the 1st. operation on Presenter was cached before executing the 2nd. operation because the 3rd. operation, the same Presenter, is gonna continue to use this connection.

def connection = sampler.threadLocalCachedConnection
props.put('presenterConnection', connection.get())

Same idea for the 2nd & 4th connection for Participant. The participant at step 4 is gonna continue to use the connection created at step 2.

  1. Presenter connects to WS, creates session & saves the session id
  2. Participant connects to WS & subscribes to the saved session
  3. Presenter sends out commands
  4. Participant reads the commands that were sent by Presenter

It worked as expected with single session. However I ran into an issue with the WebSocket Single Read Sampler at the 4th operation of reading commands that were sent from Presenter when I was running 2 concurrent sessions.

I changed the "Number of Threads" to 2 in the thread properties of each thread group. The presenter was able to create 2 session IDs at the 1st. operation. And I added the "Inter-Thread Communication PostProcessor" to store the session IDs in a queue such that it's able to be passed to other thread group. It worked for the first 3 operations until it went to the WebSocket Single Read Sampler in the last operation of reading the commands that were sent from the Presenter.

I had a JSR223 PreProcessor in place to use the cached connection at step 2.

def connection = props.get('Participant1Connection')
sampler.threadLocalCachedConnection.set(connection)

The issue was found in the response body of the 2 threads of the last operation. The first session ID was not being used. The first user at step 4 was using the 2nd session ID and the 2nd response body was empty because the 2 users were using the same session. What shall I do to fix this issue to have 2 users reading data from 2 sessions created accordingly?

enter image description here
enter image description here
enter image description here
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叹倦 2025-02-17 00:40:06

这通常是当人们在不了解代码的情况下复制代码而发生的事情。此外,如果您需要在线程组之间传递数据,则可能的测试设计存在问题。

任何。

jmeter documentation

属性与变量不同。变量是线程的本地; 属性都是所有线程的共同点

因此当您拥有&gt时; 1线程(虚拟用户)第二个线程覆盖 presenterConnection 属性的值,因此无论您拥有多少个线程,他们都在尝试使用 presenterConnection

我 的单个实例期望您需要每个线程连接,在这种情况下,您应该将当前线程编号添加为属性密钥的前缀/后缀,因此:

  • 1st thread将使用 presenterConnection1
  • 第二个线程将使用 PresenterConnection2
  • 等。

对“您的”代码的修改将类似:

props.put('presenterConnection' + ctx.getThreadNum(), connection.get())

类似地用于访问连接。

在上面的示例中 ctx 代表类实例,请参见您应该使用Groovy 文章的前8个Jmeter Java类,以获取有关此和其他 jmeter api 可用于JSR223测试元素的速记。

This is something which normally happens when people copypaste the code without understanding what it is doing. Moreover if you need to pass data between thread groups most probably there is a problem with your test design.

Whatever.

As per JMeter Documentation:

Properties are not the same as variables. Variables are local to a thread; properties are common to all threads

So when you have > 1 thread (virtual user) the second thread overwrites the value of the presenterConnection property so no matter how many threads you have they all are trying to use single instance of the presenterConnection

My expectation is that you want a connection per thread, in this case you should add current thread number as a prefix/postfix for the property key so:

  • 1st thread would use presenterConnection1
  • 2nd thread would use presenterConnection2
  • etc.

Amendment to "your" code would be something like:

props.put('presenterConnection' + ctx.getThreadNum(), connection.get())

similarly for accessing the connection.

In the above example ctx stands for JMeterContext class instance, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on this and other JMeter API shorthands available for the JSR223 Test Elements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文