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

Non-configurable elasticsearch client connection pool #40832

Closed
Sycamore-M opened this issue May 20, 2024 · 2 comments
Closed

Non-configurable elasticsearch client connection pool #40832

Sycamore-M opened this issue May 20, 2024 · 2 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@Sycamore-M
Copy link

Environment: SpringBoot 2.7.10, Elasticsearch, Java 11.

I'm using springboot autoconfigured org.elasticsearch.client.RestHighLevelClient, it uses httpclient's connection pool to send requests.

The maximum number of connections in the connection pool is fixed at 30 and is not configurable. When it accesses an elasticsearch cluster with more than 30 nodes, the connection cannot be reused correctly. It leads to too many connections in the TIME_WAIT state and increase server load.

My temporary solution is to use java reflection to modify the maximum number of connections in the connection pool:

@Configuration
public class ElasticsearchConfig {

    ElasticsearchConfig(RestHighLevelClient restHighLevelClient) throws Exception {
        HttpAsyncClient httpClient = restHighLevelClient.getLowLevelClient().getHttpClient();
        Field field = httpClient.getClass().getDeclaredField("connmgr");
        field.setAccessible(true);
        PoolingNHttpClientConnectionManager mgr = (PoolingNHttpClientConnectionManager) field.get(httpClient);
        mgr.setMaxTotal(100);
    }

}

I want to know why there is no configurable elasticsearch client connection pool provided. It is obvious that large-scale elasticsearch clusters have to adjust the connection pool size as needed.

Will you support it in future versions? Thanks.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 20, 2024
@wilkinsona
Copy link
Member

OSS support for Spring Boot 2.7.x is no longer available. Please upgrade to Spring Boot 3.1.x or later. Also, please note that Spring Boot 3.x no longer supports the high-level REST client with support for co.elastic.clients:elasticsearch-java and org.elasticsearch.client:elasticsearch-rest-client being provided instead.

If you're stuck on 2.7.x, you can use a RestClientBuilderCustomizer and its customize(HttpAsyncClientBuilder builder) method to customize the underlying HTTP client to meet your needs.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2024
@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels May 20, 2024
@Sycamore-M
Copy link
Author

Limited by the existing ES cluster version, upgrading is difficult.

Thank you for your guidance, I will try to use RestClientBuilderCustomizer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants