`
wataxi
  • 浏览: 202221 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

(转)resin优化经验

阅读更多

Resin Threads
Resin will automatically allocate and free threads as the load requires. Since the threads are pooled, Resin can reuse old threads without the performance penalty of creating and destroying the threads. When the load drops, Resin will slowly decrease the number of threads in the pool until is matches the load.
Most users can set thread-max to something large (200 or greater) and then forget about the threading. Some ISPs dedicate a JVM per user and have many JVMs on the same machine. In that case, it may make sense to reduce the thread-max to throttle the requests.
Since each servlet request gets its own thread, thread-max determines the maximum number of concurrent users. So if you have a peak of 100 users with slow modems downloading a large file, you'll need a thread-max of at least 100. The number of concurrent users is unrelated to the number of active sessions. Unless the user is actively downloading, he doesn't need a thread (except for "keepalives").
Keepalives
Keepalives make HTTP and srun requests more efficient. Connecting to a TCP server is relatively expensive. The client and server need to send several packets back and forth to establish the connection before the first data can go through. HTTP/1.1 introduced a protocol to keep the connection open for more requests. The srun protocol between Resin and the web server plugin also uses keepalives. By keeping the connection open for following requests, Resin can improve performance.
resin.conf for thread-keepalive
<resin ...>
  <thread-pool>
    <thread-max>250</thread-max>
  </thread-pool>

  <server>
    <keepalive-max>500</keepalive-max>
    <keepalive-timeout>120s</keepalive-timeout>
    ...
Timeouts

Requests and keepalive connections can only be idle for a limited time before Resin closes them. Each connection has a read timeout, request-timeout. If the client doesn't send a request within the timeout, Resin will close the TCP socket. The timeout prevents idle clients from hogging Resin resources.
...
<thread-pool>
  <thread-max>250</thread-max>
</thread-pool>

<server>

   <http port="8080" read-timeout="30s" write-timeout="30s"/>

...
...
<thread-max>250</thread-max>

<server>

   <cluster>
     <client-live-time>20s</client-live-time>

     <srun id="a" port="6802" read-timeout="30s"/>
   </cluster>

...
In general, the read-timeout and keepalives are less important for Resin standalone configurations than Apache/IIS/srun configurations. Very heavy traffic sites may want to reduce the timeout for Resin standalone.
Since read-timeout will close srun connections, its setting needs to take into consideration the client-live-time setting for mod_caucho or isapi_srun. client-live-time is the time the plugin will keep a connection open. read-timeout must always be larger than client-live-time, otherwise the plugin will try to reuse a closed socket.
Plugin keepalives (mod_caucho/isapi_srun)

The web server plugin, mod_caucho, needs configuration for its keepalive handling because requests are handled differently in the web server. Until the web server sends a request to Resin, it can't tell if Resin has closed the other end of the socket. If the JVM has restarted or if closed the socket because of read-timeout, mod_caucho will not know about the closed socket. So mod_caucho needs to know how long to consider a connection reusable before closing it. client-live-time tells the plugin how long it should consider a socket usable.
Because the plugin isn't signalled when Resin closes the socket, the socket will remain half-closed until the next web server request. A netstat will show that as a bunch of sockets in the FIN_WAIT_2 state. With Apache, there doesn't appear to be a good way around this. If these become a problem, you can increase read-timeout and client-live-time so the JVM won't close the keepalive connections as fast.
unix> netstat
...
localhost.32823      localhost.6802       32768      0 32768      0 CLOSE_WAIT
localhost.6802       localhost.32823      32768      0 32768      0 FIN_WAIT_2
localhost.32824      localhost.6802       32768      0 32768      0 CLOSE_WAIT
localhost.6802       localhost.32824      32768      0 32768      0 FIN_WAIT_2
...
TCP limits (TIME_WAIT)

A client and a server that open a large number of TCP connections can run into operating system/TCP limits. If mod_caucho isn't configured properly, it can use too many connections to Resin. When the limit is reached, mod_caucho will report "can't connect" errors until a timeout is reached. Load testing or benchmarking can run into the same limits, causing apparent connection failures even though the Resin process is running fine.
The TCP limit is the TIME_WAIT timeout. When the TCP socket closes, the side starting the close puts the socket into the TIME_WAIT state. A netstat will short the sockets in the TIME_WAIT state. The following shows an example of the TIME_WAIT sockets generated while benchmarking. Each client connection has a unique ephemeral port and the server always uses its public port:
Typical Benchmarking Netstat
unix> netstat
...
tcp   0   0 localhost:25033  localhost:8080  TIME_WAIT  
tcp   0   0 localhost:25032  localhost:8080  TIME_WAIT  
tcp   0   0 localhost:25031  localhost:8080  TIME_WAIT  
tcp   0   0 localhost:25030  localhost:8080  TIME_WAIT  
tcp   0   0 localhost:25029  localhost:8080  TIME_WAIT  
tcp   0   0 localhost:25028  localhost:8080  TIME_WAIT
...
The socket will remain in the TIME_WAIT state for a system-dependent time, generally 120 seconds, but usually configurable. Since there are less than 32k ephemeral socket available to the client, the client will eventually run out and start seeing connection failures. On some operating systems, including RedHat Linux, the default limit is only 4k sockets. The full 32k sockets with a 120 second timeout limits the number of connections to about 250 connections per second.
If mod_caucho or isapi_srun are misconfigured, they can use too many connections and run into the TIME_WAIT limits. Using keepalives effectively avoids this problem. Since keepalive connections are reused, they won't go into the TIME_WAIT state until they're finally closed. A site can maximize the keepalives by setting thread-keepalive large and setting live-time and request-timeout to large values. thread-keepalive limits the maximum number of keepalive connections. live-time and request-timeout will configure how long the connection will be reused.
Configuration for a medium-loaded Apache
...
<thread-pool>
  <thread-max>250</thread-max>
</thread-pool>

<server>
  <keepalive-max>250</keepalive-max>
  <keepalive-timeout>120s</keepalive-timeout>

  <cluster>
    <client-live-time>120s</client-live-time>

    <srun id="a" port="6802" read-timeout="120s"/>
  </cluster>
...
read-timeout must always be larger than client-live-time. In addition, keepalive-max should be larger than the maximum number of Apache processes.
Apache 1.3 issues

Using Apache as a web server on Unix introduces a number of issues because Apache uses a process model instead of a threading model. The Apache processes don't share the keepalive srun connections. Each process has its own connection to Resin. In contrast, IIS uses a threaded model so it can share Resin connections between the threads. The Apache process model means Apache needs more connections to Resin than a threaded model would.
In other words, the keepalive and TIME_WAIT issues mentioned above are particularly important for Apache web servers. It's a good idea to use netstat to check that a loaded Apache web server isn't running out of keepalive connections and running into TIME_WAIT problems.


先将resin.conf文件中的thread-min,thread-max,thread-keepalive三个参数设置的比较大,分别写上,1000,3000,1000,当然这是根据你的机器情况和可能同时访问的数量决定的,如果你的网站访问量很大的,应该再适当放大。
然后观察任务管理器中的java线程变化情况,看看到底是线程达到多大的时候,java进程当掉的。我的是在379左右当掉。
然后将thread-min,thread-max,thread-keepalive分别写为150,400,300;,也就是将当掉的时候的最大值稍微放大点,作为thread-max的值,因为该系统一般不会超过这个值。然后其他两个参数根据情况设置一下。
这只是我的估计值,根据机器性能和访问量不同,应该有所不同。
然后将accept-buffer-size值设置的较大,我设置到10000以上,这样可以让java能使用到更多的内存资源。
这样的设置基本上能够满足resin的正常运行,当掉resin服务的情况大大减少,本设置适合于中小型网站。
Resin优化:

The allocation of memory for the JVM is specified using -X options when starting Resin

(the exact options may depend upon the JVM that you are using, the examples here are for the Sun 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

Resin startup with heap memory options unix> bin/httpd.sh -Xmn100M -Xms500M -Xmx500M win> bin/httpd.exe -Xmn100M -Xms500M -Xmx500M install win service> bin/httpd.exe -Xmn100M -Xms500M -Xmx500M -install

原文:http://www.caucho.com/resin-3.0/performance/jvm-tuning.xtp


JVM 优化:

java -Xms<size>
set initial Java heap size. default:Xms32m
java -Xmx<size>
set maximum Java heap size. default:Xmx128m

set it like that:

java -Xms=32m -Xmx=256m
If the problem persist, increase Xmx more than 256 ( 512m for example )

-J-mx<num>
分享到:
评论

相关推荐

    resin 优化

    resin jvm性能优化 一、优化配置  修改 conf/resin.conf 文章中的 JVM参数 &lt;jvm-arg&gt;-Xms512m &lt;jvm-arg&gt;-Xss128k &lt;jvm-arg&gt;-Xmn184m &lt;jvm-arg&gt;-XX:ParallelGCThreads=20 &lt;jvm-arg&gt;-XX:+UseConcMarkSweepGC ...

    resin2优化-命令配置优化服务器

    resin2优化2008/07/24 00:391. Resin启动时通过bin目录下的wrapper.pl文件进行控制,我们可以修改这个文件来加一些参数,比如要加入Java的-Xms和-Xmx参数

    泛微OA安装resin服务

    可直接双击运行,如安装失败,请右击,以系统管理员身份运行。

    resin_3.1中文配置手册.doc

    resin_3.1中文配置 手册很详细 要学习的朋友可以了解一下

    resin-jvm 调优

    在充分理解了垃圾收集算法和执行过程后,才能有效的优化它的性能。有些垃圾收集专用于特殊的应用程序。比如,实时应用程序主要是为了避免垃圾收集中断,而大多数OLTP应用程序则注重整体效率。理解了应用程序的工作...

    Linux运维从入门到高级全套案例v3.rar

    5.3.4 Resin性能优化…… 5.3.5 Resin多实例配置…… 5.4 Nginx Tomcat动静分离…… 5.5 LNAMP高性能架构配置……… 5.6构建DNS域名解析服务器 5.7 MySQL主从高可用架构… 5.8Ls+ Keepalived负载均衡

    Linux运维从入门到高级全套案例v3

    5.3. 4 Resin性能优化 88 5.3. 5 Resin多实例配置 89 5. 4 Nginx Tomcat动静分离 90 5. 5 LNAMP高性能架构配置 92 5. 6 构建DNS域名解析服务器 99 5. 7 MySQL主从高可用架构 102 5. 8 LVS+Keepalived负载均衡 110 5....

    Helloer企业级论坛系统 v1.8.0.rar

    3. 进一步优化软件构架,优化设计,优化资源利用,相比Helloer 1.0.0速度更快,更省资源! 4. 另外加强了Helloer后台管理系统的功能性和操作性. 5. 大力度更新论坛模板,更简洁美观! Helloer是目前全球用户体验最优秀...

    Helloer企业级JSP论坛系统 v1.8

    3. 进一步优化软件构架,优化设计,优化资源利用,相比Helloer 1.0.0速度更快,更省资源! 4. 另外加强了Helloer后台管理系统的功能性和操作性. 5. 大力度更新论坛模板,更简洁美观! Helloer是目前全球用户体验最优秀的...

    JspRun!社区论坛系统 v6.0 bulid 090423 GBK 源码版.rar

    开发组具有丰富的 web 应用程序设计经验,尤其在论坛产品及相关领域,经过长期创新性开发,掌握了一整套从算法,数据结构到产品安全性方面的领先技术。使得 JspRun! 无论在稳定性,负载能力,安全保障等方面都居于...

    JspRun!社区论坛系统 v6.0 bulid 090424 GBK 安装版.rar

    开发组具有丰富的 web 应用程序设计经验,尤其在论坛产品及相关领域,经过长期创新性开发,掌握了一整套从算法,数据结构到产品安全性方面的领先技术。使得 JspRun! 无论在稳定性,负载能力,安全保障等方面都居于...

    Module Framework Design 2008(模块化开发框架)

    帮助企业快速设计应用系统,集成了日志、联接池、性能优化、权限控制、数据展现,常规模块功能(增加、删除、修改、查询、导出、排序)实现,采用JAVA语言编写,可以应用于JBoss,WebLogic,Tomcat ,Resin,WebSphere...

    轻松学会Linux入门教程.txt

    8-MYSQL数据库主从&架构优化,数据优化很重要.mp4 9-MYSQL读写分离8分库分表,让主管刮目相看!.mp4 10-秒杀必备之Redis企业实战,99%的人都不会的技巧!.mp4 11-Redis主从8Cluster集群实战.mp4 12-SHELL编程基础...

    【白雪红叶】JAVA学习技术栈梳理思维导图.xmind

    resin jetty 容灾 日志框架 开源框架 slf4j 框架实现 log4j logback commong logging jdk logger 测试框架 测试框架 junit easymock testng mockito bug管理 禅道 jira 开发工具 编程工具 ...

    JEECMS v2.2 beta 贺岁版

    在设计上自身预先做了搜索引擎优化,增强对搜索引擎的友好性 采用伪静态页面技术,可自定义路径结构,无需urlrewrite 轻松建设大规模网站,可通过次级域名建立子站群,各子站后台管理权限分离,全站实现单点登录 ...

    php_xmlhttp 乱码问题解决方法

    于是将自己的一个php站点直接放resin里面做开发了,总体感觉还不错,基本功能没发现问题,但在继续优化过程中,想到了xmlhttp,便随手写了几个文件试一下,无刷新效果嘛,可是竟然遇到了中文乱码,于是五一一天就...

    解决nginx/apache静态资源跨域访问问题详解

    有时为了优化网站访问速度,会给一些静态资源配置cdn加速,但是有时候会出现跨域访问的问题,在nginx和apache服务中可进行如下配置

    JSP程序员成长手册

    能使用此技术实现软件需求并有经验的积累在实现之前能做优化设计尽可能的实现模块或代码的重用。 熟悉:能够掌握此技术的50%技术要点以上,使用此技术时间超过半年上,并使用此技术成功实施1个以上的项目。能使用此...

    TurboShopV3.0(企业级免费JAVA商城)

    修正删除新闻主题没有删除其下新闻 修正访问统计关键词分析没有显示关键词 修正resin3访问页面第二次出现乱码的问题 修正查看最新商品按评论统计不正确 修正连续上传图片,没有删除旧图,造成冗余...

    脉冲磁控溅射制备树脂镜片红外防护功能薄膜

    选取氮化硅和二氧化硅作为薄膜材料,借助膜系设计软件对膜系结构进行优化,采用中频脉冲磁控溅射技术进行薄膜制备。利用高反膜透射曲线拟合方法调整薄膜的实际沉积速率,减少膜厚控制误差,在树脂镜片CR39基底的凸面...

Global site tag (gtag.js) - Google Analytics