diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java index cf50fa44c77..af80d37c6d6 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java @@ -2060,7 +2060,15 @@ void maintainPool() { } this.prevNumSessionsAcquired = SessionPool.this.numSessionsAcquired; } + + // Reset the start time for recording the maximum number of sessions + // in the pool. Instant currTime = clock.instant(); + if (currTime.isAfter(SessionPool.this.lastResetTime.plus(Duration.ofMinutes(10)))) { + SessionPool.this.maxSessionsInUse = SessionPool.this.numSessionsInUse; + SessionPool.this.lastResetTime = currTime; + } + removeIdleSessions(currTime); // Now go over all the remaining sessions and see if they need to be kept alive explicitly. keepAliveSessions(currTime); @@ -2309,6 +2317,9 @@ enum Position { @GuardedBy("lock") private int maxSessionsInUse = 0; + @GuardedBy("lock") + private Instant lastResetTime = Clock.INSTANCE.instant(); + @GuardedBy("lock") private long numSessionsAcquired = 0;