Resin 4.0.15配置優化

早先說過線上Resin的配置文件中要增加線程池大小、各種timeout參數(resin 4.0.15的默認配置文件肯定沒有這些參數,需要另行增加)。

在resin 4.0.10裏,有這麼一個bug,thread-max的數量設置沒有起作用

但後面到了resin 4.0.15應該就修復了。

下面內容會給出背景介紹以及建議配置。

1、背景:

要綜合考慮resin線程池大小、“-Xmx :JVM最大可用內存”、“-Xms:初始堆大小”、“-Xmn:Young Generation的heap size”參數互相匹配。(JVM有2個GC線程。第一個線程負責回收Heap的Young區。第二個線程在Heap不足時,遍歷Heap,將Young 區升級爲Older區。Older區的大小等於-Xmx減去-Xmn,不能將-Xms的值設的過大,因爲第二個線程被迫運行會降低JVM的性能。)

來避免線上resin服務反覆出現以下異常:

OutOfMemoryError: Java heap space
OutOfMemoryError: PermGen space

2、Resin.xml就可以設置JDK參數:

Resin 4.0已支持把JDK參數加入resin配置文件resin.xml裏。

參考resin的幫助文檔:

『JDK arguments
Resin 4.0 has moved all JDK arguments into the resin.xml file, in the <jvm-arg> tag. Because the Resin 4.0 watchdog starts each Resin server instance, it can pass the arguments defined in the configuration file to the JVM. By moving the Java arguments to the configuration file, server configuration is easier and more maintainable.

3、建議規則:

1、 Server端JVM最好將-Xms和-Xmx設爲相同值。爲了優化GC,最好讓-Xmn值約等於-Xmx的1/4。

2、 通過增大 “-XX:PermSize”和“-XX:MaxPermSize”這兩個參數來避免出現JVM內存永久保存區域溢出引發Resin的500錯誤。(鄭昀認爲,因爲線上用了spring+struts,這些框架用到大量動態class,ClassLoader是把這部分內存放在PermGen space裏的。而JVM的GC是不會清理PermGen space的。這樣容易導致線上應用報告PermGen space內存溢出。)

4、建議resin配置:

所以,建議線上部署的Resin 4.0.15的resin.xml中增加如下配置節點:

<server-default>

    <jvm-arg>-Xms1024m</jvm-arg>

    <jvm-arg>-Xmx1024m</jvm-arg>

    <jvm-arg>-Xmn256m</jvm-arg>

    <jvm-arg>-XX:PermSize=128m</jvm-arg>

<jvm-arg>-XX:MaxPermSize=256m</jvm-arg>

    <thread-max>1024</thread-max>

    <socket-timeout>30s</socket-timeout>

    <keepalive-max>512</keepalive-max>

    <keepalive-timeout>60s</keepalive-timeout>

</server-default>

5、查看resin 版本

root@pts/3 # cd /usr/local/resin/lib

root@pts/3 # java -classpath ./resin.jar com.caucho.Version
Resin-4.0.35 (built Tue, 12 Feb 2013 10:05:50 PST)
Copyright(c) 1998-2012 Caucho Technology.  All rights reserved.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章