<rdf:RDF
    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    xmlns:s='http://snipsnap.org/rdf/snip-schema#'
    xml:base='http://bliki.rimuhosting.com/rdf'>
    <s:Snip rdf:about='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java/-Xmx+settings'
         s:cUser='retep'
         s:oUser=''
         s:mUser='retep'>
        <s:name>knowledgebase/linux/java/-Xmx settings</s:name>
        <s:content>1 Java&apos;s -Xmx Heap Settings&#xD;&#xA;&#xD;&#xA;Java has a couple of settings that help control how much memory it uses:&#xD;&#xA;-Xmx sets the maximum memory heap size&#xD;&#xA;-Xms sets the minimum memory heap size.&#xD;&#xA;&#xD;&#xA;1.1 Keep -Xms Small&#xD;&#xA;&#xD;&#xA;For a server with a &apos;small&apos; amount of memory, then we recommend that -Xms is kept as small as possible.  e.g. -Xmx16m.  Some customers set this higher, but that can lead to issues.  e.g. the command that restarts tomcat runs a java process.  That Java process picks up the same -Xms setting as the actual Tomcat process.  So you will effectively be using two times -Xms when doing a restart.  If you set -Xms too high, then you may run out of memory.&#xD;&#xA;&#xD;&#xA;1.1 Don&apos;t Let -Xmx Be Too Low&#xD;&#xA;&#xD;&#xA;When setting the -Xmx setting you should consider a few things...  -Xmx has to be enough for you to run your app.  If it is set too low then you may get Java OutOfMemory exceptions (even when there is sufficient spare memory on the server).&#xD;&#xA;&#xD;&#xA;1.1 Figuring Out a Reasonable -Xmx&#xD;&#xA;&#xD;&#xA;Over and above the &apos;minimum&apos; you need a higher -Xmx setting is normally better.  If you have lots of &apos;spare&apos; memory increase the -Xmx setting.  Note that the more you allocate to Java the less will be available to your database server, other applications, and less for Linux to cache your disk reads.&#xD;&#xA;&#xD;&#xA;Whatever you do, you should ensure that the total of the -Xmx settings does not exceed the &apos;spare&apos; memory on your server.  You can figure your &apos;spare&apos; memory by stopping  your Java processes and starting up everything else that is normally running on your server.  When you run free -m it will tell you how much memory you are using.  If you subtract that value from your total memory and then subtract a bit more (for safety) that will be the maximum you should allocate with -Xmx.  e.g. if you have 96MB &apos;spare&apos; then you could allocate 2 -Xmx48m Java processes.  Or 1 -Xmx96m process.&#xD;&#xA;&#xD;&#xA;1.1 Tomcat -Xmx Settings&#xD;&#xA;&#xD;&#xA;We put our -Xmx/-Xms settings for Tomcat in /usr/local/tomcat/bin/setenv.sh in the JAVA_OPTS variable.  We find that -Xmx48 is sufficient to run a minimal Tomcat with the sample webapps installed.&#xD;&#xA;&#xD;&#xA;1.1 Heads Up If You Have a Big/Complex App&#xD;&#xA;&#xD;&#xA;Note that Java can end up using (a lot) more than the -Xmx value worth of memory, since it allocates extra/separate memory for the Java classes it uses.  So the more classes are involved in your application the more memory that Java process will require.&#xD;&#xA;&#xD;&#xA;1.1 Resolving java.lang.OutOfMemoryError: PermGen&#xD;&#xA;&#xD;&#xA;If you get an error like:&#xD;&#xA;java.lang.OutOfMemoryError: PermGen&#xD;&#xA;&#xD;&#xA;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.&#xD;&#xA;&#xD;&#xA;To increase the PermGen space use something like:&#xD;&#xA;&#xD;&#xA;-XX:MaxPermSize=128m&#xD;&#xA;&#xD;&#xA;The default is 64MB.  &#xD;&#xA;&#xD;&#xA;(Note that Xmx is separate from the PermGen space, so increasing Xmx will not help with the PermGen errors).&#xD;&#xA;&#xD;&#xA;The PermGen memory in addition to the Xmx memory.  e.g. Xmx128m &amp; MaxPermSize=128m would use up to 256MB. </s:content>
        <s:mTime>2008-03-24 22:57:42.0</s:mTime>
        <s:cTime>2006-05-04 07:18:50.0</s:cTime>
        <s:comments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
        <s:snipLinks>
            <rdf:Bag>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux'/>
                <rdf:li rdf:resource='#knowledgebase'/>
                <rdf:li rdf:resource='#snipsnap-search'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java/'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/ruby on rails'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/misc/ajax autocomplete'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java/liferay install on tomcat 5.5'/>
                <rdf:li rdf:resource='#snipsnap-index'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java/alfresco install'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/vps backups'/>
                <rdf:li rdf:resource='#glenn'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/vps setup on dedicated servers'/>
                <rdf:li rdf:resource='#retep'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/webserver/plesk notes'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/postfixadmin on debian sarge'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java/tomcat on plesk'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/postfix notes'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/xen'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/phpmyadmin'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/distros/RHEL 4'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/misc/debootstrap'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/postfix with amavis and mysql'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/rpm based php5.1 install'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/Build php 5.1.6 rpm on RHEL4'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/misc/deprecated'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/Security/Port Knocking'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/mail/mass emailing best practices'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/distros/ubuntu'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/rimuhosting/argh my server was exploited'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java/working with different character encodings'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/miscapplications/webmin'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/networking/monitoring bandwidth usage with vnstat'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/java/Running Tomcat infinitely via Daemontools'/>
                <rdf:li rdf:resource='http://bliki.rimuhosting.com/rdf#knowledgebase/linux/misc/where has my disk space gone'/>
            </rdf:Bag>
        </s:snipLinks>
        <s:attachments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
    </s:Snip>
</rdf:RDF>
