6969 * <p>Package-private for internal use.
7070 */
7171class ChannelPool extends ManagedChannel {
72+ private static final String CHANNEL_POOL_CONSECUTIVE_RESIZING_WARNING =
73+ "Channel pool is repeatedly resizing. "
74+ + "Consider adjusting `initialChannelCount` or `maxResizeDelta` to a more reasonable value. "
75+ + "See https://docs.cloud.google.com/java/docs/troubleshooting to enable logging "
76+ + "and set `com.google.api.gax.grpc.ChannelPool.level=FINEST` to log the channel pool resize behavior." ;
7277 @ VisibleForTesting static final Logger LOG = Logger .getLogger (ChannelPool .class .getName ());
7378 private static final java .time .Duration REFRESH_PERIOD = java .time .Duration .ofMinutes (50 );
7479
@@ -85,16 +90,13 @@ class ChannelPool extends ManagedChannel {
8590 private final String authority ;
8691
8792 // The number of consecutive resize cycles to wait before logging a warning about repeated
88- // resizing.
89- // This is an arbitrary value chosen to detect repeated requests for changes (multiple continuous
90- // increase or decrease attempts) without being too sensitive.
93+ // resizing. This is an arbitrary value chosen to detect repeated requests for changes
94+ // (multiple continuous increase or decrease attempts) without being too sensitive.
9195 private static final int CONSECUTIVE_RESIZE_THRESHOLD = 5 ;
9296
9397 // Tracks the number of consecutive resize cycles where a resize actually occurred (either expand
94- // or shrink).
95- // Used to detect repeated resizing activity and log a warning.
96- // Note: This field is only accessed within the synchronized resize() method, so it does not need
97- // to be atomic.
98+ // or shrink). Used to detect repeated resizing activity and log a warning.
99+ // Note: This field is only accessed safely within resizeSafely() and does not need to be atomic.
98100 private int consecutiveResizes = 0 ;
99101
100102 static ChannelPool create (
@@ -343,14 +345,7 @@ void resize() {
343345 // Log warning only once when the threshold is reached to avoid spamming logs.
344346 // Using == instead of >= ensures we don't log on every subsequent resize cycle.
345347 if (consecutiveResizes == CONSECUTIVE_RESIZE_THRESHOLD ) {
346- StringBuilder sb = new StringBuilder ();
347- sb .append ("Channel pool is repeatedly resizing. " );
348- sb .append (
349- "Consider adjusting `initialChannelCount` or `maxResizeDelta` to a more reasonable value. " );
350- sb .append ("See https://docs.cloud.google.com/java/docs/troubleshooting to enable logging " );
351- sb .append (
352- "and set `com.google.api.gax.grpc.ChannelPool.level=FINEST` to log the channel pool resize behavior." );
353- LOG .warning (sb .toString ());
348+ LOG .warning (CHANNEL_POOL_CONSECUTIVE_RESIZING_WARNING );
354349 }
355350
356351 // Only resize the pool when thresholds are crossed
0 commit comments