Skip to content

Commit

Permalink
Reduce the client TLS session cache size (#1067)
Browse files Browse the repository at this point in the history
Reduce the client TLS session cache size
  • Loading branch information
carterkozak authored Nov 30, 2020
1 parent f040293 commit b7692ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1067.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Reduce the client TLS session cache size
links:
- https://github.com/palantir/dialogue/pull/1067
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.palantir.tritium.metrics.registry.TaggedMetricRegistry;
import java.security.Provider;
import java.util.Optional;
import javax.net.ssl.SSLContext;
import org.immutables.value.Value;

/**
Expand Down Expand Up @@ -64,13 +65,19 @@ static ClientConfiguration getClientConf(ServiceConfiguration serviceConfig, Aug
ClientConfiguration.Builder builder =
ClientConfiguration.builder().from(ClientConfigurations.of(serviceConfig));

SSLContext context = augment.securityProvider()
.map(provider -> SslSocketFactories.createSslContext(serviceConfig.security(), provider))
.orElseGet(() -> SslSocketFactories.createSslContext(serviceConfig.security()));
// Reduce the session cache size for clients. We expect TLS connections to be reused, thus the cache isn't
// terribly important.
context.getClientSessionContext().setSessionCacheSize(100);
builder.sslSocketFactory(context.getSocketFactory());

if (!serviceConfig.maxNumRetries().isPresent()) {
augment.maxNumRetries().ifPresent(builder::maxNumRetries);
}

if (augment.securityProvider().isPresent()) {
builder.sslSocketFactory(SslSocketFactories.createSslSocketFactory(
serviceConfig.security(), augment.securityProvider().get()));
// Opt into GCM when custom providers (Conscrypt) is used.
builder.enableGcmCipherSuites(true);
}
Expand Down

0 comments on commit b7692ab

Please sign in to comment.