Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that sleep tasks are timed #1121

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions esrally/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,10 @@ def loads(self, s):
return super().loads(s)

async def on_request_start(session, trace_config_ctx, params):
meta = RallyAsyncElasticsearch.request_context.get()
# this can happen if multiple requests are sent on the wire for one logical request (e.g. scrolls)
if "request_start" not in meta:
meta["request_start"] = time.perf_counter()
RallyAsyncElasticsearch.on_request_start()

async def on_request_end(session, trace_config_ctx, params):
meta = RallyAsyncElasticsearch.request_context.get()
meta["request_end"] = time.perf_counter()
RallyAsyncElasticsearch.on_request_end()

trace_config = aiohttp.TraceConfig()
trace_config.on_request_start.append(on_request_start)
Expand All @@ -175,6 +171,18 @@ def init_request_context(self):
RallyAsyncElasticsearch.request_context.set(ctx)
return ctx

@classmethod
def on_request_start(cls):
meta = RallyAsyncElasticsearch.request_context.get()
# this can happen if multiple requests are sent on the wire for one logical request (e.g. scrolls)
if "request_start" not in meta:
meta["request_start"] = time.perf_counter()

@classmethod
def on_request_end(cls):
meta = RallyAsyncElasticsearch.request_context.get()
meta["request_end"] = time.perf_counter()

def return_raw_response(self):
ctx = RallyAsyncElasticsearch.request_context.get()
ctx["raw_response"] = True
Expand Down
6 changes: 5 additions & 1 deletion esrally/driver/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1630,7 +1630,11 @@ class Sleep(Runner):
"""

async def __call__(self, es, params):
await asyncio.sleep(mandatory(params, "duration", "sleep"))
es.on_request_start()
try:
await asyncio.sleep(mandatory(params, "duration", "sleep"))
finally:
es.on_request_end()

def __repr__(self, *args, **kwargs):
return "sleep"
Expand Down
4 changes: 4 additions & 0 deletions tests/driver/runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3328,6 +3328,8 @@ async def test_missing_parameter(self, sleep, es):
await r(es, params={})

self.assertEqual(0, es.call_count)
self.assertEqual(1, es.on_request_start.call_count)
self.assertEqual(1, es.on_request_end.call_count)
self.assertEqual(0, sleep.call_count)

@mock.patch("elasticsearch.Elasticsearch")
Expand All @@ -3339,6 +3341,8 @@ async def test_sleep(self, sleep, es):
await r(es, params={"duration": 4.3})

self.assertEqual(0, es.call_count)
self.assertEqual(1, es.on_request_start.call_count)
self.assertEqual(1, es.on_request_end.call_count)
sleep.assert_called_once_with(4.3)


Expand Down