Skip to content

Commit

Permalink
refactor(memory_test): Increase connections number
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 86d39c6 commit 096ebb7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tests/dragonfly/memory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ async def test_cache_eviction_with_rss_deny_oom(
"""

max_memory = 256 * 1024 * 1024 # 256 MB
first_fill_size = int(0.2 * max_memory) # 15% of max memory
second_fill_size = int(0.35 * max_memory) # Another 20% of max memory
rss_increase_size = int(0.3 * max_memory) # 30% of max memory
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

key_size = 1024 # 1 mb
num_keys_first_fill = first_fill_size // key_size
num_keys_second_fill = second_fill_size // key_size

# Step 1: Fill 15% of max memory using DEBUG POPULATE
# Fill 25% of max memory using DEBUG POPULATE
await async_client.execute_command("DEBUG", "POPULATE", num_keys_first_fill, "key", key_size)

await asyncio.sleep(1) # Wait for RSS heartbeat
Expand All @@ -145,10 +145,10 @@ async def test_cache_eviction_with_rss_deny_oom(
rss_before_connections = info_before_connections["used_memory_rss"]
logging.info(f"RSS after creating temporary large keys: {rss_before_connections}")

# Step 2: Increase RSS memory by 30% of max memory
# Increase RSS memory by 35% of max memory
# We can simulate RSS increase by creating new connections
# Estimate memory per connection
estimated_connection_memory = 20 * 1024 # 20 KB per connection
estimated_connection_memory = 10 * 1024 # 10 KB per connection
num_connections = rss_increase_size // estimated_connection_memory
connections = []
for _ in range(num_connections):
Expand All @@ -165,12 +165,12 @@ async def test_cache_eviction_with_rss_deny_oom(

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

# Step 3: Attempt to insert another 30% of data
# Attempt to insert another 30% of data
await async_client.execute_command("DEBUG", "POPULATE", num_keys_second_fill, "key2", key_size)

await asyncio.sleep(1) # Wait for RSS heartbeat

# Step 4: Check that eviction has occurred
# 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."

Expand Down

0 comments on commit 096ebb7

Please sign in to comment.