Skip to content

Commit

Permalink
Reduce netty pool size (#1944)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored Nov 3, 2021
1 parent fd05a81 commit 7e4aa40
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,14 @@
import javax.annotation.Nullable;
import org.checkerframework.checker.lock.qual.GuardedBy;
import reactor.core.publisher.Mono;
import reactor.netty.resources.ConnectionProvider;
import reactor.netty.resources.LoopResources;

public class LazyHttpClient implements HttpClient {

private static final String APPLICATIONINSIGHTS_AUTHENTICATION_SCOPE =
"https://monitor.azure.com//.default";

private static final HttpClient INSTANCE = new LazyHttpClient();
private static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 200;

public static volatile CountDownLatch safeToInitLatch;
public static volatile String proxyHost;
Expand Down Expand Up @@ -108,17 +107,16 @@ private static HttpClient init() {
}
}

ConnectionProvider connectionProvider =
ConnectionProvider.builder("fixed").maxConnections(DEFAULT_MAX_TOTAL_CONNECTIONS).build();
NettyAsyncHttpClientBuilder builder = new NettyAsyncHttpClientBuilder();
if (proxyHost != null && proxyPortNumber != null) {
return new NettyAsyncHttpClientBuilder()
.proxy(
new ProxyOptions(
ProxyOptions.Type.HTTP, new InetSocketAddress(proxyHost, proxyPortNumber)))
.connectionProvider(connectionProvider)
.build();
builder.proxy(
new ProxyOptions(
ProxyOptions.Type.HTTP, new InetSocketAddress(proxyHost, proxyPortNumber)));
}
return new NettyAsyncHttpClientBuilder().connectionProvider(connectionProvider).build();
// keeping the thread count to 1 keeps the number of 16mb io.netty.buffer.PoolChunk to 1 also
return builder
.eventLoopGroup(LoopResources.create("reactor-http", 1, true).onClient(true))
.build();
}

// pass non-null ikeyRedirectCache if you want to use ikey-specific redirect policy
Expand Down

0 comments on commit 7e4aa40

Please sign in to comment.