Skip to content

Commit

Permalink
Generate log messages in advance
Browse files Browse the repository at this point in the history
  • Loading branch information
raccoonback committed Jan 1, 2025
1 parent a5a5b98 commit ab6ac80
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -364,17 +365,31 @@ protected static void logPoolState(Channel channel, InstrumentedPool<? extends C
}

protected static void logPoolState(Channel channel, InstrumentedPool<? extends Connection> pool, String msg, @Nullable Throwable t) {
InstrumentedPool.PoolMetrics metrics = pool.metrics();
String logMsg = msg + ", " + stringifyPoolMetrics(pool);
if (t == null) {
log.debug(format(channel, logMsg));
return;
}

log.debug(
format(channel, "{}, now: {} active connections, {} inactive connections and {} pending acquire requests."),
msg,
metrics.acquiredSize(),
metrics.idleSize(),
metrics.pendingAcquireSize(),
format(channel, logMsg),
t
);
}

private static String stringifyPoolMetrics(InstrumentedPool<? extends Connection> pool) {
InstrumentedPool.PoolMetrics metrics = pool.metrics();
return new StringJoiner(" ")
.add("now:")
.add(String.valueOf(metrics.acquiredSize()))
.add("active connections,")
.add(String.valueOf(metrics.idleSize()))
.add("inactive connections")
.add(String.valueOf(metrics.pendingAcquireSize()))
.add("pending acquire requests.")
.toString();
}

final void scheduleInactivePoolsDisposal() {
if (!inactivePoolDisposeInterval.isZero()) {
Schedulers.parallel()
Expand Down

0 comments on commit ab6ac80

Please sign in to comment.