Commit 08ce8189 authored by Matija Obreza's avatar Matija Obreza

ES: Rest client network configuration updated

- No keep-alive
- Socket timeouts
parent 01862d84
......@@ -28,6 +28,7 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import org.apache.http.HttpHost;
import org.apache.http.impl.NoConnectionReuseStrategy;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.node.Node;
......@@ -152,7 +153,22 @@ public class ElasticsearchConfig extends ElasticsearchConfigurationSupport {
URL hostUrl = new URL(host);
httpHosts.add(new HttpHost(hostUrl.getHost(), hostUrl.getPort(), hostUrl.getProtocol()));
}
return new RestHighLevelClient(RestClient.builder(httpHosts.toArray(new HttpHost[httpHosts.size()])));
return new RestHighLevelClient(RestClient.builder(httpHosts.toArray(new HttpHost[httpHosts.size()])).setHttpClientConfigCallback((httpClientBuilder) -> {
// Does this make a difference?
httpClientBuilder.disableAuthCaching().disableCookieManagement();
httpClientBuilder.setMaxConnTotal(50);
httpClientBuilder.setMaxConnPerRoute(50);
// Don't reuse connections
httpClientBuilder.setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE);
System.err.println("Updated ES HTTP client config");
return httpClientBuilder;
}).setRequestConfigCallback((requestConfigBuilder) -> {
requestConfigBuilder.setConnectTimeout(2000); // default is 1000
requestConfigBuilder.setConnectionRequestTimeout(2000); // default is 1000
requestConfigBuilder.setSocketTimeout(-1); // forever
return requestConfigBuilder;
}));
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment