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

Slow the rate of growth in ConsolidatingVec #31077

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

frankmcsherry
Copy link
Contributor

@frankmcsherry frankmcsherry commented Jan 16, 2025

The growth of ConsolidatingVec was by doubling, which meant that we can end up with substantially more memory use than we really need. This PR attempts to make this configurable, growing by a smaller factor determined by a positive integer slop. If the result of consolidation is (1 - 1/slop)-full, we grow the vector by a factor of 1 + 1/(slop-1). These relationships were chosen to match the 2x behavior, but it's possible that they are imperfect.

I'm not certain how to test the impact of this, and whether we have "MV rehydration memory" tests, but that would be the right way to see if this is helpful. It comes at the potential expense of CPU.

Motivation

Tips for reviewer

Checklist

  • This PR has adequate test coverage / QA involvement has been duly considered. (trigger-ci for additional test/nightly runs)
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).
  • If this PR includes major user-facing behavior changes, I have pinged the relevant PM to schedule a changelog post.

@frankmcsherry frankmcsherry requested a review from a team as a code owner January 16, 2025 20:50
@frankmcsherry
Copy link
Contributor Author

From Slack, @teskje recommends a launch darkly flag to allow the number to be configurable, in case two was very important for some reasons (plausible!). I'll need to chase down what threading that through looks like.

Copy link
Contributor

@teskje teskje left a comment

Choose a reason for hiding this comment

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

Looks good! We could tighten down the API to prevent users from setting too-small denominator values.

/// Denominator in the growth rate, where 2 corresponds to doubling, and `n` to `1 + 1/(n-1)`.
///
/// If consolidation didn't free enough space, at least a linear amount, increase the capacity
/// The `slop` term describes the rate of growth, where we scale up by factors of 1/slop.
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
/// The `slop` term describes the rate of growth, where we scale up by factors of 1/slop.
/// The `slop` term describes the rate of growth, where we scale up by factors of 1/(slop-1).

... right?

/// The denominator `n` in the growth rate `1 + 1/(n-1)` for `ConsolidatingVec` growth.
pub const CONSOLIDATING_VEC_GROWTH_DENOMINATOR: Config<usize> = Config::new(
"consolidating_vec_growth_denominator",
2,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd be okay with defaulting this to our target (11?) and then opting out were we observe issues. Seems safe enough, considering that this trades of less memory for more CPU and we usually don't have CPU issues.

Comment on lines +50 to +51
/// Configuration for `ConsolidatingVec` determining the rate of growth (doubling, or less).
growth_denominator: usize,
Copy link
Contributor

Choose a reason for hiding this comment

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

There isn't anything that enforces "doubling or less" here, right? People could set the config to 1 or 0 and end up having a bad time. How about checking that in new and falling back to 2 on invalid values? Alternatively, redefine the semantics to have 0 mean doubling.

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