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

fix(server) : dont apply eviction on rss over limit #4276

Merged
merged 2 commits into from
Dec 9, 2024

Conversation

adiholden
Copy link
Collaborator

@adiholden adiholden commented Dec 8, 2024

This PR disables the eviction due to rss over limit

The problem with current eviction logic when rss is above the rss threshold is that we evict to many keys to reduce the rss usage.

In the test that I changed now we just debug populate a little bit higher than rss max memory threshold
If you run the test you can see that the eviction kicks in but continues for long time as we evict items but rss does not decrease
in this test we create 754974 keys and eventually get to evict 307100 keys to just drop 200MB of rss memory, while the the total rss memory is 4G.
So we are evicting so many items to get below the rss threshold (decrease 200MB), and this is because deleting items does not immediately decrease rss but only when defrag logic kicks in and starts to defragment the memory and calls decommit we see decrease in rss.

We need to improve the logic before enabling it

Signed-off-by: adi_holden <adi@dragonflydb.io>
@@ -28,6 +28,9 @@ async def calculate_estimated_connection_memory(
for conn in connections:
await conn.close()

logging.info(
f"Estimated connection memory: {estimated_connections_memory // connections_number}."
)
return estimated_connections_memory // connections_number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can be removed

f'Current rss: {memory_info["used_memory_rss"]}. rss eviction threshold: {rss_max_memory * 0.9}.'
)
stats_info = await async_client.info("stats")
logging.info(f'Current evicted: {stats_info["evicted_keys"]}. Total keys: {num_keys}.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add an assertion after this loop to verify that at least 5% of the num_keys have been evicted

@BagritsevichStepan
Copy link
Contributor

I have a question: could we try to free some memory when we detect that the RSS memory usage significantly differs from the basic memory usage?

I’m not entirely sure where this logic should be implemented, but I believe it’s worth to add this.

# Test that used memory is less than 90% of max memory
memory_info = await async_client.info("memory")
assert (
memory_info["used_memory"] < max_memory * 0.9
), "Used memory should be less than 90% of max memory."
assert (
memory_info["used_memory_rss"] < rss_max_memory * 0.9
memory_info["used_memory_rss"] > rss_max_memory * 0.9
), "RSS memory should be less than 90% of rss max memory (max_memory * rss_oom_deny_ratio)."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit.: "RSS memory should be higher than 90% of rss max memory (max_memory * rss_oom_deny_ratio)."

Signed-off-by: adi_holden <adi@dragonflydb.io>
@adiholden adiholden changed the title test : eviction on rss over limit fix(server) : dont apply eviction on rss over limit Dec 9, 2024
@adiholden
Copy link
Collaborator Author

I have a question: could we try to free some memory when we detect that the RSS memory usage significantly differs from the basic memory usage?

I’m not entirely sure where this logic should be implemented, but I believe it’s worth to add this.

We should discuss how to improve the logic , I disabled it for now, see my updated description comment.
The improvement on this logic will not be in this week version

@adiholden adiholden merged commit 03d679a into main Dec 9, 2024
9 checks passed
@adiholden adiholden deleted the fix_test_eviction_on_rss branch December 9, 2024 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants