在java里面连接es 每个请求都耗费3s左右的时间,在kibana工具里面请求同样的参数只需要几毫秒就能得到结果
下面是使用到Client
@Bean
public RestHighLevelClient restHighLevelClient() {
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost(adress, port, scheme)).setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
public RequestConfig.Builder customizeRequestConfig(
RequestConfig.Builder requestConfigBuilder) {
return requestConfigBuilder.setConnectTimeout(connectTimeout)
.setSocketTimeout(socketTimeout);
}
}).setHttpClientConfigCallback(b->{
b.setMaxConnTotal(1000);
b.setMaxConnPerRoute(5000);
return b;
}));
return client;
}
下面是使用到Client
@Bean
public RestHighLevelClient restHighLevelClient() {
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost(adress, port, scheme)).setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() {
@Override
public RequestConfig.Builder customizeRequestConfig(
RequestConfig.Builder requestConfigBuilder) {
return requestConfigBuilder.setConnectTimeout(connectTimeout)
.setSocketTimeout(socketTimeout);
}
}).setHttpClientConfigCallback(b->{
b.setMaxConnTotal(1000);
b.setMaxConnPerRoute(5000);
return b;
}));
return client;
}
2 个回复
private_void - 一只猹
赞同来自:
debug看下,es原始返回的took是多少,然后对比下请求总耗时。确定下是es的原因还是网络或你程序的原因。
如果took比较长,看下是否是缓存原因,或者java请求时es比较繁忙?
zqc0512 - andy zhou
赞同来自: