2
votes

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

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.

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

1

1 Answers

1
votes

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)

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

  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:

    JMeter TCP Reuse Connection

See How to Load Test TCP Protocol Services with JMeter article for more information.