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

SOLR-17240: Fix Http2SolrClient maxConnectionsPerDestination usage #2410

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ Improvements
* SOLR-14763: Add a CompletableFuture based asynchronous API to Http2SolrClient, HttpJdkSolrClient and LBHttp2SolrClient.
The previous asynchronous API is deprecated. (Rishi Sankar, James Dyer)

* SOLR-17240: Use the same logic for "maxConnectionsPerDestination" between http1 and http2 in the Http2SolrClient.
Http2 is no longer hardcoded to use 4 connections. (Houston Putman, Mark Miller)

Optimizations
---------------------
* SOLR-17144: Close searcherExecutor thread per core after 1 minute (Pierre Salagnac, Christine Poerschke)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ ProtocolHandlers getProtocolHandlers() {
}

private HttpClient createHttpClient(Builder builder) {
HttpClient httpClient;

executor = builder.executor;
if (executor == null) {
BlockingArrayQueue<Runnable> queue = new BlockingArrayQueue<>(256, 256);
Expand Down Expand Up @@ -208,25 +206,32 @@ private HttpClient createHttpClient(Builder builder) {
clientConnector.setSelectors(2);

HttpClientTransport transport;
int maxConnectionsPerHost =
builder.maxConnectionsPerHost != null ? builder.maxConnectionsPerHost : 0;
if (builder.useHttp1_1) {
if (log.isDebugEnabled()) {
log.debug("Create Http2SolrClient with HTTP/1.1 transport");
}

transport = new HttpClientTransportOverHTTP(clientConnector);
httpClient = new HttpClient(transport);
if (builder.maxConnectionsPerHost != null) {
httpClient.setMaxConnectionsPerDestination(builder.maxConnectionsPerHost);
}
} else {
if (log.isDebugEnabled()) {
log.debug("Create Http2SolrClient with HTTP/2 transport");
}

HTTP2Client http2client = new HTTP2Client(clientConnector);
transport = new HttpClientTransportOverHTTP2(http2client);
httpClient = new HttpClient(transport);
httpClient.setMaxConnectionsPerDestination(4);
// For HTTP2, which supports multiplexing requests over a single connection, we should reduce
// the maxConnectionsPerHost to account for the max multiplexing factor.
if (maxConnectionsPerHost > 0) {
maxConnectionsPerHost =
((maxConnectionsPerHost - 1) / http2client.getMaxConcurrentPushedStreams()) + 1;
}
}

HttpClient httpClient = new HttpClient(transport);
if (maxConnectionsPerHost > 0) {
httpClient.setMaxConnectionsPerDestination(maxConnectionsPerHost);
}

httpClient.setExecutor(this.executor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ public B withTheseParamNamesInTheUrl(Set<String> urlParamNames) {
}

/**
* Set maxConnectionsPerHost for http1 connections, maximum number http2 connections is limited to
* 4
* Set maxConnectionsPerHost for http1 and http2 connections. For http1 connections, this value is
* used without any change. For http2 connections, this value is ultimately divided by the max
* multiplexing rate per connection.
*/
@SuppressWarnings("unchecked")
public B withMaxConnectionsPerHost(int max) {
Expand Down
Loading