# RestHighLevelClient slow performance

**URL:** <https://discuss.elastic.co/t/resthighlevelclient-slow-performance/182746>\
**Category:** Elasticsearch\
**Created:** [May 25, 2019, 6:33am UTC](https://discuss.elastic.co/t/resthighlevelclient-slow-performance/182746 "2019-05-25T06:33:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![eugene\_p](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugene_p/32/46839_2.png) [@eugene\_p](https://discuss.elastic.co/u/eugene_p)\
**Post date:** [May 25, 2019, 6:33am UTC](https://discuss.elastic.co/t/resthighlevelclient-slow-performance/182746/1 "2019-05-25T06:33:12Z")

</div>

Hi everyone.  
I noticed that requests executed through RestHighLevelClient slower 6 times than the same requests executed through curl or Postman.

So I configure the RestHighLevelClient:

```
@Bean
fun restHighLevelClient(): RestHighLevelClient {
    val trustStrategy = TrustSelfSignedStrategy()

    val sslContext = SSLContexts.custom()
            .loadTrustMaterial(File(trustStore), trustStorePassword.toCharArray(), trustStrategy)
            .loadKeyMaterial(File(keyStore), keyStorePassword.toCharArray(), keyStorePassword.toCharArray())
            .build()

    val credentialsProvider = BasicCredentialsProvider()
            .apply { setCredentials(AuthScope.ANY, UsernamePasswordCredentials(username, password)) }

    return RestHighLevelClient(RestClient.builder(
            *getHosts(hosts)
    ).setHttpClientConfigCallback {
        it
                .setMaxConnPerRoute(maxConnPerRoute)
                .setMaxConnTotal(maxConnTotal)
                .setDefaultCredentialsProvider(credentialsProvider)
                .setSSLContext(sslContext)
    }
    )
}

```

In VisualVM I can see that search request takes 401ms.

 ![38](https://us1.discourse-cdn.com/elastic/original/3X/e/6/e6c1b2fe1b62565ceafc93d531dea80512aab48c.png)

But if I copy request from logs and call it in Postman it takes 65ms.

 ![06](https://us1.discourse-cdn.com/elastic/original/3X/d/6/d6f7099e128e68d18869c789cd304614549d058c.png)

It's a big difference. How can I improve performance in my code?

---

<div class="post-metadata">

**Author:** ![eugene\_p](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugene_p/32/46839_2.png) [@eugene\_p](https://discuss.elastic.co/u/eugene_p)\
**Post date:** [May 25, 2019, 5:13pm UTC](https://discuss.elastic.co/t/resthighlevelclient-slow-performance/182746/2 "2019-05-25T17:13:32Z")

</div>

Wrote my own implementation for search:

```
private fun searchRequest(index: Index,
                          indexType: IndexType,
                          source: SearchSourceBuilder): SearchResponse {
    val searchRequest = SearchRequest(index.index)
            .types(indexType.type)
            .source(source)

    val request = Converter.createSearchRequest(searchRequest).entity.content
    val writer = StringWriter()
    IOUtils.copy(request, StringWriter(), StandardCharsets.UTF_8.name())
    val httpEntity = HttpEntity(writer.toString(), getHeders())

    val postForEntity = restTemplateElastic.postForEntity(getHost(), httpEntity, String::class.java)

    val httpEntityResponse = BasicHttpEntity()
    httpEntityResponse.content = IOUtils.toInputStream(postForEntity.body, StandardCharsets.UTF_8.name())
    return Converter.createSearchResponse(httpEntityResponse, restHighLevelClient)
}

```

It's quicker than the standard implementation

My implementation:

Lifting the server siege...  
Transactions: 25226 hits  
Availability: 100.00 %  
Elapsed time: 61.06 secs  
Data transferred: 314.29 MB  
Response time: 0.24 secs  
Transaction rate: 413.13 trans/sec  
Throughput: 5.15 MB/sec  
Concurrency: 99.83  
Successful transactions: 25226  
Failed transactions: 0  
Longest transaction: 8.00  
Shortest transaction: 0.06

RestHighLevelClient.search

Lifting the server siege...  
Transactions: 1886 hits  
Availability: 100.00 %  
Elapsed time: 60.78 secs  
Data transferred: 23.49 MB  
Response time: 3.15 secs  
Transaction rate: 31.03 trans/sec  
Throughput: 0.39 MB/sec  
Concurrency: 97.60  
Successful transactions: 1886  
Failed transactions: 0  
Longest transaction: 6.77  
Shortest transaction: 0.80

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 25, 2019, 6:11pm UTC](https://discuss.elastic.co/t/resthighlevelclient-slow-performance/182746/3 "2019-05-25T18:11:10Z")

</div>

That's great. Could you share your findings in an elasticsearch issue so the client team might have a chance to look at this.

Cc @javanna aware of anything like this?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 26, 2019, 7:39am UTC](https://discuss.elastic.co/t/resthighlevelclient-slow-performance/182746/4 "2019-05-26T07:39:50Z")

</div>

Ha. Thanks for opening the issue in github:

> <https://github.com/elastic/elasticsearch/issues/42558>

I didn't know initially that you were using an "old" elasticsearch version of the rest client. Any chance you could run the same tests with 6.8.0?

---

<div class="post-metadata">

**Author:** ![eugene\_p](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eugene_p/32/46839_2.png) [@eugene\_p](https://discuss.elastic.co/u/eugene_p)\
**Post date:** [May 26, 2019, 7:43am UTC](https://discuss.elastic.co/t/resthighlevelclient-slow-performance/182746/6 "2019-05-26T07:43:39Z")

</div>

Reproduced on 6.8.0

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 26, 2019, 8:04am UTC](https://discuss.elastic.co/t/resthighlevelclient-slow-performance/182746/7 "2019-05-26T08:04:58Z")

</div>

Great. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 23, 2019, 8:05am UTC](https://discuss.elastic.co/t/resthighlevelclient-slow-performance/182746/8 "2019-06-23T08:05:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
