Java process has physical memory larger than committed memory from jcmd

Viewed 98

I have a server java app use jetty websocket server and bittorrent-tracker for websocket client

The issue is when I run with many client it has a memory leak in my java app

I check the memory usage of java app by "htop" and "jcmd PID VM.native_memory"

  • The RES in "htop" show 6.4G
  • The memory committed in "jcmd" show 2G

The jetty websocket version I use is jetty-9.4.15.v20190215, I had try newer version jetty-9.4.44.v20210927 but still memory leak

I had tested with client build from jetty websocket-client and memory leak doesn't happen

I also test with following options

  • Only use lib jetty websocket on my server java app
  • When handle onMessage I just receive messages and not take any process or response

=> Basically the server only receives connect from client and memory leak still happen.

The question is

  • Where cause memory leak ?
  • Why physical memory(RES) in "htop" larger than committed memory from jcmd ?
1 Answers

"Where cause memory leak ?"

It is probably your code. For example, if websockets are not being closed correctly on the server side, they may hang around consuming various resources ... including off-heap buffers and so on.

It is not inconceivable that there is a bug in the Jetty code that causes this, but if there was, one would expect that other people will have reported it, etcetera. (Have you checked the Jetty issue tracker for confirmed reports of memory leaks in the Jetty websocket code?)

Either way you will need to do some investigation.


Why physical memory(RES) in "htop" larger than memory usage in JVM ?

That is not unusual. A typical JVM uses a lot of memory in addition to the Java heap. This usage includes:

  • The memory used by the JVM executable, and native libraries that it uses.
  • Metaspace ... which holds compiled Java code, and so on.
  • Off-heap allocations requested by native code for various purposes.
  • Memory mapped files and so on.
Related