设为首页 收藏本站
查看: 1337|回复: 0

[经验分享] 在resin.conf中设置最大值 threadmax

[复制链接]

尚未签到

发表于 2017-2-20 11:36:18 | 显示全部楼层 |阅读模式
<!--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多个线程。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-344766-1-1.html 上篇帖子: resin下使用jbpm4无法解析配置文件 下篇帖子: resin jboss 最大连接数设置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表