Search code examples
jmeterbeanshell

Bean Shell Script Returning 0 for latency in Jmeter


I am using BeanShell Sampler to make a TCP connection/request as part of the load test. The problem now is that the results reported by jmeter always have latency as 0. I am not sure why this is the case. Any ideas?


Solution

  • JMeter doesn't know what does your code do therefore it's not smart enough (yet?) to automatically calculate the latency for you so it's up to you to figure out the latency and report it via SampleResult.setLatency() function somewhere in your code like:

    SampleResult.setLatency(1234L);
    

    Also since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting as Groovy has much better performance comparing to Beanshell

    And last but not the least, if your code only makes a TCP request you can use TCP Sampler or HTTP Raw Request Sampler, it will be faster and consume less resources