Jmeter TCP Sampler-如何重用线程之间的连接? [英] Jmeter TCP Sampler - How to reuse connection between threads?

查看:853
本文介绍了Jmeter TCP Sampler-如何重用线程之间的连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在JMeter的ThreadGroup下设置了TCP采样器.数据是从CSV文件中选取的.数据的第一行用于身份验证,所有后续行均为实际参数数据.像下面这样

I have setup a TCP sampler under a ThreadGroup in JMeter. The data is picked from a CSV file. The first line of data is for the authentication and all subsequent rows are the actual parameter data. Something like below,

AAAAAAA21
BBBBBBBCCCCCCCDDDDDDD
BBBBBBBCCCCCCCDDDDDDD
BBBBBBBCCCCCCCDDDDDDD

我想要的是,例如,如果线程组连续使用10个线程运行,则第一个线程获取第一行数据,与服务器建立连接并进行身份验证.所有后续线程都使用相同的连接(而不是每次都创建新的连接),只需将数据发送到服务器即可.这样做的原因是,数据模拟了一个设备,该设备发送第一个数据包进行身份验证并创建连接,而所有后续数据包都在同一连接上发送数据.我想使用JMeter模拟设备测试.

What I want is that if the thread group is run continuously with 10 threads for example, the first thread gets the first line of data, makes the connection with server and authenticates. All subsequent threads use the same connection (instead of creating a new connection every time) and simply send data to the server. The reason for doing this is that the data simulates a device which sends the first packet for authentication and creates the connection and all subsequent data packets send data on the same connection. I want to simulate the device testing using JMeter.

我发现的局限性是JMeter正在为每个线程创建一个新的连接,并且在线程退出时该连接将被关闭.似乎没有办法在threadGroup中的所有线程之间共享连接,或者也许我不知道这种方式.

The limitation I find is that JMeter is creating a new connection for every thread and the connection gets closed when the thread exits. There seems to be no way to share the connection between all threads in the threadGroup or maybe there is a way which I am not aware of.

寻找可以测试此用例的方式

Looking for ways in which I can test this usecase

推荐答案

不幸的是,不可能共享不同线程之间的连接,因为每个线程代表一个单独的虚拟用户,因为虚拟用户彼此之间一无所知.此外,如果您尝试在不同线程之间共享连接,则一次只能使用一个连接(否则,您将遇到多个线程同时写入同一连接而导致数据损坏的情况)

Unfortunately there is no possibility to share a connection between different threads as each thread represents a separate virtual user as virtual users don't know anything about each other. Moreover if you will try to share connection between different threads only one will be able to use connection at a time (otherwise you will run into the situation when several threads are concurrently writing into the same connection resulting in corrupt data)

因此您可以为每个虚拟用户使用1个连接(即,您总共有10个连接)

So you can use 1 connection per virtual user (i.e. you will have 10 connections in total)

  1. 循环控制器添加到线程组,然后在Forever上打钩框或将循环计数"设置为-1-这样子采样器将永远运行
  2. 将TCP Sampler添加为Loop Controller的子级,并在Re-use connection框上打勾,以便您的测试计划如下:

  1. Add Loop Controller to your Thread Group and either tick Forever box or set Loop Count to -1 - this way children sampler(s) will run forever
  2. Add TCP Sampler as a child of the Loop Controller and tick Re-use connection box so your test plan would look like:

请参见如何使用以下方法加载测试TCP协议服务有关更多信息,请参见JMeter 文章.

这篇关于Jmeter TCP Sampler-如何重用线程之间的连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆