java-client icon indicating copy to clipboard operation
java-client copied to clipboard

Http client connection management is not optimal

Open zhenglaizhang opened this issue 3 years ago • 1 comments

When we dig into the CommonsHttpClientImpl, upon each request, it will create new http client, execute and then close https://github.com/semi-technologies/weaviate-java-client/blob/85a837c61e096b8bab0512a14ba2c519d9ae421b/src/main/java/technology/semi/weaviate/client/base/http/impl/CommonsHttpClientImpl.java#L112 The http client created by HttpClients.createDefault() has a default connection manager with max=20 and maxPerRoute=2. However it should be put as the CommonsHttpClientImpl class field and shared by multiple http calls and no need to do client close. Otherwise, we may met with following exception under a bit heavy load.

Mar 30, 2022 3:20:23 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.NoRouteToHostException) caught when processing request to {}->[http://10.43.68.129:80](http://10.43.68.129/): Cannot assign requested address (Address not available)
Mar 30, 2022 3:20:23 PM org.apache.http.impl.execchain.RetryExec execute

And going further we can use customized HTTP client connection pool manager to let client optimize the connections based on their loads. And I tried locally this will increase the throughput especially under heavy load.

Creating the issue just for sync up in case you guys are already actively optimizing this. If not I could probably create a PR for this.

zhenglaizhang avatar Mar 31 '22 14:03 zhenglaizhang

I think this has been fixed, @antas-marcin?

byronvoorbach avatar Dec 07 '22 12:12 byronvoorbach