JAVA中文世界论坛|JAVA开发者论坛

在技术版发广告帖一律删除ID,禁IP.

如果发现登录有问题,请用http://bbs.chinajavaworld.com访问.
发帖时包含代码格式请使用 {code}代码内容{code} ,其中每个{code}各占一行。注,原来的ubb代码[code]代码[/code]继续支持。
发表主题时如果选上“标记为问题”,在得到“有帮助的”或“正确的”答案后,请在回帖旁边点“有帮助的”或“正确的”按钮,系统将奖励积分给该回帖的作者。主题作者的信誉值也会增加。除此之外,还可以在发表主题后自已设定奖励积分。
欢迎访问JAVA中文博客频道:http://blog.chinajavaworld.com/

欢迎, 游客
游客设置

论坛主页 » J2EE 应用服务器 技术论坛 » Resin 技术论坛

主题: Resin 3 pro高并发,响应性与稳定性方案

回复主题 回复主题 搜索论坛 搜索论坛 返回主题列表 返回主题列表

链接 回复: 6 - 页数: 1 - 最后发表: 2008-8-27 下午6:11 最后发表: findpie 主题: [ 上一个 | 下一个 ]
anotherbug



发帖: 656
积分: 155
注册: 04-12-23
博客
Resin 3 pro高并发,响应性与稳定性方案
发表于: 2006-10-19 下午9:33
  回复本主题 回复
以下方案我是在Intel xeon(至强) 3.2G 2个双核物理CPU+2G内存(Ecc)上进行:

resin版本为resin-pro-3.0.21,JVM为Jrockit 1.5_06, resin java 启动参数 -Xms256m -Xmx512m

1. 以下为resin.conf配置
<!--
- Resin 3.0 configuration file.
-->
<resin xmlns="http://caucho.com/ns/resin" xmlns:resin="http://caucho.com/ns/resin/core">
<!--
- Logging configuration for the JDK logging API.
-->
<log name="" level="all" path="stdout:" timestamp="[%H:%M:%S.%s] "/>

<logger name="com.caucho.java" level="config"/>
<logger name="com.caucho.loader" level="config"/>

<dependency-check-interval>600s</dependency-check-interval>

<javac compiler="internal" args=""/>

<thread-pool>
<thread-max>10240</thread-max>
<spare-thread-min>50</spare-thread-min>
</thread-pool>

<min-free-memory>5M</min-free-memory>

<server>
<class-loader>
<tree-loader path="${resin.home}/lib"/>
<tree-loader path="${server.root}/lib"/>
</class-loader>

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

<resin:if test="${resin.isProfessional()}">
<select-manager enable="true"/>
</resin:if>

<bind-ports-after-start/>

<http server-id="" host="*" port="80"/>

<cluster>
<srun server-id="" host="127.0.0.1" port="6802"/>
</cluster>

<resin:if test="${resin.isProfessional()}">
<persistent-store type="cluster">
<init path="session"/>
</persistent-store>
</resin:if>

<ignore-client-disconnect>true</ignore-client-disconnect>

<resin:if test="${isResinProfessional}">
<cache path="cache" memory-size="20M"/>
</resin:if>

<web-app-default>
<class-loader>
<tree-loader path="${server.root}/ext-webapp"/>
</class-loader>

<cache-mapping url-pattern="/" expires="60s"/>
<cache-mapping url-pattern="*.gif" expires="600s"/>
<cache-mapping url-pattern="*.jpg" expires="600s"/>

<servlet servlet-name="directory" servlet-class="com.caucho.servlets.DirectoryServlet">
<init enable="false"/>
</servlet>

<allow-servlet-el/>

<session-config>
<enable-url-rewriting>false</enable-url-rewriting>
</session-config>

</web-app-default>

<host-default>
<class-loader>
<compiling-loader path="webapps/WEB-INF/classes"/>
<library-loader path="webapps/WEB-INF/lib"/>
</class-loader>

<!--access-log path="logs/access.log"
format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"' rollover-period="1W"/-->

<web-app-deploy path="webapps"/>

<ear-deploy path="deploy">
<ear-default>
<!-- Configure this for the ejb server
-
- <ejb-server>
- <config-directory>WEB-INF</config-directory>
- <data-source>jdbc/test</data-source>
- </ejb-server>
-->
</ear-default>
</ear-deploy>

<resource-deploy path="deploy"/>

<web-app-deploy path="deploy"/>
</host-default>

<resin:import path="${resin.home}/conf/app-default.xml"/>

<host-deploy path="hosts">
<host-default>
<resin:import path="host.xml" optional="true"/>
</host-default>
</host-deploy>

<host id="" root-directory=".">
<web-app id="/" document-directory="d:\website\chat">
</web-app>
</host>

</server>
</resin>


2. 在应用的web.xml中加入resin status查看servlet映射

      <servlet-mapping servlet-class='com.caucho.servlets.ResinStatusServlet'>
<url-pattern>/resin-status</url-pattern>
<init enable="read"/>
</servlet-mapping>

3. 启动resin,确认应用正常启动。

4. 写访问测试程序

import java.io.InputStream;
import java.net.URL;

public class TestURL
{ public static void main(String[] args) throws Exception
{ long a = System.currentTimeMillis();
System.out.println("Starting request url:");
for(int i = 0; i < 10000; i++){ URL url = new URL("http://192.168.1.200/main.jsp");

InputStream is = url.openStream();
is.close();
System.out.println("Starting request url:"+i);
} System.out.println("request url end.take "(System.currentTimeMillis()-a)"ms");
}
}


5. 在Jbuilder中执行TestURL

在执行过程中,一边刷新http://192.168.1.200/resin-status,查看resin状态,在http://*:80 中的 Active Threads 和 Total,会一直增长,当长到512的时候不再增长,这时再刷新resin-status页面时,会发现打开很慢。原因是服务器已经达到最大连接数,在等待前面连接的释放而不能接受新的连接。

于是下载Resin 3.0.21源码,搜索 512,发现com.caucho.server.port.Port类中有以下代码:
// default timeout
private long _timeout = 65000L;

private int _connectionMax = 512;//就是这行,查找resin所有源码后,发现没有对这个值进行设置 private int _minSpareConnection = 16;

private int _keepaliveMax = -1;

private int _minSpareListen = 5;
private int _maxSpareListen = 10;
将_connectionMax 改为 20480,然后重新编译并替换resin.jar中的Port类。

6. 重新启动Resin,再次运行TestURL进行测试,这次你会发现Threads Active 和 Total 一直变大,且可以超过512一直增大,在测试程序运行过程中刷新页面,页面响应性能还是不错的.

另,测试过程中Resin会打印出 1-3次 强制执行GC的信息,属于正常。

7.待测试完毕,Threads Active 和 Total 马上降为1.Idle为9,总内存为536.87Meg 空闲内存为480.33M

再经多次测试,结果一致,内存回收正常,表明当前 resin 稳定性和响应性可靠。

本文由 Java开发者(Chinajavaworld.com)享有版权,转载请注明出自 JAVA开发者(http://www.chinajavaworld.com)

ChinaJavaWorld.com | JAVA中文世界...带给你无限可能...
anotherbug



发帖: 656
积分: 155
注册: 04-12-23
博客
Re: Resin 3 pro高响应性与稳定性方案
发表于: 2006-10-19 下午9:58   原文: anotherbug 原文: anotherbug
  回复本主题 回复
附件 resin-status.gif (10.4 KB)
resin-status高负载时状态图

ChinaJavaWorld.com | JAVA中文世界...带给你无限可能...
livedoty


发帖: 16
积分: 100
注册: 06-10-16
博客
Re: Resin 3 pro高响应性与稳定性方案
发表于: 2006-10-20 下午8:50   原文: anotherbug 原文: anotherbug
  回复本主题 回复
强~
顶!

感谢楼主分享~

http://news.163.com/ 也是Resin 3.x的后台,不要被/*/*/???.html 的静态页地址迷惑。
网易买了resin pro的授权!
网易的新闻站点能用Resin做后台,可见Resin 3.x是十分稳定和可靠的!
_
ps:网易的前端有gzip压缩服务器和squid cdn加速服务器,内容过期300s,大站能用动态页面+cache,说明Resin是很强的!
wangwei1998


发帖: 69
积分: 100
注册: 05-3-6
博客
Re: Resin 3 pro高并发,响应性与稳定性方案
发表于: 2006-10-28 下午9:36   原文: anotherbug 原文: anotherbug
  回复本主题 回复
_connectionMax的值不能通过外部设置?
shijiunv


发帖: 3
积分: 100
注册: 05-1-25
博客
Re: Resin 3 pro高并发,响应性与稳定性方案
发表于: 2007-1-5 上午11:25   原文: wangwei1998 原文: wangwei1998
  回复本主题 回复
在resin.conf中设置最大值。

<thread-pool>
<!-- Maximum number of threads. -->
<thread-max>128</thread-max>

<!-- Minimum number of spare connection threads. -->
<spare-thread-min>25</spare-thread-min>
</thread-pool>

需要考虑的是,每个线程需要一个stack。
高压力服务,内存才是瓶颈。
在32位系统中,resin只能使用2G内存。

其实128已经足够用了:)
anotherbug



发帖: 656
积分: 155
注册: 04-12-23
博客
Re: Resin 3 pro高并发,响应性与稳定性方案
发表于: 2007-2-15 上午8:36   原文: shijiunv 原文: shijiunv
  回复本主题 回复
在resin.conf中设置最大值。

hread-pool>
<!-- Maximum number of threads. -->
<thread-max>128</thread-max>

<!-- Minimum number of spare connection threads.
-->
<spare-thread-min>25</spare-thread-min>
/thread-pool>

需要考虑的是,每个线程需要一个stack。
高压力服务,内存才是瓶颈。
在32位系统中,resin只能使用2G内存。

其实128已经足够用了:)

引用Resin的文档

Stack size

Each thread in the VM get's a stack. The stack size will limit the number of threads that you can have, too big of a stack size and you will run out of memory as each thread is allocated more memory than it needs.

The Resin startup scripts (httpd.exe on Windows, wrapper.pl on Unix) will set the stack size to 2048k, unless it is specified explicity. 2048k is an appropriate value for most situations.

JVM option passed to Resin Meaning
-Xss the stack size for each thread

-Xss determines the size of the stack: -Xss1024k. If the stack space is too small, eventually you will see an exception class java.lang.StackOverflowError .

Some people have reported that it is necessary to change stack size settings at the OS level for Linux. A call to ulimit may be necessary, and is usually done with a command in /etc/profile:

Limit thread stack size on Linux

ulimit -s 2048
-Xss=1M可以指定stack为1M,理论上计算128线程就用了128M,但实际上的占用还要少得多,我在2G的内存机器上(经过TCP优化)进行高负载测试,最高跑到了4000多个线程。

ChinaJavaWorld.com | JAVA中文世界...带给你无限可能...
findpie


发帖: 4
积分: 100
注册: 08-8-22
博客
Re: Resin 3 pro高并发,响应性与稳定性方案
发表于: 2008-8-27 下午6:11   原文: anotherbug 原文: anotherbug
  回复本主题 回复
<servlet-mapping servlet-class='com.caucho.servlets.ResinStatusServlet'>
<url-pattern>/resin-status</url-pattern>
<init enable="read"/>
</servlet-mapping>
请问这段总是提示出错,我用的是resin3.0.23测试版,什么原因?

把 RSS 阅读器指向这里读取所有论坛的最新回帖