diff options
author | Bjørn Christian Seime <bjorn.christian@seime.no> | 2023-10-30 12:40:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-30 12:40:48 +0100 |
commit | 3fcfc3ee06681ddc9c49f542d379f97d2fb43ebb (patch) | |
tree | 9b9b6404fdcbb8955de1134516d964851aad2884 | |
parent | 70cf1f41940b73b7db3cc219e6119030e094cf3f (diff) | |
parent | c79578f4331f2b8433b3ede5841bdf910164d564 (diff) |
Merge pull request #29139 from vespa-engine/jonmv/feed-client-conn-ttl
Allow specifying connection TTL for feed client
4 files changed, 17 insertions, 1 deletions
diff --git a/vespa-feed-client-api/abi-spec.json b/vespa-feed-client-api/abi-spec.json index e8c2b4a3c9e..907d974ff09 100644 --- a/vespa-feed-client-api/abi-spec.json +++ b/vespa-feed-client-api/abi-spec.json @@ -144,6 +144,7 @@ "public static void setFeedClientBuilderSupplier(java.util.function.Supplier)", "public abstract ai.vespa.feed.client.FeedClientBuilder setConnectionsPerEndpoint(int)", "public abstract ai.vespa.feed.client.FeedClientBuilder setMaxStreamPerConnection(int)", + "public abstract ai.vespa.feed.client.FeedClientBuilder setConnectionTimeToLive(java.time.Duration)", "public abstract ai.vespa.feed.client.FeedClientBuilder setSslContext(javax.net.ssl.SSLContext)", "public abstract ai.vespa.feed.client.FeedClientBuilder setHostnameVerifier(javax.net.ssl.HostnameVerifier)", "public abstract ai.vespa.feed.client.FeedClientBuilder setProxyHostnameVerifier(javax.net.ssl.HostnameVerifier)", diff --git a/vespa-feed-client-api/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java b/vespa-feed-client-api/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java index 270ecad6af8..7101b8452ed 100644 --- a/vespa-feed-client-api/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java +++ b/vespa-feed-client-api/src/main/java/ai/vespa/feed/client/FeedClientBuilder.java @@ -7,6 +7,7 @@ import java.net.URI; import java.nio.file.Path; import java.security.PrivateKey; import java.security.cert.X509Certificate; +import java.time.Duration; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -63,6 +64,9 @@ public interface FeedClientBuilder { */ FeedClientBuilder setMaxStreamPerConnection(int max); + /** Sets a duration after which this client will recycle active connections. This is off ({@code Duration.ZERO}) by default. */ + FeedClientBuilder setConnectionTimeToLive(Duration ttl); + /** Sets {@link SSLContext} instance. */ FeedClientBuilder setSslContext(SSLContext context); diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java index cacaeac30ae..6b4372fd11a 100644 --- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/FeedClientBuilderImpl.java @@ -60,6 +60,7 @@ public class FeedClientBuilderImpl implements FeedClientBuilder { boolean speedTest = false; Compression compression = auto; URI proxy; + Duration connectionTtl = Duration.ZERO; public FeedClientBuilderImpl() { @@ -95,6 +96,13 @@ public class FeedClientBuilderImpl implements FeedClientBuilder { return this; } + @Override + public FeedClientBuilder setConnectionTimeToLive(Duration ttl) { + if (ttl.isNegative()) throw new IllegalArgumentException("Connection TTL cannot be negative, but was " + ttl); + this.connectionTtl = ttl; + return this; + } + /** Sets {@link SSLContext} instance. */ @Override public FeedClientBuilderImpl setSslContext(SSLContext context) { diff --git a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/JettyCluster.java b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/JettyCluster.java index 1edcc6d6cba..5454249d52e 100644 --- a/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/JettyCluster.java +++ b/vespa-feed-client/src/main/java/ai/vespa/feed/client/impl/JettyCluster.java @@ -159,7 +159,10 @@ class JettyCluster implements Cluster { dest, Pool.StrategyType.RANDOM, connectionsPerEndpoint, false, dest, Integer.MAX_VALUE); pool.preCreateConnections(connectionsPerEndpoint); if (secureProxy) pool.setMaxDuration(Duration.ofMinutes(1).toMillis()); - else pool.setMaximizeConnections(true); + else { + pool.setMaximizeConnections(true); + pool.setMaxDuration(b.connectionTtl.toMillis()); + } return pool; }); HttpClient httpClient = new HttpClient(transport); |