1

Possible Duplicate:
Limit jvm process memory on ubuntu

In my application I'm uploading documents to a server, which does some analyzing on it.

Today I analyzed my application using jconsole.exe and heap dumps as I tried to find out if I'm having memory issues / a memory leak. I thought I might suffer of one since my application is growing very much on RAM while the application is running.

As I watched the heap / codecache / perm gen etc. memory with jconsole after some runs, I was surprised as I saw the following:

check

picture link: https://www7.pic-upload.de/13.06.12/murk9qrka8al.png

As you can see at the jconsole on the right, the heap is increasing when I'm doing analyzing-related stuff, but it's also decreasing again to its normal size when the work is over. On the left you can see the "htop" of the sever the application is deployed on. And there it is: The RAM is, although the heap acts normally and it also seems the garbage collector is running correct, incredible high at almost 3,2gb.

This is now really confusing me. I was thinking if my java vm stack could have to do something with this? I did some research and what I found spoke about the vm stack as a little memory with only a few megabytes (or even only kb).

My technical background:

  • The application is running on glassfish v.3.1.2
  • The database is running on MySQL
  • Hibernate is used as ORM framework
  • Java version is 1.7.0_04
  • It's implemented using VAADIN
  • MySQL database and glassfish are the only things running on this server
  • I'm constructing XML-DOM-style documents using JAXB during the analysis and save them in the database
  • Uploaded documents are either .txt or .pdf files
  • OS is linux

Solution?

Do you have any ideas why this happens and what I can do for fixing it? I'm really surprised at the moment, since I thought the memory problems came from a memory leak which causes the heap to explode. But now, the heap isn't the problem. It's the RAM that goes higher and higher while the heap stays on the same level. And I don't know what to do to resolve it.

Thanks for every thought you're sharing with me.

Edit: Maybe I should also state out that this behaviour is currently making me impossible to really let other people use my application. When the RAM is full and the server doesn't respond anymore I'm out.

Edit2: Maybe I should also add that this RAM keeps increasing after every successfull further analyzation.

trincot
  • 317,000
  • 35
  • 244
  • 286
Waylander
  • 825
  • 2
  • 12
  • 34
  • Can you see the picture? Otherwise this is the link: http://www7.pic-upload.de/13.06.12/murk9qrka8al.png – Waylander Jun 13 '12 at 21:13
  • It will help to know the OS. Linux? Thoughts: htop is virtual memory footprint, which is much different from allocated heap. Copying garbage collectors often rely on free space being equal to allocated heap space, so perhaps there is nothing wrong here. – Gene Jun 13 '12 at 21:17
  • I think you are somehow reserving (or the code is) more RAM than needed, but it might be a security measure. Just like if you use an Array with a fixed size, the RAM usage will be less. But if you use something like an ArrayList which does not have a fixed size, then it will take up more RAM etc. It's a simple example, but might be why. – OmniOwl Jun 13 '12 at 21:17
  • the OS is Linux, thanks for the Comment – Waylander Jun 13 '12 at 21:31
  • My problem is about that the ram usage goes higher and higher, not about a bigger size in general that doesn't de- and increase in a bigger way – Waylander Jun 13 '12 at 22:11
  • Are you saying the problem is that your RAM usage within the heap is growing or that your heap is too big? – Preston Jun 14 '12 at 16:27

1 Answers1

1

There are lots more things that use memory in a JVM implementation than the Heap Settings.

The Heap settings via -Xmx only controls the Java Heap, it doesn't control consumption of native memory by the JVM, which is consumed completely differently based on implementation.

From the following article Thanks for the Memory ( Understanding How the JVM uses Native Memory on Windows and Linux )

Maintaining the heap and garbage collector use native memory you can't control.

More native memory is required to maintain the state of the memory-management system maintaining the Java heap. Data structures must be allocated to track free storage and record progress when collecting garbage. The exact size and nature of these data structures varies with implementation, but many are proportional to the size of the heap.

and the JIT compiler uses native memory just like javac would

Bytecode compilation uses native memory (in the same way that a static compiler such as gcc requires memory to run), but both the input (the bytecode) and the output (the executable code) from the JIT must also be stored in native memory. Java applications that contain many JIT-compiled methods use more native memory than smaller applications.

and then you have the classloader(s) which use native memory

Java applications are composed of classes that define object structure and method logic. They also use classes from the Java runtime class libraries (such as java.lang.String) and may use third-party libraries. These classes need to be stored in memory for as long as they are being used. How classes are stored varies by implementation.

I won't even start quoting the section on Threads, I think you get the idea that the Java Heap isn't the only thing that consumes memory in a JVM implementation, not everything goes in the JVM heap, and the heap takes up way more native memory that what you specify for management and book keeping.

Native Code

App Servers many times have native code that runs outside the JVM but still shows up to the OS as memory associated with the process that controls the app server.