diff --git a/CHANGES b/CHANGES index d69f4e69..af6be6e4 100644 --- a/CHANGES +++ b/CHANGES @@ -1,8 +1,12 @@ HikariCP Changes +Changes in 6.0.1 + + * change default maxLifetime variance from 2.5% to 25% to further avoid mass connection die-off dips + Changes in 6.0.0 - * fixed #2152 duplicate connection in try with resources clause caused close() being called twice on each connection. + * fixed #2152 duplicate connection in try with resources clause caused close() being called twice on each connection * merged #2226 consistent handling of errorCode and sqlState in timeout exception diff --git a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java index ae97e403..1f7cec84 100644 --- a/src/main/java/com/zaxxer/hikari/pool/HikariPool.java +++ b/src/main/java/com/zaxxer/hikari/pool/HikariPool.java @@ -64,6 +64,7 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag private final long aliveBypassWindowMs = Long.getLong("com.zaxxer.hikari.aliveBypassWindowMs", MILLISECONDS.toMillis(500)); private final long housekeepingPeriodMs = Long.getLong("com.zaxxer.hikari.housekeeping.periodMs", SECONDS.toMillis(30)); + private final long lifeTimeVarianceFactor = Math.min(40, Math.max(2, Long.getLong("com.zaxxer.hikari.lifeTimeVarianceFactor", 4))); // variance% = 100 / factor private final boolean isRequestBoundariesEnabled = Boolean.getBoolean("com.zaxxer.hikari.enableRequestBoundaries"); private static final String EVICTED_CONNECTION_MESSAGE = "(connection was evicted)"; @@ -470,7 +471,7 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag // *********************************************************************** /** - * Creating new poolEntry. If maxLifetime is configured, create a future End-of-life task with 2.5% variance from + * Creating new poolEntry. If maxLifetime is configured, create a future End-of-life task with variance from * the maxLifetime time to ensure there is no massive die-off of Connections in the pool. */ private PoolEntry createPoolEntry() @@ -480,8 +481,8 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag final var maxLifetime = config.getMaxLifetime(); if (maxLifetime > 0) { - // variance up to 2.5% of the maxlifetime - final var variance = maxLifetime > 10_000 ? ThreadLocalRandom.current().nextLong( maxLifetime / 40 ) : 0; + // default variance upto 25% of the maxLifetime (random) + final var variance = maxLifetime > 10_000L ? ThreadLocalRandom.current().nextLong( maxLifetime / lifeTimeVarianceFactor ) : 0L; final var lifetime = maxLifetime - variance; poolEntry.setFutureEol(houseKeepingExecutorService.schedule(new MaxLifetimeTask(poolEntry), lifetime, MILLISECONDS)); } @@ -605,11 +606,11 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag /** * "Soft" evict a Connection (/PoolEntry) from the pool. If this method is being called by the user directly * through {@link com.zaxxer.hikari.HikariDataSource#evictConnection(Connection)} then {@code owner} is {@code true}. - * + *
* If the caller is the owner, or if the Connection is idle (i.e. can be "reserved" in the {@link ConcurrentBag}), * then we can close the connection immediately. Otherwise, we leave it "marked" for eviction so that it is evicted * the next time someone tries to acquire it from the pool. - * + *
* @param poolEntry the PoolEntry (/Connection) to "soft" evict from the pool * @param reason the reason that the connection is being evicted * @param owner true if the caller is the owner of the connection, false otherwise @@ -683,7 +684,7 @@ public final class HikariPool extends PoolBase implements HikariPoolMXBean, IBag * timeout, e.g. a SQLException thrown by the driver while trying to create a new Connection, then use the * SQL State from that exception as our own and additionally set that exception as the "next" SQLException inside * our exception. - * + *
* As a side effect, log the timeout failure at DEBUG, and record the timeout failure in the metrics tracker. * * @param startTime the start time (timestamp) of the acquisition attempt