?? jvm-tuning.xtp
字號:
<document><header><product>resin</product><title>JVM Tuning</title><description><p>Better performance in production servers is possible with proper configurationof JVM parameters, particularily those related to memory usage and garbagecollection.</p></description></header><body><summary/><s1 name="memory" title="Heap size"><p>The allocation of memory for the JVM is specified using -X options whenstarting Resin (the exact options may depend upon the JVM that you are using,the examples here are for the Sun JVM).</p><deftable><tr> <th>JVM option passed to Resin</th> <th>Meaning</th></tr><tr> <td>-Xms</td> <td>initial java heap size</td></tr><tr> <td>-Xmx</td><td>maximum java heap size</td></tr><tr> <td>-Xmn</td> <td>the size of the heap for the <i>young generation</i></td> </tr> </deftable><example title="Example: resin.xml startup with heap memory options"><resin xmlns="http://caucho.com/ns/resin"><cluster id=""> <server id="" address="127.0.0.1" port="6800"> <jvm-arg>-Xmx500M</jvm-arg> <jvm-arg>-Xms500M</jvm-arg> <jvm-arg>-Xmn100M</jvm-arg> <http port="80"/> </server> ...</cluster></resin></example><p>It is good practice with server-side Java applications like Resin to set theminimum <var>-Xms</var> and maximum <var>-Xmx</var> heap sizes to the same value.</p><p>For efficient <a href="#garbage-collection">garbage collection</a>, the<var>-Xmn</var> value should be lower than the <var>-Xmx</var> value.</p><s2 title="Heap size does not determine the amount of memory your process uses"><p>If you monitor your java process with an OS tool like top or taskmanager,you may see the amount of memory you use exceed the amount you have specifiedfor -Xmx. -Xmx limits the java heap size, java will allocate memory for otherthings, including a stack for each thread. It is not unusual for the totalmemory consumption of the VM to exceed the value of -Xmx.</p></s2></s1> <!-- memory --><s1 name="garbage-collection" title="Garbage collection"><p>(thanks to Rob Lockstone for his comments)</p> <p>There are essentially two GC threads running. One is a very lightweightthread which does "little" collections primarily on the Eden (a.k.a.Young) generation of the heap. The other is the Full GC thread whichtraverses the entire heap when there is not enough memory left toallocate space for objects which get promoted from the Eden to theolder generation(s).</p><p>If there is a memory leak or inadequate heap allocated, eventually the oldergeneration will start to run out of room causing the Full GC thread to run(nearly) continuously. Since this process "stops the world", Resin won't beable to respond to requests and they'll start to back up.</p><p>The amount allocated for the Eden generation is the value specified with<var>-Xmn</var>. The amount allocated for the older generation is the value of<var>-Xmx</var> minus the <var>-Xmn</var>. Generally, you don't want the Eden to betoo big or it will take too long for the GC to look through it for space thatcan be reclaimed.</p><p>See also:</p><ul><li><a href="troubleshoot.xtp#garbage-collector">Troubleshooting Technique: Garbage Collector</a></li><li><a href="http://java.sun.com/docs/hotspot/gc1.4.2/">Sun documentation on garbage collection</a></li></ul></s1> <!-- garbage-collection --><s1 name="stack-size" title="Stack size"><p>Each thread in the VM get's a stack. The stack size will limit the number ofthreads that you can have, too big of a stack size and you will run out ofmemory as each thread is allocated more memory than it needs.</p><p>The Resin startup scripts (resin.exe on Windows, resin.sh on Unix) will setthe stack size to 2048k, unless it is specified explicity. 2048k is anappropriate value for most situations. </p><deftable title="Stack configuration"><tr> <th><jvm-arg></th> <th>Meaning</th></tr><tr> <td>-Xss</td> <td>the stack size for each thread</td></tr></deftable><p><code>-Xss</code> determines the size of the stack: <code>-Xss1024k</code>.If the stack space is too small, eventually you will see an exception <a href="javadoc|java.lang.StackOverflowError|"/>.</p><p>Some people have reported that it is necessary to change stack size settingsat the OS level for Linux. A call to <code>ulimit</code> may be necessary, andis usually done with a command in /etc/profile:</p><example title="Limit thread stack size on Linux">unix> ulimit -s 2048</example></s1><s1 name="monitor" title="Monitoring the JVM"><p>JDK 5 includes a number of tools that are useful for monitoring the JVM.Documentation for these tools is available from the<a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/index.html#manage">Sunwebsite</a>. For JDK's prior to 5, Sun provides the<a href="http://developer.sun.com/dev/coolstuff/jvmstat">jvmstat tools</a>.</p><p>The most useful tool is <var>jconsole</var>. Details on using jconsole areprovided in the <a href="jmx.xtp#console">Administration</a> section of theResin documentation.</p><example title="Example: jconsole configuration"><resin xmlns="http://caucho.com/ns/resin"><cluster id=""> <server-default> <jvm-arg>-Dcom.sun.management.jmxremote</jvm-arg> </server-default> <server id="" address="127.0.0.1" port="6800"/> ...</cluster> </resin></example><example title="Example: jconsole launching"><i> ... in another shell window ... </i>win> jconsole.exeunix> jconsole<i>Choose Resin's JVM from the "Local" list.</i></example><p><var>jps</var> and <var>jstack</var> are also useful, providing a quick command linemethod for obtaining stack traces of all current threads.Details on obtaining and interpreting stack traces is in the<a href="troubleshoot.xtp#thread-dump">Troubleshooting</a>section of the Resin documentation.</p><example title="jps and jstack"><b># jps</b>12903 Jps20087 Resin<b># jstack 20087</b>Attaching to process ID 20087, please wait...Debugger attached successfully.Client compiler detected.JVM version is 1.5.0-beta2-b51Thread 12691: (state = BLOCKED) - java.lang.Object.wait(long) (Compiled frame; information may be imprecise) - com.caucho.util.ThreadPool.runTasks() @bci=111, line=474 (Compiled frame) - com.caucho.util.ThreadPool.run() @bci=85, line=423 (Interpreted frame) - java.lang.Thread.run() @bci=11, line=595 (Interpreted frame)Thread 12689: (state = BLOCKED) - java.lang.Object.wait(long) (Compiled frame; information may be imprecise) - com.caucho.util.ThreadPool.runTasks() @bci=111, line=474 (Compiled frame) - com.caucho.util.ThreadPool.run() @bci=85, line=423 (Interpreted frame) - java.lang.Thread.run() @bci=11, line=595 (Interpreted frame)...</example></s1></body></document>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -