-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chore: connection pipeline cache does not shrink #4491
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
Changes from all commits
33d4a49
5696c66
aa4eb3d
0cbdc1a
95df3ea
20b405b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1061,7 +1061,7 @@ async def test_timeout(df_server: DflyInstance, async_client: aioredis.Redis): | |
assert len(clients) == 2 | ||
|
||
await asyncio.sleep(2) | ||
|
||
@assert_eventually | ||
async def wait_for_conn_drop(): | ||
clients = await async_client.client_list() | ||
|
@@ -1070,4 +1070,84 @@ async def wait_for_conn_drop(): | |
|
||
await wait_for_conn_drop() | ||
info = await async_client.info("clients") | ||
assert int(info["timeout_disconnects"]) >= 1 | ||
assert int(info["timeout_disconnects"]) >= 1 | ||
|
||
|
||
# Test that the cache pipeline does not grow or shrink under constant pipeline load. | ||
@dfly_args({"proactor_threads": 1, "pipeline_squash": 9}) | ||
async def test_pipeline_cache_only_async_squashed_dispatches(df_factory): | ||
server = df_factory.create() | ||
server.start() | ||
|
||
client = server.client() | ||
|
||
async def push_pipeline(size=1): | ||
p = client.pipeline(transaction=True) | ||
for i in range(size): | ||
p.info() | ||
res = await p.execute() | ||
return res | ||
|
||
# Dispatch only async command/pipelines and force squashing. pipeline_cache_bytes, | ||
# should be zero because: | ||
# We always dispatch the items that will be squashed, so when `INFO` gets called | ||
# the cache is empty because the pipeline consumed it throughout its execution | ||
for i in range(0, 30): | ||
# it's actually 11 commands. 8 INFO + 2 from the MULTI/EXEC block that is injected | ||
# by the client. Connection fiber yields to dispatch/async fiber when | ||
# ++async_streak_len_ >= 10. The minimum to squash is 9 so it will squash the pipeline | ||
# and INFO ALL should return zero for all the squashed commands in the pipeline | ||
res = await push_pipeline(8) | ||
for i in range(1): | ||
assert res[i]["pipeline_cache_bytes"] == 0 | ||
|
||
# Non zero because we reclaimed/recycled the messages back to the cache | ||
info = await client.info() | ||
assert info["pipeline_cache_bytes"] > 0 | ||
|
||
|
||
# Test that the pipeline cache size shrinks on workloads that storm the datastore with | ||
# pipeline commands and then "back off" by gradually reducing the pipeline load such that | ||
# the cache becomes progressively underutilized. At that stage, the pipeline should slowly | ||
# shrink (because it's underutilized). | ||
@dfly_args({"proactor_threads": 1}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add some comments on this test |
||
async def test_pipeline_cache_size(df_factory): | ||
server = df_factory.create(proactor_threads=1) | ||
server.start() | ||
|
||
# Start 1 client. | ||
good_client = server.client() | ||
bad_actor_client = server.client() | ||
|
||
async def push_pipeline(bad_actor_client, size=1): | ||
# Fill cache. | ||
p = bad_actor_client.pipeline(transaction=True) | ||
for i in range(size): | ||
p.lpush(str(i), "V") | ||
await p.execute() | ||
|
||
# Establish a baseline for the cache size. We dispatch async here. | ||
await push_pipeline(bad_actor_client, 32) | ||
info = await good_client.info() | ||
|
||
old_pipeline_cache_bytes = info["pipeline_cache_bytes"] | ||
assert old_pipeline_cache_bytes > 0 | ||
assert info["dispatch_queue_bytes"] == 0 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We cam drain the |
||
for i in range(30): | ||
await push_pipeline(bad_actor_client) | ||
await good_client.execute_command(f"set foo{i} bar") | ||
|
||
info = await good_client.info() | ||
|
||
# Gradually release pipeline. | ||
assert old_pipeline_cache_bytes > info["pipeline_cache_bytes"] | ||
assert info["dispatch_queue_bytes"] == 0 | ||
|
||
# Now drain the full cache. | ||
async with async_timeout.timeout(5): | ||
while info["pipeline_cache_bytes"] != 0: | ||
await good_client.execute_command(f"set foo{i} bar") | ||
info = await good_client.info() | ||
|
||
assert info["dispatch_queue_bytes"] == 0 |
Uh oh!
There was an error while loading. Please reload this page.