Search code examples
jmeterperformance-testingload-testingjmeter-pluginsbeanshell

How to measure response size data for individual sampler during load test


How to measure size of response data of multiple http samplers in JMeter. I need to find the individual size of all http sampler during the load, not for overall. I am using Beanshell sampler but it is giving overall size not individual for each sampler.

import java.util.io.*;
import java.lang.io.*;
test = prev.getResponseDataAsString().length();
text = ctx.getCurrentSampler().getName();
log.info("Sampler Name: " +text+ ": Size: " +test);
if(text.equalsIgnoreCase("Test Sampler"))
{
 props.put("totalsize",Integer.parseInt("0"));
}
else
{
  props.put("totalsize", (props.get("totalsize")!=null?props.get("totalsize"):0) + test);
}
log.info("totalsize is = "+props.get("totalsize"));


I am using Beanshell sampler but it is giving overall size not individual for each sampler.
I need total individual response size for each sampler during my load test.

Solution

    1. First of all I don't understand fully what your code is doing. You're using props shorthand for storing the data and the properties are global for the whole JVM so if you run your test with > 1 user the next thread will overwrite the value set by the previous thread. Maybe you should use vars instead which is for JMeterVariables which are thread-local?

    2. I believe JMeter saves it into its .jtl results file by default, take a look at bytes column which contains response size for each individual sampler.

      enter image description here

    3. Also be aware that starting from JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting mainly for performance reasons so consider migrating. More information: Beanshell vs. JSR223 vs. Java For JMeter: Complete Showdown