Search code examples
locust

How to get response-time of a specific request in Locust?


Is there a way to get the average/median/percentile response-time for a specific request (not for the aggregated result)?

I know that using following code I can get the aggregated response times. self.environment.stats.total.get_response_time_percentile(0.95)

Could it be that the only way to get these numbers is to extract them from the CSV output? Hopefully not...


Solution

  • Looking through the code, there's this test that seems to show how to do what you want:

    self.environment.stats.get("/ultra_fast", "GET").num_requests
    

    /ultra_fast was an endpoint that the test hit with a GET request. It then gets the number of requests and failures to assert the number I'd each is 1. So you should be able to do .get_response_time_percentile(0.95) on that instead. That's confirmed by the code that prepares the stats for the web UI.

    This sort of question shows how great open source code is. You can look or search through it to see how things work and get ideas on how to do what you want. In this case, I searched for self.environment.stats and looked for uses that weren't .total. I encourage you to try that yourself next time. Good luck!