在resin.conf中设置最大值 threadmax

<!--S 头部开始-->

在resin.conf中设置最大值 threadmax

2007年11月07日 评论(0)|浏览(7) 点击查看原文

以下方案我是在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映射

1

2

3

4

 

<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 = 65000;

 

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)

 

 

> 在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

1

 

ulimit -s 2048

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

你可能感兴趣的:(thread,Web,linux,servlet,JBuilder)