'Performance test with jmeter based on response field

I am trying to run some performance tests on an ElasticSearch-backed JSON REST API, to try the impact of different filters on ElasticSearch.

I don't want to use the standard jmeter output, because there is too much clutter due to the over-the-wire time.

My API returns the time taken on ElasticSearch based on the took (tookInMillis in the java RestHighLevelClient we are using) property of the org.elasticsearch.action.search.SearchResponse. This is returned in a time_taken property of the API response.

This is a sample response

{
    "page_size": 1,
    "current_page": 1,
    "number_of_pages": 2495,
    "total_results": 2495,
    "additional_results_exist": false,
    "time_taken": 55,
    "results": [
        {       
                // object here, we don't really care
        },
        {            
                // object here, we don't really care
        }
    ],
    "request_id": "06e8001c-caf2-46f4-bf16-08c8d1ceb079"
}

So, the use case would be:

  • send requests via the Loop Controller
  • extract the time_taken property from the responses
  • get avg, 90%, 95%, 99%, min, max stats based on the time_taken response property.

I have found several references, mentioning JSON extractor, RegEx extactor, beanshell, but I didn't manage to get anything to work.

So, I would really appreciate a minimal working setup.

The jmeter version I am using is 5.4.3



Solution 1:[1]

We would really appreciate if you could provide the response from the ElasticSearch because we don't have any idea of how does it look like hence we cannot come up with a proper JSON Extractor setup.

I don't know what "time_taken" is, in Elastic Search it's called took:

{
  "took": 1, <--------------- I assume you want this value
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": null,
    "hits": [
      
    ]
  }
}

If this is the case it can be obtained using JSON Extractor configured like:

enter image description here

If you want to utilize JMeter listeners you can create a "fake" sampler using i.e. Dummy Sampler where you can control response time:

enter image description here

This way the "fake" sampler will have response time from the took ElasticSearch response JMeter will calculate the percentiles.

Demo:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dmitri T