Skip to content

Commit

Permalink
rename start_timestamp to start_perf_counter to differentiate it from…
Browse files Browse the repository at this point in the history
… "start_time"
  • Loading branch information
cyberw committed Oct 11, 2021
1 parent 0a7dccc commit 747a55e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 6 additions & 4 deletions locust/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions locust/contrib/fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 747a55e

Please sign in to comment.