You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/05/04 01:10:47 UTC
[james-project] 03/03: JAMES-3737 Allow configuring ElasticSearch connections
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 5b9155995f1fbe627f7a69477722f43e62815a7b
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Apr 18 17:08:12 2022 +0700
JAMES-3737 Allow configuring ElasticSearch connections
To quote the driver itself: default settings for connection
pooling may be too constraining. These limits might be hit
with a few concurrent ElasticSearch request. Exposing these setting is thus interesting.
---
.../james/backends/es/v7/ClientProvider.java | 3 ++
.../backends/es/v7/ElasticSearchConfiguration.java | 40 +++++++++++++++++++---
.../ROOT/pages/configure/elasticsearch.adoc | 9 +++++
src/site/xdoc/server/config-elasticsearch.xml | 6 ++++
4 files changed, 54 insertions(+), 4 deletions(-)
diff --git a/backends-common/elasticsearch-v7/src/main/java/org/apache/james/backends/es/v7/ClientProvider.java b/backends-common/elasticsearch-v7/src/main/java/org/apache/james/backends/es/v7/ClientProvider.java
index 9d4fc151cc..a8b16ffc22 100644
--- a/backends-common/elasticsearch-v7/src/main/java/org/apache/james/backends/es/v7/ClientProvider.java
+++ b/backends-common/elasticsearch-v7/src/main/java/org/apache/james/backends/es/v7/ClientProvider.java
@@ -76,6 +76,9 @@ public class ClientProvider implements Provider<ReactorElasticSearchClient> {
configureHostScheme(builder);
configureTimeout(builder);
+ configuration.getMaxConnections().ifPresent(builder::setMaxConnTotal);
+ configuration.getMaxConnectionsPerHost().ifPresent(builder::setMaxConnPerRoute);
+
builder.setThreadFactory(NamedThreadFactory.withName("ElasticSearch-driver"));
return builder;
diff --git a/backends-common/elasticsearch-v7/src/main/java/org/apache/james/backends/es/v7/ElasticSearchConfiguration.java b/backends-common/elasticsearch-v7/src/main/java/org/apache/james/backends/es/v7/ElasticSearchConfiguration.java
index a29140a2f6..b7dedbac23 100644
--- a/backends-common/elasticsearch-v7/src/main/java/org/apache/james/backends/es/v7/ElasticSearchConfiguration.java
+++ b/backends-common/elasticsearch-v7/src/main/java/org/apache/james/backends/es/v7/ElasticSearchConfiguration.java
@@ -307,6 +307,8 @@ public class ElasticSearchConfiguration {
private Optional<HostScheme> hostScheme;
private Optional<Credential> credential;
private Optional<SSLConfiguration> sslTrustConfiguration;
+ private Optional<Integer> maxConnectionsPerHost;
+ private Optional<Integer> maxConnections;
public Builder() {
hosts = ImmutableList.builder();
@@ -319,6 +321,8 @@ public class ElasticSearchConfiguration {
hostScheme = Optional.empty();
credential = Optional.empty();
sslTrustConfiguration = Optional.empty();
+ maxConnectionsPerHost = Optional.empty();
+ maxConnections = Optional.empty();
}
public Builder addHost(Host host) {
@@ -359,6 +363,16 @@ public class ElasticSearchConfiguration {
return this;
}
+ public Builder maxConnectionsPerHost(Optional<Integer> maxConnectionsPerHost) {
+ this.maxConnectionsPerHost = maxConnectionsPerHost;
+ return this;
+ }
+
+ public Builder maxConnections(Optional<Integer> maxConnections) {
+ this.maxConnections = maxConnections;
+ return this;
+ }
+
public Builder requestTimeout(Optional<Duration> requestTimeout) {
this.requestTimeout = requestTimeout;
return this;
@@ -397,7 +411,7 @@ public class ElasticSearchConfiguration {
requestTimeout.orElse(DEFAULT_REQUEST_TIMEOUT),
hostScheme.orElse(DEFAULT_SCHEME),
credential,
- sslTrustConfiguration.orElse(DEFAULT_SSL_TRUST_CONFIGURATION));
+ sslTrustConfiguration.orElse(DEFAULT_SSL_TRUST_CONFIGURATION), maxConnections, maxConnectionsPerHost);
}
}
@@ -420,6 +434,8 @@ public class ElasticSearchConfiguration {
public static final String ELASTICSEARCH_NB_SHARDS = "elasticsearch.nb.shards";
public static final String ELASTICSEARCH_RETRY_CONNECTION_MIN_DELAY = "elasticsearch.retryConnection.minDelay";
public static final String ELASTICSEARCH_RETRY_CONNECTION_MAX_RETRIES = "elasticsearch.retryConnection.maxRetries";
+ public static final String ELASTICSEARCH_MAX_CONNECTIONS = "elasticsearch.max.connections";
+ public static final String ELASTICSEARCH_MAX_CONNECTIONS_PER_HOSTS = "elasticsearch.max.connections.per.hosts";
public static final int DEFAULT_CONNECTION_MAX_RETRIES = 7;
public static final int DEFAULT_CONNECTION_MIN_DELAY = 3000;
@@ -448,6 +464,8 @@ public class ElasticSearchConfiguration {
.waitForActiveShards(configuration.getInteger(WAIT_FOR_ACTIVE_SHARDS, DEFAULT_WAIT_FOR_ACTIVE_SHARDS))
.minDelay(Optional.ofNullable(configuration.getInteger(ELASTICSEARCH_RETRY_CONNECTION_MIN_DELAY, null)))
.maxRetries(Optional.ofNullable(configuration.getInteger(ELASTICSEARCH_RETRY_CONNECTION_MAX_RETRIES, null)))
+ .maxConnections(Optional.ofNullable(configuration.getInteger(ELASTICSEARCH_MAX_CONNECTIONS, null)))
+ .maxConnectionsPerHost(Optional.ofNullable(configuration.getInteger(ELASTICSEARCH_MAX_CONNECTIONS_PER_HOSTS, null)))
.build();
}
@@ -540,9 +558,11 @@ public class ElasticSearchConfiguration {
private final HostScheme hostScheme;
private final Optional<Credential> credential;
private final SSLConfiguration sslConfiguration;
+ private final Optional<Integer> maxConnections;
+ private final Optional<Integer> maxConnectionsPerHost;
private ElasticSearchConfiguration(ImmutableList<Host> hosts, int nbShards, int nbReplica, int waitForActiveShards, int minDelay, int maxRetries, Duration requestTimeout,
- HostScheme hostScheme, Optional<Credential> credential, SSLConfiguration sslConfiguration) {
+ HostScheme hostScheme, Optional<Credential> credential, SSLConfiguration sslConfiguration, Optional<Integer> maxConnections, Optional<Integer> maxConnectionsPerHost) {
this.hosts = hosts;
this.nbShards = nbShards;
this.nbReplica = nbReplica;
@@ -553,6 +573,8 @@ public class ElasticSearchConfiguration {
this.hostScheme = hostScheme;
this.credential = credential;
this.sslConfiguration = sslConfiguration;
+ this.maxConnections = maxConnections;
+ this.maxConnectionsPerHost = maxConnectionsPerHost;
}
public ImmutableList<Host> getHosts() {
@@ -595,6 +617,14 @@ public class ElasticSearchConfiguration {
return sslConfiguration;
}
+ public Optional<Integer> getMaxConnections() {
+ return maxConnections;
+ }
+
+ public Optional<Integer> getMaxConnectionsPerHost() {
+ return maxConnectionsPerHost;
+ }
+
@Override
public final boolean equals(Object o) {
if (o instanceof ElasticSearchConfiguration) {
@@ -609,7 +639,9 @@ public class ElasticSearchConfiguration {
&& Objects.equals(this.requestTimeout, that.requestTimeout)
&& Objects.equals(this.hostScheme, that.hostScheme)
&& Objects.equals(this.credential, that.credential)
- && Objects.equals(this.sslConfiguration, that.sslConfiguration);
+ && Objects.equals(this.sslConfiguration, that.sslConfiguration)
+ && Objects.equals(this.maxConnections, that.maxConnections)
+ && Objects.equals(this.maxConnectionsPerHost, that.maxConnectionsPerHost);
}
return false;
}
@@ -617,6 +649,6 @@ public class ElasticSearchConfiguration {
@Override
public final int hashCode() {
return Objects.hash(hosts, nbShards, nbReplica, waitForActiveShards, minDelay, maxRetries, requestTimeout,
- hostScheme, credential, sslConfiguration);
+ hostScheme, credential, sslConfiguration, maxConnections, maxConnectionsPerHost);
}
}
diff --git a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/elasticsearch.adoc b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/elasticsearch.adoc
index 3cd61a5867..6d3c1fd6cb 100644
--- a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/elasticsearch.adoc
+++ b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/elasticsearch.adoc
@@ -34,6 +34,15 @@ You may consult the https://www.elastic.co/guide/en/elasticsearch/reference/7.10
| elasticsearch.retryConnection.minDelay
| Minimum delay between connection attempts
+
+| elasticsearch.max.connections
+| Maximum count of HTTP connections allowed for the ElasticSearch driver. Optional integer, if unspecified driver defaults
+applies (30 connections).
+
+| elasticsearch.max.connections.per.hosts
+| Maximum count of HTTP connections per host allowed for the ElasticSearch driver. Optional integer, if unspecified driver defaults
+applies (10 connections).
+
|===
=== Mailbox search
diff --git a/src/site/xdoc/server/config-elasticsearch.xml b/src/site/xdoc/server/config-elasticsearch.xml
index 0cd6d1349b..c3bd3276cd 100644
--- a/src/site/xdoc/server/config-elasticsearch.xml
+++ b/src/site/xdoc/server/config-elasticsearch.xml
@@ -87,6 +87,12 @@
<dt><strong>elasticsearch.index.name</strong></dt>
<dd><strong>Deprecated</strong> Use <strong>elasticsearch.index.mailbox.name</strong> instead. <br/>
Name of the mailbox index backed by the alias. It will be created if missing.</dd>
+ <dt><strong>elasticsearch.max.connections</strong></dt>
+ <dd>Maximum count of HTTP connections allowed for the ElasticSearch driver. Optional integer, if unspecified driver defaults
+ applies (30 connections).</dd>
+ <dt><strong>elasticsearch.max.connections.per.hosts</strong></dt>
+ <dd>Maximum count of HTTP connections per host allowed for the ElasticSearch driver. Optional integer, if unspecified driver defaults
+ applies (10 connections).</dd>
<dt><strong>elasticsearch.alias.read.mailbox.name</strong></dt>
<dd>Name of the alias to use by Apache James for mailbox reads. It will be created if missing.
The target of the alias is the index name configured above.</dd>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org