7

I'm using JEST to connect to elasticsearch in a spring-boot application. When the application is idle (doesn't send any requests to elasticsearch) for some time, then the JestClient is throwing SocketTImeoutException. I'm creating the client using a bean:

@Bean
public JestClient client() throws Exception {
    JestClientFactory factory = new JestClientFactory();
    factory.setHttpClientConfig(new HttpClientConfig
        .Builder(esURL)
        .multiThreaded(true)
        .connTimeout(60000)
        .readTimeout(60000)
        .defaultMaxTotalConnectionPerRoute(10)
        .maxTotalConnection(100).build());
    return factory.getObject();
}

Is there anything I'm missing here?

Ian Campbell
  • 23,484
  • 14
  • 36
  • 57
pkgajulapalli
  • 1,066
  • 3
  • 20
  • 44
  • What version of es? and jest? – Depzor Jan 17 '18 at 13:15
  • ES version 5.6.5 & Jest version 5.3.3 – pkgajulapalli Jan 17 '18 at 16:27
  • Have you found a solution already? I have the exact same issue: the first request in a while is then taking 30 seconds and a timeout occurs.. then the next requests give almost instant response back) (using jest 2.0.4) – Depzor Jan 24 '18 at 21:29
  • 2
    @Depzor @pkgajulapalli Just mentioning an idea I would try: look into this feature - https://github.com/searchbox-io/Jest/pull/149 - meaning, configure `maxConnectionIdleTime` so that the idle connections are killed **before** actually being used (which would result in the timeout exception you get). An example in the tests themselves: https://github.com/searchbox-io/Jest/blob/v2.0.4/jest/src/test/java/io/searchbox/client/JestClientFactoryIntegrationTest.java#L116 – Andrei Stefan Jan 25 '18 at 01:13
  • @andrei-stefan Mmm when adding this: .IllegalStateException: Expected the service to be RUNNING, but the service has FAILED – Depzor Jan 25 '18 at 08:14
  • Looks weird. That's just a parameter, why would you get that just by adding it?! Are you sure it's the parameter's fault? – Andrei Stefan Jan 25 '18 at 08:33
  • Mmm guava dependency conflict: java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor; – Depzor Jan 25 '18 at 09:47
  • Bummer. When I looked in GH that feature should be available in the Jest version you are using. – Andrei Stefan Jan 25 '18 at 16:56
  • @AndreiStefan yes it seems to work now! (was using guava 16.0 and 19.0 is required) and no more time outs occur after being idle for some time. Thanks a lot. What would be a good setting for maxConnectionIdleTime, currently set it to 10 seconds... why 10 and not 1 second for instance? – Depzor Jan 27 '18 at 10:21
  • I can imagine that you would want to reuse connections and not create one every time. – Andrei Stefan Jan 27 '18 at 12:39
  • And a 1 second idle time would kill them really often. – Andrei Stefan Jan 27 '18 at 14:04

1 Answers1

3

An idea I would try: look into this feature - https://github.com/searchbox-io/Jest/pull/149 - meaning, configure maxConnectionIdleTime so that the idle connections are killed before actually being used (which would result in the timeout exception you get). An example in the tests themselves: https://github.com/searchbox-io/Jest/blob/v2.0.4/jest/src/test/java/io/searchbox/client/JestClientFactoryIntegrationTest.java#L116

Regarding the value to use for it, I am not sure what is the timeout for the network socket... guessing 30 seconds. And whatever you set for the maxConnectionIdleTime it should be less than that. Maybe try to observe from the timeouts you get what idle time protects you and which not.

Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89