Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the client TLS session cache size #1067

Merged
merged 2 commits into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

down from a default of 20480 by the looks of things

    /**
     * Returns the size of the cache used for storing <code>SSLSession</code>
     * objects grouped under this <code>SSLSessionContext</code>.
     *
     * @implNote The JDK implementation returns the cache size as set by
     *           the {@code setSessionCacheSize} method, or if not set, the
     *           value of the {@systemProperty javax.net.ssl.sessionCacheSize}
     *           system property.  If neither is set, it returns a default
     *           value of 20480.
     *
     * @return size of the session cache; zero means there is no size limit.
     *
     * @see #setSessionCacheSize
     */
    public int getSessionCacheSize();

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