Skip to content

Added minimum in-memory cache size#467

Draft
jrhyness wants to merge 2 commits intoKuadrant:mainfrom
jrhyness:jr_466
Draft

Added minimum in-memory cache size#467
jrhyness wants to merge 2 commits intoKuadrant:mainfrom
jrhyness:jr_466

Conversation

@jrhyness
Copy link

Description
If the cache size is not specified via --cache and there is no available memory reported, it gets set to 0 and qualified counters cannot be cached. This PR introduces a minimum cache size, as proposed in the linked issue.

Related Issue
#466

Tests
With no available memory reported:

{"timestamp":"2026-01-29T17:00:56.598806Z","level":"WARN","fields":{"message":"No cache size provided. Using 1000 entries (70% of 0MB available memory with a 1000 entry minimum)."},"target":"limitador_server"}

With available memory:

{"timestamp":"2026-01-29T17:03:42.177875Z","level":"WARN","fields":{"message":"No cache size provided. Using 144703856 entries (70% of 15771MB available memory with a 1000 entry minimum)."},"target":"limitador_server"}

Signed-off-by: Jim Rhyness <jrhyness@ca.ibm.com>
Comment on lines 888 to 890
let size = std::cmp::max(MIN_CACHE_SIZE,(memory
/ (std::mem::size_of::<Counter>() + 16/* size_of::<AtomicExpiringValue>() */) as f64)
as u64;
as u64);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this is entirely safe - if 1000 counters is > free_mem won't we oom?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks. Good point, and would oom happen if the server was explicitly started with a --cache size ?

@adam-cattermole
Copy link
Member

Thanks for the PR! For more context - this issue arose as on an overcommitted machine I had free_size report 0 and use a cache size of 0 (so all of my qualified counters were thrown away). My expectation was more so that if the size (70% of free mem) was below some threshold (unsure on the best value for this) we just exit out with an error.

@jrhyness
Copy link
Author

#466

Thanks for the PR! For more context - this issue arose as on an overcommitted machine I had free_size report 0 and use a cache size of 0 (so all of my qualified counters were thrown away). My expectation was more so that if the size (70% of free mem) was below some threshold (unsure on the best value for this) we just exit out with an error.

I hit this as well. In my case, on a Mac, sys.available_memory() reported 0 but sys.free_memory() was quite a bit more. I'll revisit this. Thanks again.

@jrhyness jrhyness marked this pull request as draft January 30, 2026 13:51
- Changed sys.available_memory to sys.free_memory ( TODO: test other OSes )

Signed-off-by: Jim Rhyness <jrhyness@redhat.com>
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