Keepalive property for the connection between client and elasticsearch should be considered as configurable. Futher more, i do think it's good to keep it alive by default.
Here is the issue:
When read/write elasticsearch in high concurrency, threads have chances to stuck on obsolete connection between client and elasticsearch. The more threads involves, the quicker stucking on connection happens. The reason is described here:
Worse, if the connection is dropped silently while a request is in flight then the client may block indefinitely since it will send no more data on this connection and will therefore never find out that it's been closed.
And here is the situation i run into. Logs can also be found here: - https://stackoverflow.com/questions/73217318/elasticsearch-java-response-stuck
similar issue: - https://github.com/elastic/elasticsearch/issues/65909
However, spring boot can't config keepalive through current properties. We have to write some config codes like:
@Bean
public RestClientBuilderCustomizer keepalive() {
return new RestClientBuilderCustomizer() {
@Override
public void customize(RestClientBuilder builder) {
}
@Override
public void customize(HttpAsyncClientBuilder builder) {
builder.setDefaultIOReactorConfig(IOReactorConfig.custom().setSoKeepAlive(true).build());
log.info("es tcp keep-alive must be enabled!");
}
};
}
So i add some support for spring.elasticsearch.keepalive=true to make it easier to config.
Comment From: pivotal-cla
@puppylpg Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
Comment From: pivotal-cla
@puppylpg Thank you for signing the Contributor License Agreement!
Comment From: snicoll
@puppylpg thank you for making your first contribution to Spring Boot.
Comment From: puppylpg
Will this mr be merged into 2.x.x besides 3.0.0-M5?
Comment From: wilkinsona
Sorry, it won't. It's an enhancement so it only belongs in a new major or minor release. We don't have any plans at the moment for a 2.8 release so 3.0 is the next available release in which it can be included.
Comment From: puppylpg
ok, thanks for your reply (sad, for still using jdk8 in our production environment :sweat_smile::sweat_smile::sweat_smile:)