Skip to content

Commit

Permalink
shrink string cache reset threshold a bit
Browse files Browse the repository at this point in the history
A slow ramp up to 4 MiB could _look_ like a memory leak. However, a
slow ramp to 2 MiB is probably going to look like it's within normal
operating ranges.
  • Loading branch information
morrisonlevi committed Jun 12, 2024
1 parent c7a7d7c commit c72a081
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions profiling/src/profiling/stack_walking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ mod detail {
CACHED_STRINGS.with(|cell| {
let set: &StringSet = &cell.borrow();
let arena_used_bytes = set.arena_used_bytes();
// todo: pin down threshold
let threshold = 4 * 1024 * 1024;
// A slow ramp up to 2 MiB is probably _not_ going to look like
// a memory leak, whereas a higher threshold could make a user
// suspect a leak.
let threshold = 2 * 1024 * 1024;
if arena_used_bytes > threshold {
debug!("string cache arena is using {arena_used_bytes} bytes which exceeds the {threshold} byte threshold, resetting");
// Note that this cannot be done _during_ a request. The
Expand Down
2 changes: 1 addition & 1 deletion profiling/src/string_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl StringSet {
// Keep this in the megabyte range. It's virtual, so we do not need
// to worry much about unused amounts, but asking for wildly too much
// up front, like in gigabyte+ range, is not good either.
const SIZE_HINT: usize = 4 * 1024 * 1024;
const SIZE_HINT: usize = 2 * 1024 * 1024;
let arena = ChainAllocator::new_in(SIZE_HINT, VirtualAllocator {});

let mut strings = HashSet::with_hasher(Hasher::default());
Expand Down

0 comments on commit c72a081

Please sign in to comment.