Skip to content
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 @@ -26,6 +26,7 @@
import io.trino.spi.security.ConnectorIdentity;
import jakarta.annotation.PreDestroy;
import okhttp3.ConnectionPool;
import okhttp3.Dispatcher;
import okhttp3.OkHttpClient;

import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -96,6 +97,9 @@ public static HttpClient createAzureHttpClient(OkHttpClient okHttpClient, HttpCl
Integer poolSize = clientOptions.getMaximumConnectionPoolSize();
// By default, OkHttp uses a maximum idle connection count of 5.
int maximumConnectionPoolSize = (poolSize != null && poolSize > 0) ? poolSize : 5;
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequests(Runtime.getRuntime().availableProcessors() * 4);
dispatcher.setMaxRequestsPerHost(Runtime.getRuntime().availableProcessors() * 2);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the same as the default for the number of worker threads: https://github.com/trinodb/trino/blob/master/core/trino-main/src/main/java/io/trino/execution/TaskManagerConfig.java#L62

I didn't want to get it from that config to avoid adding a dependency on trino-main. I set the max requests as twice as much, but I don't have any specific reason for it. I'm open for suggestions how to choose a better value.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this worth exposing it as a configuration property?

Also nit: extract Runtime.getRuntime().availableProcessors() to a variable, and also inline dispatcher below

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can't inline it, as the setters don't return anything.

If we'll make it configurable, it should only be a fallback in case we get the default wrong. Maybe we should ask differently - in which cases the number of worker threads should be customized?


return new OkHttpAsyncHttpClientBuilder(okHttpClient)
.proxy(clientOptions.getProxyOptions())
Expand All @@ -104,6 +108,8 @@ public static HttpClient createAzureHttpClient(OkHttpClient okHttpClient, HttpCl
.writeTimeout(clientOptions.getWriteTimeout())
.readTimeout(clientOptions.getReadTimeout())
.connectionPool(new ConnectionPool(maximumConnectionPoolSize,
clientOptions.getConnectionIdleTimeout().toMillis(), TimeUnit.MILLISECONDS)).build();
clientOptions.getConnectionIdleTimeout().toMillis(), TimeUnit.MILLISECONDS))
.dispatcher(dispatcher)
.build();
}
}