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

feat: Add support for in-memory caching #1028

Merged
merged 2 commits into from
Feb 20, 2023
Merged

feat: Add support for in-memory caching #1028

merged 2 commits into from
Feb 20, 2023

Conversation

Swatinem
Copy link
Member

Fixes #994 by adding the infrastructure and defaults for in-memory caching.

This implements weighing of cache items (based on a bunch of size_ofs),
and per-item TTL based on the ExpirationTime.

Each cache defaults to ~100k in-memory size, which should be roughly ~1k items.
Except for object_meta which defaults to ~100M in-memory and is very hot,
and cficaches which defaults to ~400M and are expensive to parse, with variable per-item weight.

@Swatinem
Copy link
Member Author

Well, the test failure shows that we indeed need to have immutable caches before we start to do anything with in-memory caching :-(

@Swatinem Swatinem force-pushed the ref/memory-cache branch 3 times, most recently from a7086be to 44659e7 Compare February 15, 2023 11:06
@codecov
Copy link

codecov bot commented Feb 15, 2023

Codecov Report

Merging #1028 (fb9cb87) into master (9c2135e) will increase coverage by 0.18%.
The diff coverage is 94.56%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1028      +/-   ##
==========================================
+ Coverage   74.96%   75.15%   +0.18%     
==========================================
  Files          83       83              
  Lines       11912    11981      +69     
==========================================
+ Hits         8930     9004      +74     
+ Misses       2982     2977       -5     

Fixes #994 by adding the infrastructure and defaults for in-memory caching.

This implements weighing of cache items (based on a bunch of `size_of`s),
and per-item TTL based on the `ExpirationTime`.

Each cache defaults to ~100k in-memory size, which should be roughly ~1k items.
Except for `object_meta` which defaults to ~100M in-memory and is very hot,
and `cficaches` which defaults to ~400M and are expensive to parse.
@Swatinem Swatinem marked this pull request as ready for review February 17, 2023 08:59
@Swatinem Swatinem requested a review from a team February 17, 2023 08:59
Comment on lines +129 to +130
// FIXME: `object_meta` caches treat download errors as `malformed`
config.caches.derived.retry_malformed_after = Some(Duration::ZERO);
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this has been broken ever since https://github.com/getsentry/symbolicator/pull/516/files#diff-2f856962a69fa5bec61ba23e49b676ce0d95db30e21d49f938da24302cb8b3b4R343-R349

object_meta are a Derived cache, so server errors were only being retried after the "malformed" timeout since basically forever.

crates/symbolicator-service/src/caching/memory.rs Outdated Show resolved Hide resolved
Comment on lines +296 to +305

/// Capacity (in bytes) for the in-memory `object_meta` Cache.
///
/// Defaults to `100 MiB (= 104_857_600)`.
pub object_meta_capacity: u64,

/// Capacity (in bytes) for the in-memory `cficaches` Cache.
///
/// Defaults to `400 MiB (= 419_430_400)`.
pub cficaches_capacity: u64,
Copy link
Contributor

Choose a reason for hiding this comment

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

To be honest I'm not too fond of the entire InMemoryCacheConfig struct. For these options in particular I think it would be nicer if they lived directly in their respective cache configurations (i.e. add an in_memory_capacity field to DownloadedCacheConfig and DerivedCacheConfig), but I understand that would make setting these defaults impossible.

Copy link
Member Author

Choose a reason for hiding this comment

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

I would rather like to get rid of the difference between DownloadedCacheConfig and DerivedCacheConfig altogether. The comment I posted above shows that we have bugs related to the retry_after timings. And the only difference between the two is the time-to-idle, which we could express as their own explicit config settings.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah actually that would be even better.

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.

Add in-memory caching
2 participants