How to decrease java heap size? - java

I've got an app which is running on JBoss. The server's RAM is too low (about 2gb), so I need to decrease Java heap size. Also I've got 2 versions of Java : system version(1.4.2) and 1.7.0 for JBoss 7 only.
So, how can I decrease Java heap size properly?

There are two flags to control the heap size: -Xms128m will start your heap at 128 megs, and -Xmx1g controls the maximum size (here, it would set it to 1 gig).

You can change the heap size in jboss startup file, edit bat or sh file and search for -Xms and change it to your required size.

Default size of Heap space in Java is 128MB on most of 32 bit Sun's JVM and default values of heap size parameters on 64-bit systems have been increased up by approximately 30%.
You can use
java -XX:+PrintFlagsFinal -version | grep HeapSize
to check your default size.
Read more
You can change size of heap space by using JVM options -Xms and -Xmx. Xms denotes starting size of Heap while -Xmx denotes maximum size of Heap in Java.
You can use
java -Xms1024M -Xmx2048M YourApp
Or edit the /bin/run.sh|exe file by searching for “Sun JVM memory allocation pool parameters” and changing the JAVA_OPTS line:
set JAVA_OPTS=%JAVA_OPTS% -server -Xms1152m -Xmx1152m -XX:MaxPermSize=128m
-XX:MaxNewSize=128m

Related

Why am i not able to set exact values vor java heap space?

When i set the java heap space to -Xms4g -Xmx4g my monitory only shows roughly 3.78 GB allocated for heap space. When set to -Xms2g -Xmx2g it shows 1.93 GB like shown in this picture
Where do these values come from?

Increasing memory through terminal in linux through "-XX:PermSize=192m -XX:MaxPermSize=2g -Xms2g -Xmx2g"

I am running java developer IDE and in a process of trouble shooting a module . For this i have increased the logging memory of the tool, Now when logging it error is coming on console as
Uncaught exception
java.lang.OutOfMemoryError: Java heap space
i am using below command for increasing memory
"-XX:CompileThreshold=8000 -XX:PermSize=192m -XX:MaxPermSize=2g -Xms2g -Xmx2g"
earlier it is
"-XX:CompileThreshold=8000 -XX:PermSize=192m -XX:MaxPermSize=1024m -Xms1024m -Xmx1024m"
my system memory is 16 GB through the command cat /proc/meminfo
but the system free memory is less than 1 GB when exception
Uncaught exception
java.lang.OutOfMemoryError: Java heap space
is coming , I have allocated maximum memory to be utilized as 2gb
-XX:MaxPermSize=2g
but it is occupying approximately all available memory.
Do not know whether this command is help full or not whether could i assign more memory like below command
"-XX:CompileThreshold=8000 -XX:PermSize=192m -XX:MaxPermSize=10g -Xms10g -Xmx10g"
increasing it to 10g will be good or not , or is there any problem with my command.
Use -Xms1024m -Xmx1024m to control your heap size (1024m is only for demonstration, the exact number depends your system memory). Setting minimum and maximum heap size to the same is usually a best practice since JVM doesn't have to increase heap size at runtime

java file executed from command line but not from browser(apache)?

I have a java file which is being triggered from a shell script. If I execute the shell script at command line it is executing the java file without any issues but if i execute this shell script from browser( i have a index.php which executes this shell script in linux server ) it is not executing the java file in shell script. The shell script is executed properly If I remove the java execution line from the shell script.
below is the error i received when executed from browser.
Error From browser:Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00007fcf589ac000, 2555904, 1) failed; error='Permission denied' (errno=13) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (malloc) failed to allocate 2555904 bytes for committing reserved memory. # An error report file with more information is saved as: # /tmp/hs_err_pid306.log
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 2555904 bytes for committing reserved memory.
# Possible reasons:
# The system is out of physical RAM or swap space
# In 32 bit mode, the process size limit was hit
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Use 64 bit Java on a 64 bit OS
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
# Out of Memory Error (os_linux.cpp:2726), pid=306, tid=140528680765184
#
# JRE version: (7.0_51-b13) (build )
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode linux-amd64 compressed oops)
Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
Please help me on how I can fix this problem.. Stuck with this issue from last one week. :|
Permission problem.
Probably you run this java file as a different user from a browser.
An error report file with more information is saved as: # /tmp/hs_err_pid306.log
What does this error say?
Issue you have is with the HEAP memory.You don't have set enough memory to run the application.
Default size of Heap space in Java is 128MB on most of 32 bit Sun's JVM but its highly varies from JVM to JVM e.g. default maximum and start heap size for the 32-bit Solaris Operating System (SPARC Platform Edition) is -Xms=3670K and -Xmx=64M and Default values of heap size parameters on 64-bit systems have been increased up by approximately 30%. Also if you are using throughput garbage collector in Java 1.5 default maximum heap size of JVM would be Physical Memory/4 and default initial heap size would be Physical Memory/16. Another way to find default heap size of JVM is to start an application with default heap parameters and monitor in using JConsole which is available on JDK 1.5 onwards, on VMSummary tab you will be able to see maximum heap size.
By the way you can increase size of java heap space based on your application need and I always recommend this to avoid using default JVM heap values. if your application is large and lots of object created you can change size of heap space by using JVM options -Xms and -Xmx. Xms denotes starting size of Heap while -Xmx denotes maximum size of Heap in Java. There is another parameter called -Xmn which denotes Size of new generation of Java Heap Space. Only thing is you can not change the size of Heap in Java dynamically, you can only provide Java Heap Size parameter while starting JVM. I have shared some more useful JVM options related to Java Heap space and Garbage collection on my post 10 JVM options Java programmer must know, you may find useful.
Read more: http://javarevisited.blogspot.com/2011/05/java-heap-space-memory-size-jvm.html#ixzz30FsKCqeT
If it's tomcat you have to set this Memory Variables in "catalina.sh".
Eg : If you a starting the application through command Line :
/bin/java -Xms2048M -Xmx2048M Djava.util.logging.config.file= -Xms2048M -Xmx2048M

Why is Tomcat not reserving minimum heap space

I am running Tomcat 6 on Linux and set Xms and Xmx in setenv.sh. After starting the Tomcat server I don't see the memory usage increased by at least specified in Xms.
Before startup free -m is showing 1500 as free memory.
In my startup.sh I can see memory settings.
CATALINA_OPTS: -Xms512m -Xmx1024m
After server startup free -m is showing 1140 as free memory. Why free memory is not reduced by at least 512m?
jinfo 14064 is showing VM Flags: -Xms512m -Xmx1024m
jmap -heap is also showing memory settings are applied
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 1073741824 (1024.0MB)
Is there anything I am missing?
free -m command
http://www.linuxtoday.com/upload/understanding-free-command-in-linuxunix-130530185004.html
This command will show Actual free RAM.
RAM memory and Virtual memory are different.
Actual initial heap size and max heap size can be allocation by heap
could be identified with the following command.
add the following jvm argument -verbose:gc
and restart the server. Once the server is restarted and after initialization the verbose logs shows the following
// attribute name="maxHeapSize" value="0x40000000"
//attribute name="initialHeapSize" value="0x20000000"
Converting the value into the MB it will show the Xms and Xmx allocation.
Above shown is the snippet of the following command
java -Xms512M -Xmx1024M -verbose:gc -version

error(s)_during_evaluation Eclipse

Eclipse debugger just stopped showing variabile data few days ago it always says error(s)_during_evaluation, i tried increasing the ram in ini , tried to reinstall Eclipse JUNO, and installed Eclipse Helios. Nothing fixed this problem
If it is a memory issue you can try increasing the heap size.It is possible to increase heap size allocated by the Java Virtual Machine (JVM) by using command line options.
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
For running from command line you can use
java -Xms64m -Xmx256m HelloWorld
If you are using the tomcat server, you can change the heap size by going to Eclipse/Run/Run Configuration and select Apache Tomcat/your_server_name/Arguments and under VM arguments section use the following:
-XX:MaxPermSize=256m
-Xms256m -Xmx512M

Categories