Skip to content

Commit

Permalink
chore: connection pipeline cache grows without shrinking
Browse files Browse the repository at this point in the history
Signed-off-by: kostas <[email protected]>
  • Loading branch information
kostasrim committed Jan 21, 2025
1 parent 986ef7c commit 33d4a49
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/dragonfly/connection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,3 +1051,60 @@ async def test_hiredis(df_factory):
server.start()
client = base_redis.Redis(port=server.port, protocol=3, cache_config=CacheConfig())
client.ping()


@dfly_args({"proactor_threads": 1})
async def test_pipeline_cache_size(df_factory):
server = df_factory.create(proactor_threads=1)
server.start()

# Start 1 client.
good_client = server.client()

await good_client.execute_command("set foo bar")

bad_actor_client = server.client()

info = await bad_actor_client.info()

# Cache is empty.
assert info["pipeline_cache_bytes"] == 0
assert info["dispatch_queue_bytes"] == 0

async def push_pipeline(bad_actor_client):
# Fill cache.
p = bad_actor_client.pipeline(transaction=True)
for i in range(1):
p.lpush(str(i), "V")
await p.execute()

await push_pipeline(bad_actor_client)
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

# Whoops, total pipeline_cache_bytes haven't changed. If a workload aggregates a bunch
# pipeline_cache_bytes because it recycled too many messages, they won't gradually be released
# if one command (one connection out of `n` connections) dispatches async. Only 1 command out of
# n connections must be dispatched async and the pipeline won't gradually be relesed.
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()

# Pipeline cache bytes remained constant :(
assert old_pipeline_cache_bytes == info["pipeline_cache_bytes"]
assert info["dispatch_queue_bytes"] == 0

# Now drain it
for i in range(30):
await good_client.execute_command(f"set foo{i} bar")

info = await good_client.info()

# Drained
assert info["pipeline_cache_bytes"] == 0
assert info["dispatch_queue_bytes"] == 0

0 comments on commit 33d4a49

Please sign in to comment.