• resin3的优化配置


    resin3的优化配置

     

    说明: 
    本文是在apache2+resin3(开源版)环境下的配置,主要是对resin3配置进行了分析,详细调试请见caucho-doc ,apache2的调优见apache的man文档。实践总结,如转载请注明出处--2hei.net 谢谢.

      Using Resin(R)  under the GNU Public License (GPL).
      See 
    http://www.caucho.com for information on Resin Professional,
      including caching, clustering, JNI acceleration, and OpenSSL integration.

    resin配置文件:  resin.conf

    1、dependency-check-interval 参数调整
    resin检查系统配置及java、jsp、resin.conf等文件的时间间隔。
    默认值为2秒,适合开发及调试环境,如果是正式环境尽量把参数调大或者直接改为-1,不允许检查,也就是禁止了热部署。
    <dependency-check-interval>-1s</dependency-check-interval>

    2、缓存
    改变cache-mapping的值:
          <cache-mapping url-pattern="/" expires="5s"/>
          <cache-mapping url-pattern="*.gif" expires="60s"/>
          <cache-mapping url-pattern="*.jpg" expires="60s"/>
          <cache-mapping url-pattern="*.png" expires="60s"/>
    3、jvm优化
    jvm需要根据你的系统配置及应用来调整。

    JVM OPTION PASSED TO RESIN     MEANING
    -Xms                           initial java heap size
    -Xmx                           maximum java heap size
    -Xmn                           the size of the heap for the young generation

    将-Xms和-Xmx设置为一样大小是不错的选择。
    如: bin/httpd.sh -Xms500M -Xmx500M -Xmn100M

    更多的关于jvm优化参数如:young generation、Eden generation、older generation可见
    Sun documentation on garbage collection

    jvm的监控,google一下有很多的工具,如:jconsole jstat jstack

    jconsole的使用见我的另外一篇文章 《使用Jconsole对java的内存使用情况(JVM)进行监控

    $jps
    1229 Jps
    1003 Resin
    973 resin.jar

    $jmap 973
    Attaching to process ID 973, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 1.5.0_16-b02
    0x0000000040000000      64K     /home/jdk1.5.0_16/bin/java
    0x00000030b2a00000      127K    /lib64/ld-2.5.so
    0x00000030b2e00000      1647K   /lib64/libc-2.5.so
    0x00000030b3200000      22K     /lib64/libdl-2.5.so
    0x00000030b3600000      600K    /lib64/libm-2.5.so
    0x00000030b3a00000      138K    /lib64/libpthread-2.5.so
    0x00000030b5a00000      111K    /lib64/libnsl-2.5.so
    0x00002aaab46ad000      26K     /home/jdk1.5.0_16/jre/lib/amd64/libmanagement.so
    0x00002aaab49de000      79K     /home/jdk1.5.0_16/jre/lib/amd64/libnet.so
    0x00002aeeac3c1000      9933K   /home/jdk1.5.0_16/jre/lib/amd64/server/libjvm.so
    0x00002aeeacd46000      43K     /home/jdk1.5.0_16/jre/lib/amd64/native_threads/libhpi.so
    0x00002aeeace61000      52K     /lib64/libnss_files-2.5.so
    0x00002aeead06c000      58K     /home/jdk1.5.0_16/jre/lib/amd64/libverify.so
    0x00002aeead17b000      171K    /home/jdk1.5.0_16/jre/lib/amd64/libjava.so
    0x00002aeead2a5000      78K     /home/jdk1.5.0_16/jre/lib/amd64/libzip.so

    jstat -gc 1489 1000 3
     S0C    S1C    S0U    S1U      EC       EU        OC         OU         PC     PU        YGC     YGCT  FGC     FGCT     GCT   
    43648.0 43648.0  0.0    0.0   262208.0 101390.5  699072.0   18545.6   28032.0 15756.6      1    0.055   1      0.115    0.170
    43648.0 43648.0  0.0    0.0   262208.0 101390.5  699072.0   18545.6   28032.0 15756.6      1    0.055   1      0.115    0.170
    43648.0 43648.0  0.0    0.0   262208.0 101390.5  699072.0   18545.6   28032.0 15756.6      1    0.055   1      0.115    0.170

    jstack 1489
    Thread 1495: (state = BLOCKED)
     - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
     - java.lang.Object.wait() @bci=2, line=474 (Interpreted frame)
     - java.lang.ref.Reference$ReferenceHandler.run() @bci=46, line=116 (Interpreted frame)

    Thread 1489: (state = IN_NATIVE)
     - java.net.SocketInputStream.socketRead0(java.io.FileDescriptor, byte[], int, int, int) @bci=0 (Interpreted frame)
     - java.net.SocketInputStream.read(byte[], int, int) @bci=84, line=129 (Interpreted frame)
     - java.net.SocketInputStream.read() @bci=23, line=182 (Interpreted frame)
     - com.caucho.server.resin.Resin.waitForExit() @bci=304, line=1265 (Interpreted frame)
     - com.caucho.server.resin.Resin.main(java.lang.String[]) @bci=42, line=1367 (Interpreted frame)
     

    4、JNI加速
    resin不使用NIO而是使用了JNI的方式使用本地码的方式来提升效率,经验证,resin使用JNI的效率要高于使用NIO,
    使用JNI是需要对resin进行编译,在./configure时把jni编译进去,

    ./configure --enable-jni      美中不足的是Resin Professional版本才提供此项功能。

    下面是resin-doc的说明:
    Resin does not use NIO - it uses JNI to handle low-level I/O calls with native code. The performance using this method was found to be much better than nio.

    5、jsp第一次编译的处理
    一般来讲,第一次访问jsp会自动进行编译,如果更新了过多的jsp、且系统访问很大的话,重启resin容易造成负载过高。

    下面配置是启动app-server时,对所有的jsp进行编译,编译完毕后启动监听,这样启动时间会长一些,但是可以防止第一次访问编译造成系统负载大。
          <listener>
            <listener-class>com.caucho.jsp.JspPrecompileListener</listener-class>
            <init>
              <extension>jsp</extension>
              <extension>jspx</extension>
            </init>
          </listener>
    6、resin 与apache 性能的比较
    resin3单独使用时性能也是不错,当然也可以跟apache配合使用。下面是resin-doc中的说法:
    For JSP and Servlets, Resin standalone is certainly faster than Resin/Apache. Because of the extra overhead of the Resin/Apache connection, the Resin/Apache configuration is necessarily slower than Resin standalone.
    可以看出各有优劣,
    apache对于静态页面来说比较快。如果使用了SSL,apache+resin要比resin单独使用快一些,更为重要的是resin3的开源版本不支持ssl。

    7resin-server TIME_WAIT 过多的处理
    thread-max指定了最大连接数,socket-timeout是socket超时时间
    keepalive-max指定了长连接的数量,这是可以重复使用的连接,netstat -an时系统可以看到响应数量的ESTABLISHED状态
    设定keepalive-max和把keepalive-timeout调小可以减少TIME_WAIT的数量。
          <thread-max>256</thread-max>
          <socket-timeout>65s</socket-timeout>
          <keepalive-max>128</keepalive-max>
          <keepalive-timeout>120s</keepalive-timeout>
    一般来讲如果是Resin standalone方式,调整timeout并不是很重要,如果是apache+resin的方式,而且apache压力很大的情况下,需要调小timeout的值。
    load-balance-idle-time是用来设置load-balance和分布式session的关闭时间,默认时间为keepalive-timeout - 1s
    <load-balance-idle-time>100s</load-balance-idle-time>

    8、关于watchdog
    resin3启动是多了一个watchdog的进程。可以单独启动也可以跟随resin.jar一起启动,主要是用来监控resin jvm实例,在必要的时候重启。

    <watchdog-jvm-arg>-Dcom.sun.management.jmxremote</watchdog-jvm-arg>
    <watchdog-port>6600</watchdog-port>

    查看  watchdog  状态    
    java -jar lib/resin.jar status
    Resin/3.1.6 status for watchdog at 127.0.0.1:6600

    server '' : active
      password: missing
      user: root
      root: /home/resin/
      conf: /home/resin/conf/resin.conf

    来源:http://www.2hei.net/mt/2008/11/resin3-tuning.html

  • 相关阅读:
    linux下网络排错与查看
    linux下判断网络是否连接
    Linux 下操作gpio(两种方法,驱动和mmap)
    Kernel 中的 GPIO 定义和控制
    springboot jpa 解决延迟加载问题
    Hibernate @OneToOne懒加载实现解决方案
    Hibernate缓存和懒加载的坑你知道多少?这5个简单问题回答不上来就不敢说会用hibernate
    Spring Boot JPA 懒加载
    Spring Boot中使用Spring-data-jpa让数据访问更简单、更优雅
    Spring Data Jpa 详解 (配置篇)
  • 原文地址:https://www.cnblogs.com/momofan/p/2636184.html
Copyright © 2020-2023  润新知