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 netty pool size #1944

Merged
merged 1 commit into from
Nov 3, 2021
Merged
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

200 to 1? what is the motivation?

Copy link
Member Author

Choose a reason for hiding this comment

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

200 is a different number, I don't think we need a non-default value for that.

1 is the number of threads (down from default which is based on cpu-count).

the motivation is in the comment below (to reduce memory consumption, which was a regression in 3.2.0 when we switched http clients)


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