# Higher number of active threads with elasticsearch-java dependency

**URL:** <https://discuss.elastic.co/t/higher-number-of-active-threads-with-elasticsearch-java-dependency/364385>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [August 5, 2024, 1:10pm UTC](https://discuss.elastic.co/t/higher-number-of-active-threads-with-elasticsearch-java-dependency/364385 "2024-08-05T13:10:18Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![sibasish.palo](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@sibasish.palo](https://discuss.elastic.co/u/sibasish.palo)\
**Post date:** [August 13, 2024, 11:59am UTC](https://discuss.elastic.co/t/higher-number-of-active-threads-with-elasticsearch-java-dependency/364385/21 "2024-08-13T11:59:57Z")

</div>

sorry if i am asking a very basic question

1. if we go ahead with a load balancer(LB) the client always resolves to one IP from the LB, which defeats the whole purpose of having a load balancer
2. if we go ahead with registering the IP addresses of Elasticsearch client nodes with a sniffer, how the sniffer manages/re-establishes the connections if all the registered client nodes goes down

I understand all the approaches outlined seems reasonable but what i was looking for is some kind of best practices or best way to connect to the Elasticsearch cluster with fail safes in place.

Again sorry if i am asking something very very basic

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [August 13, 2024, 12:12pm UTC](https://discuss.elastic.co/t/higher-number-of-active-threads-with-elasticsearch-java-dependency/364385/22 "2024-08-13T12:12:28Z")

</div>

> [@sibasish.palo](#):
>
> the client always resolves to one IP from the LB

You can specify a collection of IP addresses when constructing the client, rather than just a single `HttpHost`. Or you can use the LB as the seed address for sniffing.

---

<div class="post-metadata">

**Author:** ![sibasish.palo](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@sibasish.palo](https://discuss.elastic.co/u/sibasish.palo)\
**Post date:** [August 27, 2024, 3:26pm UTC](https://discuss.elastic.co/t/higher-number-of-active-threads-with-elasticsearch-java-dependency/364385/23 "2024-08-27T15:26:39Z")

</div>

Thank you for the information.

need one more help though.

we are seeing many connections on `TIME_WAIT` state and connections seems to be reset every 10 minute interval(strange behaviour).

Below is the code we are using

```auto
RestClientBuilder restClientBuilder = RestClient.builder(
                new HttpHost("host", port, "https"));

        restClientBuilder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
            @Override
            public HttpAsyncClientBuilder customizeHttpClient(final HttpAsyncClientBuilder b) {
                b.setMaxConnPerRoute(500);
                b.setMaxConnTotal(500);
                return b.setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(210).build());
            }
        });

        ElasticsearchTransport transport = new RestClientTransport(restClientBuilder.build(), new JacksonJsonpMapper());
        return new ElasticsearchClient(transport);

```

1. do we have any configuration or a way to keep minimum connections similar to `setMaxConnTotal()`, tried searching in documentation didn't find any .
2. Any help on why the connections will reset every 10 minute interval, does it have some internal time out set some where ?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [August 27, 2024, 3:30pm UTC](https://discuss.elastic.co/t/higher-number-of-active-threads-with-elasticsearch-java-dependency/364385/24 "2024-08-27T15:30:41Z")

</div>

> [@sibasish.palo](#):
>
> connections seems to be reset every 10 minute interval(strange behaviour).

Normally this kind of thing is due to some network device interfering with open connections rather than anything you can fix in software. You'll need to talk to your network infra folks about it.

---

<div class="post-metadata">

**Author:** ![sibasish.palo](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@sibasish.palo](https://discuss.elastic.co/u/sibasish.palo)\
**Post date:** [August 27, 2024, 3:32pm UTC](https://discuss.elastic.co/t/higher-number-of-active-threads-with-elasticsearch-java-dependency/364385/25 "2024-08-27T15:32:26Z")

</div>

Thank you for the quick reply.

any configuration option for a way to keep minimum connections similar to `setMaxConnTotal()`

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [August 27, 2024, 3:55pm UTC](https://discuss.elastic.co/t/higher-number-of-active-threads-with-elasticsearch-java-dependency/364385/26 "2024-08-27T15:55:55Z")

</div>

I'm not aware of anything like that. If you're using enough connections, they'll stay open, otherwise they will get cleaned up. So maybe you're not sending enough requests?

---

<div class="post-metadata">

**Author:** ![sibasish.palo](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@sibasish.palo](https://discuss.elastic.co/u/sibasish.palo)\
**Post date:** [August 27, 2024, 4:42pm UTC](https://discuss.elastic.co/t/higher-number-of-active-threads-with-elasticsearch-java-dependency/364385/27 "2024-08-27T16:42:00Z")

</div>

Ok thank you for the information.

[Previous page](https://discuss.elastic.co/t/higher-number-of-active-threads-with-elasticsearch-java-dependency/364385.md?page=1)
