Applying Grails Too Much Memory

Tomcat 5.5.x and 6.0.x

Grails 1.6.x

Java 1.6.x

OS CentOS 5.x (64 bit)

VPS server with memory as 384M

JAVA_OPTS: tried many combinations, including the following

export JAVA_OPTS = '- Xms128M -Xmx512M -XX: MaxPermSize = 1024m'

export JAVA_OPTS = '- server -Xms128M -Xmx128M -XX: MaxPermSize = 256M'

(As recommended by http://www.grails.org/Deployment )

I created an empty Grails application by simply providing the grails create-app command and then WARed it

I am running Tomcat on a VPS server

When I simply start the Tomcat server without deploying the applications, the free memory is about 236M and the used memory is about 156 M.

When I deploy my β€œempty” application, the memory consumption increases to 360 M, and finally, the Tomcat instance is killed as soon as it takes up all the free memory

As you saw, my application is as light as possible.

Not sure why memory consumption is so high.

I was really looking for a real application, but narrowed down to this scenario, which is easier to share and explain.

UPDATE I tested the same "empty" application on my local Tomcat 5.5.x on Windows and it worked fine

Java process memory consumption captured from 32 M to 107 M. But it did not crash and remained within acceptable limits

So, the hunt for the answer continues ... Interestingly, something is wrong in my Linux box. Not sure though ...

UPDATE 2 See Also http://www.grails.org/Grails+Test+On+Virtual+Server

This confirms my belief that my simple application should work on my configuration.

+4
source share
3 answers

It is a false economy to try to run a long Java application in as little memory as possible. The garbage collector, and therefore the application will work much more efficiently if it has a lot of regular heap memory. Give the application too little heap and it will spend too much time collecting garbage.

(This may seem a little contradictory, but believe me: the effect is predictable in theory and observed in practice.)

EDIT

In practical terms, I would suggest the following approach:

  • Start by launching Tomcat + Grails with the same memory as you can give it so that you have something that starts. (Set the size of the pepper to the default ... unless you have clear evidence that Tomcat + Grails is exhausting itself.)

  • Run the application to get it in a steady state and find out what its average working set is. You should be able to figure this out from the memory profiler or by examining the GC log.

  • Then set the Java heap size to (say) double measure the working set size or more. (This is what I tried to do above.)

Actually, there is another possible reason for your problems. Although you say Java to use heaps of a given size, it may not be able to do this. When the JVM requests memory from the OS, there are a couple of situations where the OS refuses.

  • If the computer (real or virtual) that runs the OS does not have unallocated "real" memory, and the swap space of the OS is fully allocated, it will have to refuse requests for more memory.

  • In addition, it is possible (although unlikely) that the memory limits for each process are valid. This will force the OS to refuse requests outside this limit.

Finally, note that Java uses more virtual memory, which can be taken into account simply by adding the stack, heap, and number of perments together. There is memory used by executable + DLLs, memory used for I / O buffers, and possibly other materials.

+6
source

384MB is quite small. I run a small Grails application on a 512 MB VPS on enjoyvps.net (in no way connected, just a happy client) and it has been running for a few months a little under 200 MB. I use 32-bit Linux and the JDK, although it doesn't make sense to spend all this memory on 64-bit pointers if you don't have access to a lot of memory.

0
source

Can you try deploying tomcat monitoring software like psiprobe and finding out where the memory is used?

0
source

Source: https://habr.com/ru/post/1305408/


All Articles