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

[chttp2] Fix bug in timeout encoding #34751

Merged
merged 8 commits into from
Oct 27, 2023
Merged

[chttp2] Fix bug in timeout encoding #34751

merged 8 commits into from
Oct 27, 2023

Conversation

ctiller
Copy link
Member

@ctiller ctiller commented Oct 19, 2023

Just the right combination of timeout values could lead to a large amount of growth in the timeout cache, leading to high memory usage and high cpu utilization on the client attempting that encoding.

Fix: cap the number of cached timeout values we'll consider to a very small number (I'm choosing five).

Add a fuzzer that ensures that we're actually respecting the limits of inaccuracy we're imposing upon ourselves.

@ctiller ctiller added the release notes: no Indicates if PR should not be in release notes label Oct 19, 2023
};

class TimeoutCompressorImpl {
public:
void EncodeWith(absl::string_view key, Timestamp deadline, Encoder* encoder);

private:
std::vector<PreviousTimeout> previous_timeouts_;
enum { kNumPreviousValues = 5 };
Copy link
Contributor

Choose a reason for hiding this comment

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

why enum?

Copy link
Member Author

Choose a reason for hiding this comment

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

in C++98 this was the way to say static constexpr const kNumPreviousValues = 5;... and:

  1. old habits are hard to break :)
  2. having typed that I'm not clear we've made progress

still, updated to the more modern syntax

Choose a reason for hiding this comment

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

sorry, i am afraid that this problem is important or not ?i am reall sorry to bother

double ratio = timeout.RatioVersus(it->timeout);
for (size_t i = 0; i < kNumPreviousValues; i++) {
const auto& previous = previous_timeouts_[i];
if (!table.ConvertableToDynamicIndex(previous.index)) continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

will this if condition return if previous_timeouts_[i] has not been populated yet, like if the index is 0? What does ConvertableToDynamicIndex check for?

Copy link
Member Author

Choose a reason for hiding this comment

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

added some comments around the safety of this

// be considered earlier.
std::swap(*it, *previous_timeouts_.begin());
if (ratio > -3 && ratio <= 0) {
encoder->EmitIndexed(table.DynamicIndex(previous.index));
Copy link
Contributor

Choose a reason for hiding this comment

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

Will there be any negative effects to emitting these timeouts directly rather than adding to the queue first? What if there are a lot of timeouts like this?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we hit this sufficiently frequently this could cause some significant hpack table churn... evidence so far says that we'll not hit it frequently, but it'll be something to watch.

@ctiller ctiller merged commit afe5f6d into grpc:master Oct 27, 2023
9 checks passed
@ctiller ctiller deleted the smol branch October 27, 2023 16:38
ctiller added a commit that referenced this pull request Oct 27, 2023
ctiller added a commit that referenced this pull request Oct 27, 2023
@copybara-service copybara-service bot added the imported Specifies if the PR has been imported to the internal repository label Oct 27, 2023
@ctiller ctiller restored the smol branch April 8, 2024 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bloat/none imported Specifies if the PR has been imported to the internal repository lang/core per-call-memory/neutral per-channel-memory/neutral release notes: no Indicates if PR should not be in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants