java Xms command for increasing heap size not working correctly

3.1k Views Asked by At

Ubuntu Server hosting some WAr apps is getting several heap error meessages like follows. This server runs tomcat8 and was working perfectly, now and without any changes on code side server is getting error and Tomcat stops.

    EVERE: SEVERE:Memory usage is low, parachute is non existent, your 
    system may start failing.
Exception: java.lang.OutOfMemoryError thrown from the 
UncaughtExceptionHandler in thread "Thread-21"
Exception: java.lang.OutOfMemoryError thrown from the 
UncaughtExceptionHandler in thread "Thread-9"
Exception: java.lang.OutOfMemoryError thrown from the 
UncaughtExceptionHandler in thread "Thread-17"
SEVERE:Memory usage is low, parachute is non existent, your system may start 
failing.
Exception in thread "Thread-11" java.lang.OutOfMemoryError: Java heap space
Exception in thread "http-nio-8080-Acceptor-0" Exception in thread 
"ContainerBackgroundProcessor[StandardEngine[Catalina]]" Exception in thr 
09:39:19.841 ERROR 116336 --- [nio-8080-exec-5] 
o.s.b.w.servlet.support.ErrorPageFilter  : Forwarding to error page from 
request [/teams/my
java.lang.OutOfMemoryError: Java heap space
SEVERE:Memory usage is low, parachute is non existent, your system may start 
failing.
java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space

I´m not a developer so I don´t know pretty much about java (basic things). At first I though that It was related to ram memory (4gb on server) but then I read in many places that is pretty much related to Java max heap size . So I run following command and checked that I have 65 MB for inicial size and 1 GB for maximum.

java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize'
 intx CompilerThreadStackSize                   = 0                                   {pd product}
uintx ErgoHeapSizeLimit                         = 0                                   {product}
uintx HeapSizePerGCThread                       = 87241520                            {product}
uintx InitialHeapSize                          := 65011712                            {product}
uintx LargePageHeapSizeThreshold                = 134217728                           {product}
uintx MaxHeapSize                              := 1031798784                          {product}
 intx ThreadStackSize                           = 1024                                {pd product}
 intx VMThreadStackSize                         = 1024                                {pd product}

Now I want to increment max size to 2 GB and set it like that. I checked in this post here and is talking about the command to do So, but when I run it on the console I´m unable to do so. Here is command:

 java -Xms64m -Xmx2048m

I get this, like command syntax is not ok

Usage: java [-options] class [args...]
       (to execute a class)
   or  java [-options] -jar jarfile [args...]
       (to execute a jar file)

Also read this answer but is not quite clear

Also I read aboud editing catalina.sh , but If I vim that command I don´t get any part where heap size or Xms can be edited so question would be:

Also read this but I don´t wan´t to set this for any jar, Want to do this for all war applications on server.

So After reading so many posts and answers, and not having the best knowledge in java, how is the best way to do this? How is the correct command? after this command is run the max heap size is configured for good? I also know that on the code side, devs also need to check their part as I also read that this issue is not only from hardware and java configuration . Thank you!

2

There are 2 best solutions below

1
On BEST ANSWER

Okay, the java command you're trying doesn't set some global value or anything like that. That is how you would specify the initial and max heap when running a particular program, and the error message is telling you, 'I don't know what you want me to run. Please tell me where to find my main method'.

This isn't a ubuntu problem, either. It's really a Tomcat issue. You're going to need to update your Tomcat configuration. You need to tell Tomcat to start your program with the memory amounts you need. Please review Tomcat documentation (or maybe someone else will tell you how, but I haven't run Tomcat in years).

For what it's worth, you may need to get a programmer involved. You don't say what your program is trying to do, but needing more than 1 gig may be systematic of a different problem. It could just be you're working with sorta-big data, but running out of memory very often is a programming bug

0
On

instead of trying to set the values globally to jvm assign the xmx and xms values to the process such that it takes the values you specify

java -Xms64m -Xmx2048m -jar {your application name }

rather than going with the above command which you are currently using, i recommend you to do below

 java -jar -Xms64m -Xmx2048m {your application name }

here min max heap sizes will be set to your process itself.

to verify whether the specified values got updated, you can use the below cammands.

you can use jps command to list down all currently running processes.then pick the pid of the process relevant to your application.

use the below command with the pid you received for your application

jcmd {pid} VM.flags

this will give you a response like this

-XX:CICompilerCount=4 -XX:InitialHeapSize=4345298944 -XX:MaxHeapSize=8388608000 -XX:MaxNewSize=2796027904 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=1448083456 -XX:OldSize=2897215488 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseParallelGC 

here you can see both initial heap size(Xms ) and mac heap size (Xmx).(in my case it was 4Gb and 8Gb-yours should be 64mb and 2 Gb). check whether they tally with the values u set after running the command I recommended.

if so you are all good.