elastcsearch RestHighLevelClient使用完成是否需要执行close
Elasticsearch | 作者 tulong | 发布于2020年03月24日 | 阅读数:13379
背景:
1、elasticsearch 7.1,采用自定义初始化RestHightLevelClient,代码如下:
RestClientBuilder build = RestClient.builder( HttpHost.create(address) ).
setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() { @Override public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) { httpAsyncClientBuilder.setMaxConnTotal(100); httpAsyncClientBuilder.setMaxConnPerRoute(100);//最大路由连接数 return httpAsyncClientBuilder; } }).
setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() { @Override public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) { requestConfigBuilder.setConnectTimeout(3*1000); requestConfigBuilder.setSocketTimeout(3*1000);//连接超时时间 requestConfigBuilder.setConnectionRequestTimeout(5*1000);//获取连接超时时间 return requestConfigBuilder; } });
return new RestHighLevelClient(build);
2、在执行查询的地方注入RestHighLevelClient
问题:
1、使用完成后如果调用close方法,第二次调用就无法使用了,难道要重新构建连接吗?每次重新构建连接应该会更浪费时间吧
2、如上这种用法在qps达到600左右的时候会出现一个异常:Request cannot be executed; I/O reactor status: STOPPED,意思是当前连接被关闭了,但是为啥其他请求还能正常查询,如果连接关闭了不应该全部查询不了吗?还是说RestHighLevelClient底层维护了线程池,高并发下取到了某个关闭的连接。如果是这样的,怎么判断取到连接的状态?
1、elasticsearch 7.1,采用自定义初始化RestHightLevelClient,代码如下:
RestClientBuilder build = RestClient.builder( HttpHost.create(address) ).
setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() { @Override public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpAsyncClientBuilder) { httpAsyncClientBuilder.setMaxConnTotal(100); httpAsyncClientBuilder.setMaxConnPerRoute(100);//最大路由连接数 return httpAsyncClientBuilder; } }).
setRequestConfigCallback(new RestClientBuilder.RequestConfigCallback() { @Override public RequestConfig.Builder customizeRequestConfig(RequestConfig.Builder requestConfigBuilder) { requestConfigBuilder.setConnectTimeout(3*1000); requestConfigBuilder.setSocketTimeout(3*1000);//连接超时时间 requestConfigBuilder.setConnectionRequestTimeout(5*1000);//获取连接超时时间 return requestConfigBuilder; } });
return new RestHighLevelClient(build);
2、在执行查询的地方注入RestHighLevelClient
问题:
1、使用完成后如果调用close方法,第二次调用就无法使用了,难道要重新构建连接吗?每次重新构建连接应该会更浪费时间吧
2、如上这种用法在qps达到600左右的时候会出现一个异常:Request cannot be executed; I/O reactor status: STOPPED,意思是当前连接被关闭了,但是为啥其他请求还能正常查询,如果连接关闭了不应该全部查询不了吗?还是说RestHighLevelClient底层维护了线程池,高并发下取到了某个关闭的连接。如果是这样的,怎么判断取到连接的状态?
3 个回复
wuwenxi
赞同来自: Vitosolen
tulong - 80 IT
赞同来自:
1、https://github.com/elastic/ela ... 39946
2、https://github.com/elastic/ela ... 45115
yinyao - 90后it男
赞同来自: