Seems like when there is IO operations waiting for external service lots of thread are waiting at sun.misc.Unsafe.park. This contributed to native memory buildup that does not gets cleared. How does this Native memory gets cleared. Does it gets cleared after some time automatically
Using thread-per-connction IO incurs the following memory costs:
ByteBuffer
or byte[]
passed to the read/write/send/receive method-Xss
argument. A complete fix requires multiplexing multiple connections on fewer thread via nonblocking/asynchronous IO. AsynchronousSocketChannel
makes this easy to use for TCP sockets, HttpClient
for HTTP. For other protocols you'll need to look for libraries implementing async IO.DirectByteBuffer
instances to IO methods. using async IO also reduces the total number of buffers that need to be used concurrently Overall the JVM should clean up the native resources needed for IO eventually, but when that happens may depend on how long you keep the java objects that depend on those native resources alive.