diff --git a/locust/clients.py b/locust/clients.py index f8a7817be0..4b5d91f4eb 100644 --- a/locust/clients.py +++ b/locust/clients.py @@ -123,10 +123,12 @@ def request(self, method, url, name=None, catch_response=False, context={}, **kw # prepend url with hostname unless it's already an absolute URL url = self._build_url(url) - start_timestamp = time.perf_counter() # high precision timestamp - start_time = time.time() # seconds since epoch - + + start_time = time.time() + start_perf_counter = time.perf_counter() response = self._send_request_safe_mode(method, url, **kwargs) + response_time = (time.perf_counter() - start_perf_counter) * 1000 + url_after_redirect = (response.history and response.history[0] or response).request.path_url if self.user: @@ -135,7 +137,7 @@ def request(self, method, url, name=None, catch_response=False, context={}, **kw # store meta data that is used when reporting the request to locust's statistics request_meta = { "request_type": method, - "response_time": (time.perf_counter() - start_timestamp) * 1000, + "response_time": response_time, "name": name or url_after_redirect, "context": context, "response": response, diff --git a/locust/contrib/fasthttp.py b/locust/contrib/fasthttp.py index 198c4fb9ab..6b38ca2ead 100644 --- a/locust/contrib/fasthttp.py +++ b/locust/contrib/fasthttp.py @@ -161,7 +161,6 @@ def request( # prepend url with hostname unless it's already an absolute URL url = self._build_url(path) - start_timestamp = time.perf_counter() # high precision timestamp start_time = time.time() # seconds since epoch if self.user: @@ -186,9 +185,9 @@ def request( old_redirect_response_codes = self.client.redirect_resonse_codes self.client.redirect_resonse_codes = [] + start_perf_counter = time.perf_counter() # send request, and catch any exceptions response = self._send_request_safe_mode(method, url, payload=data, headers=headers, **kwargs) - # store meta data that is used when reporting the request to locust's statistics request_meta = { "request_type": method, "name": name or path, @@ -210,7 +209,7 @@ def request( try: request_meta["response_length"] = len(response.content or "") except HTTPParseError as e: - request_meta["response_time"] = (time.perf_counter() - start_timestamp) * 1000 + request_meta["response_time"] = (time.perf_counter() - start_perf_counter) * 1000 request_meta["response_length"] = 0 request_meta["exception"] = e self.environment.events.request.fire(**request_meta) @@ -219,7 +218,7 @@ def request( # Record the consumed time # Note: This is intentionally placed after we record the content_size above, since # we'll then trigger fetching of the body (unless stream=True) - request_meta["response_time"] = int((time.perf_counter() - start_timestamp) * 1000) + request_meta["response_time"] = int((time.perf_counter() - start_perf_counter) * 1000) if catch_response: return ResponseContextManager(response, environment=self.environment, request_meta=request_meta)