Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
java [2012/12/04 23:47]
a
java [2012/12/05 00:07]
a [Good/best practices]
Line 1: Line 1:
 ====== Java (jvm) tips and tricks ====== ====== Java (jvm) tips and tricks ======
 +
 +
 +===== Enviroment settings =====
 +
 +==== Linux (with multiple java enviroments) ====
 +
 +''.bashrc'' / ''bash.profile''
 +   export JAVA_HOME="/usr/local/java/"
 +   export PATH=/usr/local/java/bin:$PATH
 +
 +
 +
 +===== Tunning  =====
  
 {{ :memoryjvm.png?nolink |}} {{ :memoryjvm.png?nolink |}}
Line 15: Line 28:
 | **-XX:MinHeapFreeRatio** | default is 40%. JVM will allocate memory to always have as minimum 40% of free memory. When -Xmx = -Xms, it's useless. | | **-XX:MinHeapFreeRatio** | default is 40%. JVM will allocate memory to always have as minimum 40% of free memory. When -Xmx = -Xms, it's useless. |
 | **-XX:MaxHeapFreeRatio:** | default is 70%. The same as Min, to avoid unecessary memory allocation. | | **-XX:MaxHeapFreeRatio:** | default is 70%. The same as Min, to avoid unecessary memory allocation. |
 +
 +
 +<note important>
 +**A nice gotcha...** \\
 +Major collection don't run until tenured is full.
 +This mean that using -Xmx1024, current heap could be 750MB with 500MB of "dead" object. If the JVM is idle, it could stay like that during a very long time => wasting 500MB or RAM for an idle JVM !
 +</note> 
 +
 <note tip> <note tip>
    * It is good practice with server-side Java applications like Resin to set the minimum **''-Xms''** and maximum **''-Xmx''** heap sizes to the same value.    * It is good practice with server-side Java applications like Resin to set the minimum **''-Xms''** and maximum **''-Xmx''** heap sizes to the same value.
    * For efficient garbage collection, the **''-Xmn''** value should be lower than the **''-Xmx''** value.    * For efficient garbage collection, the **''-Xmn''** value should be lower than the **''-Xmx''** value.
 </note> </note>
 +
 +==== Good/best practices ====
 +
 +FIXME
 +==== Examples ====
 +
 +tying to limit jvm to ~2G of RAM (java x86_64)
 +    java -Xms512m -Xmx2G -XX:+UseCompressedOops -server -XX:MaxPermSize128
 +    
 +java (i386)
 +    java -Xms1400m -Xmx2G -XX:MaxPermSize=128m -server
 +==== Troubleshooting ====
 +
 +=== Resolving java.lang.OutOfMemoryError: PermGen ===
 +if you get an error like:
 +
 +   java.lang.OutOfMemoryError: PermGen
 +
 +The PermGen space is used for things that do not change (or change often). e.g. Java classes.  So often large, complex apps will need lots of PermGen space.  Similarly if you are doing frequent war/ear/jar deployments to running servers like Tomcat or JBoss you may need to issue a server restart after a few deploys or increase your PermGen space.
 +
 +To increase the PermGen space use something like: **-XX:MaxPermSize=128m** //(The default is 64MB.)//
 +
 +(Note that Xmx is separate from the PermGen space, so increasing Xmx will not help with the PermGen errors). \\
 +**The PermGen memory in addition to the Xmx memory.  e.g. -Xmx128m and MaxPermSize=128m would use up to 256MB.**
 +
 +
 +
 +
 +
 +
 +
  
  
  
java.txt ยท Last modified: 2012/12/07 12:29 by a
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready