-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(gax-grpc): add configurable resize delta and warning for repeated resizing #12838
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
Changes from 11 commits
03e341c
2060fcf
e876b31
b3ffb64
8a5daa1
813e101
91ffb52
de28aef
827b22d
899736f
f9792b6
856f3f2
a6a34dc
2be58da
e61486f
cbef704
2895af5
068887e
947fad5
f62aa0c
697c336
387c68e
defe1bb
e84b9d2
35234d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,19 @@ class ChannelPool extends ManagedChannel { | |
| private final AtomicInteger indexTicker = new AtomicInteger(); | ||
| private final String authority; | ||
|
|
||
| // The number of consecutive resize cycles to wait before logging a warning about repeated | ||
| // resizing. | ||
| // This is an arbitrary value chosen to detect repeated requests for changes (multiple continuous | ||
| // increase or decrease attempts) without being too sensitive. | ||
| private static final int CONSECUTIVE_RESIZE_THRESHOLD = 5; | ||
|
|
||
| // Tracks the number of consecutive resize cycles where a resize actually occurred (either expand | ||
| // or shrink). | ||
| // Used to detect repeated resizing activity and log a warning. | ||
| // Note: This field is only accessed within the synchronized resize() method, so it does not need | ||
| // to be atomic. | ||
|
lqiu96 marked this conversation as resolved.
Outdated
|
||
| private int consecutiveResizes = 0; | ||
|
lqiu96 marked this conversation as resolved.
|
||
|
|
||
| static ChannelPool create( | ||
| ChannelPoolSettings settings, | ||
| ChannelFactory channelFactory, | ||
|
|
@@ -313,9 +326,31 @@ void resize() { | |
| int currentSize = localEntries.size(); | ||
| int delta = tentativeTarget - currentSize; | ||
| int dampenedTarget = tentativeTarget; | ||
| if (Math.abs(delta) > ChannelPoolSettings.MAX_RESIZE_DELTA) { | ||
| dampenedTarget = | ||
| currentSize + (int) Math.copySign(ChannelPoolSettings.MAX_RESIZE_DELTA, delta); | ||
| if (Math.abs(delta) > settings.getMaxResizeDelta()) { | ||
|
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. Do we know why there was a limit in the first place? Were there any technical limitations?
Member
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. IIUC, it looks to just be a choice. Dampening and rate limit the channel growth to not overwhelm the client for a sudden burst. |
||
| dampenedTarget = currentSize + (int) Math.copySign(settings.getMaxResizeDelta(), delta); | ||
| } | ||
|
|
||
| // We only count as "resized" if the thresholds are crossed and we actually attempt to scale. | ||
| // Checking (dampenedTarget != currentSize) would cause false positives when the pool is within | ||
| // bounds but not at the target, because the target aims for the middle of the bounds. | ||
| boolean resized = (currentSize < minChannels || currentSize > maxChannels); | ||
| if (resized) { | ||
| consecutiveResizes++; | ||
| } else { | ||
| consecutiveResizes = 0; | ||
| } | ||
|
|
||
| // Log warning only once when the threshold is reached to avoid spamming logs. | ||
| // Using == instead of >= ensures we don't log on every subsequent resize cycle. | ||
| if (consecutiveResizes == CONSECUTIVE_RESIZE_THRESHOLD) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| sb.append("Channel pool is repeatedly resizing. "); | ||
| sb.append( | ||
| "Consider adjusting `initialChannelCount` or `maxResizeDelta` to a more reasonable value. "); | ||
| sb.append("See https://docs.cloud.google.com/java/docs/troubleshooting to enable logging "); | ||
| sb.append( | ||
| "and set `com.google.api.gax.grpc.ChannelPool.level=FINEST` to log the channel pool resize behavior."); | ||
| LOG.warning(sb.toString()); | ||
| } | ||
|
|
||
| // Only resize the pool when thresholds are crossed | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.