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

Add support to disable record cache #2034

Merged
merged 1 commit into from
Oct 7, 2024
Merged

Conversation

muhamadazmy
Copy link
Contributor

Add support to disable record cache

Summary:
Since record cache will be used in multiple places. It's possible
to disable it by setting the memory budget to None. This way code
can still use the cache normally but no records will be cached.

All calls to Get will always return None if cache is disabled

@@ -122,7 +122,12 @@ impl<T: TransportConnect> ReplicatedLogletProvider<T> {
_metadata_store_client: metadata_store_client,
networking,
// todo(asoli): read memory budget from ReplicatedLogletOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

should we remove the todo then?

.max_capacity(memory_budget_bytes.try_into().unwrap_or(u64::MAX))
.eviction_policy(EvictionPolicy::lru())
.build();
/// Creates a new instance of RecordCache. If memory budges is None
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Creates a new instance of RecordCache. If memory budges is None
/// Creates a new instance of RecordCache. If memory budget is None

@@ -237,6 +237,13 @@ pub struct ReplicatedLogletOptions {
///
/// Retry policy for log server RPCs
pub log_server_retry_policy: RetryPolicy,

/// records_cache_memory_budget_bytes
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// records_cache_memory_budget_bytes
/// # In-memory RecordCache memory limit

/// Optional size of records cache in bytes.
/// If set to None, records cache will be disabled.
/// Defaults: 20M
pub records_cache_memory_budget_bytes: Option<usize>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pub records_cache_memory_budget_bytes: Option<usize>,
pub record_cache_memory_size: Option<usize>,

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you look at common.rs's configuration for inspiration? For configuration keys that accept bytes, we have some helpers to allow setting those values from human-friendly strings. A good example is rocksdb_total_memory_size


/// records_cache_memory_budget_bytes
///
/// Optional size of records cache in bytes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Optional size of records cache in bytes.
/// Optional size of record cache in bytes.

@@ -257,6 +264,7 @@ impl Default for ReplicatedLogletOptions {
Some(10),
Some(Duration::from_millis(2000)),
),
records_cache_memory_budget_bytes: Some(20_000_000), // 20MB
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
records_cache_memory_budget_bytes: Some(20_000_000), // 20MB
record_cache_memory_size: Some(20_000_000), // 20MB

Comment on lines 244 to 247
/// If set to None, record cache will be disabled.
/// Defaults: 20M
#[cfg_attr(feature = "schemars", schemars(with = "NonZeroByteCount"))]
pub record_cache_memory_size: Option<NonZeroByteCount>,
Copy link
Contributor

Choose a reason for hiding this comment

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

toml format doesn't support nulls, so we can't unset this from the configuration file. Perhaps we should allow this to be disabled by setting the size to zero instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah okay, good point. I wasn't sure if I should use None, or 0 as the value to disable the cache.

Summary:
Since record cache will be used in multiple places. It's possible
to disable it by setting the memory budget to None. This way code
can still use the cache normally but no records will be cached.

All calls to Get will always return None if cache is disabled
Copy link
Contributor

@AhmedSoliman AhmedSoliman left a comment

Choose a reason for hiding this comment

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

🚢 🚢 🚢 🚢

@muhamadazmy muhamadazmy merged commit 86e6966 into restatedev:main Oct 7, 2024
16 checks passed
@muhamadazmy muhamadazmy deleted the pr2034 branch October 7, 2024 11:41
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