Skip to content

Commit cce4419

Browse files
committed
fix: update max_in_use_session at 10 mins interval
1 parent 8d295c4 commit cce4419

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionPool.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,13 @@ void maintainPool() {
20612061
this.prevNumSessionsAcquired = SessionPool.this.numSessionsAcquired;
20622062
}
20632063
Instant currTime = clock.instant();
2064+
2065+
// Reset the start time for recording the maximum number of sessions in the pool
2066+
if (currTime.isAfter(SessionPool.this.lastResetTime.plus(Duration.ofMinutes(10)))) {
2067+
SessionPool.this.maxSessionsInUse = SessionPool.this.numSessionsInUse;
2068+
SessionPool.this.lastResetTime = currTime;
2069+
}
2070+
20642071
removeIdleSessions(currTime);
20652072
// Now go over all the remaining sessions and see if they need to be kept alive explicitly.
20662073
keepAliveSessions(currTime);
@@ -2309,6 +2316,9 @@ enum Position {
23092316
@GuardedBy("lock")
23102317
private int maxSessionsInUse = 0;
23112318

2319+
@GuardedBy("lock")
2320+
private Instant lastResetTime = Clock.INSTANCE.instant();
2321+
23122322
@GuardedBy("lock")
23132323
private long numSessionsAcquired = 0;
23142324

0 commit comments

Comments
 (0)