Skip to content

Commit

Permalink
spotify#875 - disable connection pooling for named pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-zajic committed Nov 27, 2018
1 parent 1d11fb4 commit 86bd883
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/main/java/com/spotify/docker/client/DefaultDockerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,12 @@
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.HttpClientConnectionManager;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.glassfish.hk2.api.MultiException;
import org.glassfish.jersey.apache.connector.ApacheClientProperties;
Expand Down Expand Up @@ -447,8 +449,8 @@ protected DefaultDockerClient(final Builder builder) {
this.uri = originalUri;
}

final PoolingHttpClientConnectionManager cm = getConnectionManager(builder);
final PoolingHttpClientConnectionManager noTimeoutCm = getConnectionManager(builder);
final HttpClientConnectionManager cm = getConnectionManager(builder);
final HttpClientConnectionManager noTimeoutCm = getConnectionManager(builder);

final RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout((int) builder.connectTimeoutMillis)
Expand Down Expand Up @@ -535,15 +537,19 @@ public String getHost() {
return fromNullable(uri.getHost()).or("localhost");
}

private PoolingHttpClientConnectionManager getConnectionManager(Builder builder) {
final PoolingHttpClientConnectionManager cm =
new PoolingHttpClientConnectionManager(getSchemeRegistry(builder));

// Use all available connections instead of artificially limiting ourselves to 2 per server.
cm.setMaxTotal(builder.connectionPoolSize);
cm.setDefaultMaxPerRoute(cm.getMaxTotal());

return cm;
private HttpClientConnectionManager getConnectionManager(Builder builder) {
if (builder.uri.getScheme().equals(NPIPE_SCHEME)) {
final BasicHttpClientConnectionManager bm =
new BasicHttpClientConnectionManager(getSchemeRegistry(builder));
return bm;
} else {
final PoolingHttpClientConnectionManager cm =
new PoolingHttpClientConnectionManager(getSchemeRegistry(builder));
// Use all available connections instead of artificially limiting ourselves to 2 per server.
cm.setMaxTotal(builder.connectionPoolSize);
cm.setDefaultMaxPerRoute(cm.getMaxTotal());
return cm;
}
}

private Registry<ConnectionSocketFactory> getSchemeRegistry(final Builder builder) {
Expand Down

0 comments on commit 86bd883

Please sign in to comment.