Skip to content

Commit

Permalink
refactor: small fix
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Bagritsevich <stefan@dragonflydb.io>
  • Loading branch information
BagritsevichStepan committed Nov 22, 2024
1 parent 096ebb7 commit 358c45c
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions tests/dragonfly/memory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ async def test_cache_eviction_with_rss_deny_oom(

max_memory = 256 * 1024 * 1024 # 256 MB
first_fill_size = int(0.25 * max_memory) # 25% of max memory
second_fill_size = int(0.3 * max_memory) # Another 35% of max memory
rss_increase_size = int(0.35 * max_memory) # 30% of max memory
second_fill_size = int(0.3 * max_memory) # Another 30% of max memory
rss_increase_size = int(0.3 * max_memory) # 30% of max memory

key_size = 1024 # 1 mb
num_keys_first_fill = first_fill_size // key_size
Expand All @@ -143,12 +143,16 @@ async def test_cache_eviction_with_rss_deny_oom(
# Get RSS memory before creating new connections
info_before_connections = await async_client.info("memory")
rss_before_connections = info_before_connections["used_memory_rss"]
logging.info(f"RSS after creating temporary large keys: {rss_before_connections}")
logging.info(f"RSS before creating new connections: {rss_before_connections}")

# Increase RSS memory by 35% of max memory
# tmp
evicted_keys_before_connections = info_before_connections["evicted_keys"]
logging.info(f"Evicted keys before creating new connections: {evicted_keys_before_connections}")

# Increase RSS memory by 30% of max memory
# We can simulate RSS increase by creating new connections
# Estimate memory per connection
estimated_connection_memory = 10 * 1024 # 10 KB per connection
estimated_connection_memory = 15 * 1024 # 15 KB per connection
num_connections = rss_increase_size // estimated_connection_memory
connections = []
for _ in range(num_connections):
Expand All @@ -163,6 +167,10 @@ async def test_cache_eviction_with_rss_deny_oom(
rss_after_connections = info_after_connections["used_memory_rss"]
logging.info(f"RSS after creating new connections: {rss_after_connections}")

# tmp
evicted_keys_after_connections = info_after_connections["evicted_keys"]
logging.info(f"Evicted keys after creating new connections: {evicted_keys_after_connections}")

assert rss_after_connections > rss_before_connections, "RSS memory should have increased."

# Attempt to insert another 30% of data
Expand All @@ -172,7 +180,11 @@ async def test_cache_eviction_with_rss_deny_oom(

# Check that eviction has occurred
info = await async_client.info("stats")
assert info.get("evicted_keys", 0) > 0, "Eviction should have occurred due to memory pressure."
rss = info["used_memory_rss"]
evicted_keys = info["evicted_keys"]
logging.info(f"RSS before creating new connections: {rss}")
logging.info(f"Evicted keys before creating new connections: {evicted_keys}")
assert evicted_keys > 0, "Eviction should have occurred due to rss memory pressure."

for conn in connections:
await conn.close()

0 comments on commit 358c45c

Please sign in to comment.