-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Overload: Limit the number of streams reset per invocation of WatermarkBufferFactory::resetAccountsGivenPressure. #17949
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ namespace { | |
| // Effectively disables tracking as this should zero out all reasonable account | ||
| // balances when shifted by this amount. | ||
| constexpr uint32_t kEffectivelyDisableTrackingBitshift = 63; | ||
| constexpr uint32_t kMaxNumberOfStreamsToResetPerInvocation = 50; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd comment here as well that 50 is arbitrary, to limit work done (as you doc up above)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
| } // end namespace | ||
|
|
||
| void WatermarkBuffer::add(const void* data, uint64_t size) { | ||
|
|
@@ -194,28 +195,30 @@ uint64_t WatermarkBufferFactory::resetAccountsGivenPressure(float pressure) { | |
| // Compute buckets to clear | ||
| const uint32_t buckets_to_clear = std::min<uint32_t>( | ||
| std::floor(pressure * BufferMemoryAccountImpl::NUM_MEMORY_CLASSES_) + 1, 8); | ||
| uint32_t bucket_idx = BufferMemoryAccountImpl::NUM_MEMORY_CLASSES_ - buckets_to_clear; | ||
|
|
||
| ENVOY_LOG_MISC(warn, "resetting streams in buckets >= {}", bucket_idx); | ||
| uint64_t num_streams_reset = 0; | ||
| // TODO(kbaichoo): Add a limit to the number of streams we reset | ||
| // per-invocation of this function. | ||
| // Clear buckets | ||
| while (bucket_idx < BufferMemoryAccountImpl::NUM_MEMORY_CLASSES_) { | ||
|
|
||
| uint32_t last_bucket_to_clear = BufferMemoryAccountImpl::NUM_MEMORY_CLASSES_ - buckets_to_clear; | ||
| ENVOY_LOG_MISC(warn, "resetting streams in buckets >= {}", last_bucket_to_clear); | ||
|
|
||
| // Clear buckets, prioritizing the buckets with larger streams. | ||
| uint32_t num_streams_reset = 0; | ||
| for (uint32_t buckets_cleared = 0; buckets_cleared < buckets_to_clear; ++buckets_cleared) { | ||
| const uint32_t bucket_to_clear = | ||
| BufferMemoryAccountImpl::NUM_MEMORY_CLASSES_ - buckets_cleared - 1; | ||
| ENVOY_LOG_MISC(warn, "resetting {} streams in bucket {}.", | ||
| size_class_account_sets_[bucket_idx].size(), bucket_idx); | ||
| size_class_account_sets_[bucket_to_clear].size(), bucket_to_clear); | ||
|
|
||
| auto it = size_class_account_sets_[bucket_idx].begin(); | ||
| while (it != size_class_account_sets_[bucket_idx].end()) { | ||
| auto it = size_class_account_sets_[bucket_to_clear].begin(); | ||
| while (it != size_class_account_sets_[bucket_to_clear].end()) { | ||
| if (num_streams_reset >= kMaxNumberOfStreamsToResetPerInvocation) { | ||
| return num_streams_reset; | ||
| } | ||
| auto next = std::next(it); | ||
| // This will trigger an erase, which avoids rehashing and invalidates the | ||
| // iterator *it*. *next* is still valid. | ||
| (*it)->resetDownstream(); | ||
| it = next; | ||
| ++num_streams_reset; | ||
| } | ||
|
|
||
| ++bucket_idx; | ||
| } | ||
|
|
||
| return num_streams_reset; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Overload/overload?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.