Search code examples
algorithmgroovyjmeterperformance-testingjsr223

How to send requests with varying number of payload elements while reaching a desired average of all elements at the end of the script?


I have a need to continuously generate the same HTTP request over a defined duration but with a random varying number of objects in the body (within a 1-99 range), on each thread loop and my requirement is that at the end of the script I should end up with a calculated average of 3 such objects. So I think that I need to somehow store the number of objects from each HTTP request (under concurrent heavy load) and then influence the creation of these objects during runtime so that I may reach my goal of 3 at the end of the script duration.

In Jmeter, I have a HTTP Request Sampler with some static XML body and some variable which holds a place in which I insert dynamically generated data. I have a JSR223 Preprocessor as a child element for the purpose of the dynamical data generation. That preprocessor has code which can generate one XML node or more based on an int parameter. If I say I want to create 2 XML nodes, I set that parameter to 2. I can create 1 or 99 such nodes. Then I insert this XML nodes into the body payload of the HTTP Request Sampler in the variable place, on each request.

Example of what I call XML nodes. In this example I have 3 such nodes. One node is between tags:

  <object a='false' b='false' pReqID='ID00001'>
    <al ad='2021-09-20' alc='bla' bla='2021-09-20T11:00:00.000Z' sn='AB8912' />
    <doc docType='P' docId='555551555' name='Braiden' date='12/31/2022' />
  </object>
  <object a='false' b='false' pReqID='ID00002'>
    <al ad='2021-09-20' alc='bla' bla='2021-09-20T11:00:00.000Z' sn='AB8912' />
    <doc docType='P' docId='100000001' name='Dominique' date='12/10/2024' />
  </object>
  <object a='false' b='false' pReqID='ID00003'>
    <al ad='2021-09-20' alc='bla' bla='2021-09-20T11:00:00.000Z' sn='AB8912' />
    <doc docType='P' docId='100000002' name='Joyce' date='11/15/2025' />
  </object>

My need is to generate HTTP requests with varying XML nodes in the body each time, but at the end of the script duration, I should end up with a calculated number of 3 .

I know that I can do a random function between 1 and 99 to generate random nodes inside my HTTP request body on each run, but I don't know how to control the average number of nodes as the script is running so that by the time the script is over I would end up with a number of sent samples and these samples should have bodies with varying content nodes between 1 and 99, but on average the calculated result should be 3.

For example let's say that I send the same HTTP request with 2 threads and 5 loops, so 10 times in total, but of those 10 times, the body of the request contained 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10 XML nodes. On average this would be 5.5, but I don't know how to measure and control/influence this result according to my wants from JMeter.

How could JMeter check the average and control/influence the nodes generation on each request so that on average after the script has run for a certain duration (2hours) this average becomes what I want it to be?


Solution

  • I don't think it's possible because you don't know how many iterations will happen in 2 hours. You can get quite close to 3, but if the number of calls fluctuates the mean will fluctuate as well.

    If you switch to fixed number of iterations from 2 hours execution you could go for: