1
votes

I want to check the performance of API using Apache Jmeter 2.11. The response data for HTTP request is as follows:

{
"global_id": 11111,
"name": "IMG_001.JPG",
"width": "1111",
"height": "1111",
"time_taken": {
  "segment_1_time": 1,
  "segment_2_time": 1,
  "segment_3_time": 27,
  "segment_4_time": 1,
  "segment_5_time": 56,
  "segment_6_time": 8,
  "total_time": 94
 }
}

Thread Properties: Number of threads: 1, Ramp-up period(in seconds): 1, Loop Count: 50

I want to calculate the aggregate mean time taken by each segment for all the responses i.e. Mean time taken by segment_1, Mean time taken by segment_2, Mean time taken by segment_3, Mean time taken by segment_4, Mean time taken by segment_5 and Mean time taken by segment_6.

What are the post processors and javascript required for calculating the mean segments' times?

2
Do you mean avg response time for each Loop?Nithin CV
No. of threads:1 and Loop Count:50. That means total 50 requests will be sent to server. I want to calculate Mean time taken by each segment across the 50 responses. For instance, first response has "Segment_1_time":1, second response has "Segment_1_time":3, third response has "segment_1_time": 5 and so on. The mean time for segment_1 will be (1+3+5)/3 = 3. I want to calculate the response time for each segment(1,2,...,6) in this way.user3463296

2 Answers

0
votes

I think you need to use regular expression extractor with beanshell post processor,

First, you need to extract your segment value using regular expression extractor with proper Regex like segment_1_time":(.*?), etc.

Next, use beanshell post processor to calculate the Total value of each segment time,

var CurrentSegmentValue=vars.get("SEGMENT1");//Current segment value from Regular expression extractor

log.info("CurrentSegmentValue = "+CurrentSegmentValue);

/* You need to use this logic to calculate other segment values like SEGMENT2,3,4,5,6 etc
 *  but remember this method makes performace bottle neck when you have tested with higher number of threads
 *  and result may be differ see any appropriate web links for Jmeter performance tuning and suggested to use 64 bit JVM
 */

var totalvalueString=vars.get("totalValue");

if(totalvalueString==null)
{
vars.put("totalValue","0");
}

int totalValue= java.lang.Integer.parseInt(CurrentSegmentValue)+java.lang.Integer.parseInt(totalvalueString);

vars.put("totalValue",""+totalValue);

log.info("Final Total Value:"+totalValue);

//Going to next loop
/*Divide total value with number of threads you will get your mean time*/  

In above code each segment value from response is saved and added with previous value.

Finally you can divide it with number of threads to get mean
Hopes this may help you and refer this link for more information about bean shell scripting

0
votes

If you are open to try other test tool, you may want to look at NetGend. Here is a blog that shows how this scenario is implemented on NetGend platform - so simple that you don't need a lot of programming background to understand it.

Good luck.