I'm not sure about what is happening and I'm not going to answer exactly your question but here are some thoughts:
If you have an application running, it would be better IMO to have a singleton which you create when the application starts and only close when the application stops.
try the 8.6 version of the client.
It's normally not needed, but may be close as well the restClient?
l mean there will be a few connections to port 9200 and some files open in every request.
but these connections and files open didn't release after the request was finished.
the file open will keep growing until reaches the upper limit of 65535.
in the beginning, there have 1455 file handles, and I post 5 queries, it increases to 1642, and decrease to 1638, then stay at 1638.
[root]# ls -lrt /proc/1382/fd | wc -l
1450
[root]# ls -lrt /proc/1382/fd | wc -l
1455
[root]# ls -lrt /proc/1382/fd | wc -l
1455
[root]# ls -lrt /proc/1382/fd | wc -l
1455
[root]# ls -lrt /proc/1382/fd | wc -l
1642
[root]# ls -lrt /proc/1382/fd | wc -l
1638
[root]# ls -lrt /proc/1382/fd | wc -l
1638
[root]# ls -lrt /proc/1382/fd | wc -l
1638
[root]# ls -lrt /proc/1382/fd | wc -l
1638
[root]# ls -lrt /proc/1382/fd | wc -l
1638
[root]# ls -lrt /proc/1382/fd | wc -l
1638
[root]# ls -lrt /proc/1382/fd | wc -l
1638
[root]# ls -lrt /proc/1382/fd | wc -l
1638
[root]# ls -lrt /proc/1382/fd | wc -l
1638
[root]# ls -lrt /proc/1382/fd | wc -l
1638
[root]# ls -lrt /proc/1382/fd | wc -l
1638
[root]# ls -lrt /proc/1382/fd | wc -l
1638
[root]# ls -lrt /proc/1382/fd | wc -l
1638
[root]# ls -lrt /proc/1382/fd | wc -l
1638
I've solved the file handle issue. some pipe leaking on my test environment.
I think this might not a problem.
And I found that when I create a restClient, there are actually multiple connections more than two being created, I wonder why and why not requests through two connections (client to server and server to client)?
The official clients are generally designed to be set up as singletons and reused by multiple threads. When connecting to Elasticsearch they set up a connection pool of long running connections. Each client request will use one of these connections. This improves performance and latency as new connections do not need to be established repeatedly, which can be slow, especially if SSL is used.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.