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

[经验分享] tomcat 优化到每秒并发1000

[复制链接]

尚未签到

发表于 2017-1-30 15:14:06 | 显示全部楼层 |阅读模式
现在系统部署只能达到240+ , tomcat + apache 也只能到 900 + ,看到robbin的发帖能达到1000 ,不知道该如何配置,特来请教:

http://www.iteye.com/post/370111?page=8







robbin 写道

既然你用tomcat4都可以达到并发600,那tomcat5.5在同样环境下经过调优完全可以达到1000,看来问题还是在于你们tomcat没有配置好。
  附带环境配置如下:
  环境配置如下: (jdk没有用 -server)

Java代码 DSC0000.gif





  • windows2003企业版sp2


  • Intel(R)Xeon(R)4CPU5130@2.0GHz4.00GB内存


  • apache_2.2.8-win32-x86


  • mod_jk-apache-2.0.59

  • jdk-1_5_0_14-windows-i586-p.exe-client


  • Tomcat-6.0.16+apr



windows 2003 企业版 sp2
Intel(R) Xeon(R) 4 CPU 5130 @ 2.0GHz 4.00GB 内存
apache_2.2.8-win32-x86
mod_jk-apache-2.0.59
jdk-1_5_0_14-windows-i586-p.exe -client
Tomcat-6.0.16 + apr

  server.xml

Xml代码





  • <Executorname="tomcatThreadPool"namePrefix="catalina-exec-"maxThreads="2000"minSpareThreads="1000"/>



  • <Connectorport="8080"protocol="HTTP/1.1"

  • connectionTimeout="2000"

  • redirectPort="8443"enableLookups="false"

  • acceptCount="5000"maxThreads="2000"/>




<Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="2000" minSpareThreads="1000"/>

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="2000"
redirectPort="8443"  enableLookups="false"
acceptCount="5000" maxThreads="2000"/>
  catalina.bat

Java代码





  • setJAVA_OPTS=-Xms1400m-Xmx1400m-Djava.awt.headless=true



set JAVA_OPTS=-Xms1400m -Xmx1400m -Djava.awt.headless=true
  index.jsp (除了下面这些代码,还有200行html代码,没有一个图片)

Java代码





  • <%

  • for(inti=0;i<1000;i++){

  • request.setAttribute("key_"+i,"value_"+i);
  • }



  • for(inti=0;i<100;i++){

  • request.getSession().setAttribute("key_"+i,"value_"+i);
  • }
  • %>
  • <br/>

  • <%=request.getSession().getAttribute("key_0")%>

  • <%=request.getSession().getAttribute("key_0")%>

  • <%=request.getSession().getAttribute("key_0")%>

  • <%=request.getSession().getAttribute("key_0")%>

  • <%=request.getSession().getAttribute("key_0")%>

  • <%=request.getSession().getAttribute("key_0")%>



<%
for(int i=0;i<1000;i++){
request.setAttribute("key_"+i,"value_"+i);
}

for(int i=0;i<100;i++){
request.getSession().setAttribute("key_"+i,"value_"+i);
}
%>
<br />
<%=request.getSession().getAttribute("key_0")%>
<%=request.getSession().getAttribute("key_0")%>
<%=request.getSession().getAttribute("key_0")%>
<%=request.getSession().getAttribute("key_0")%>
<%=request.getSession().getAttribute("key_0")%>
<%=request.getSession().getAttribute("key_0")%>
  tomat 启动信息如下:

Java代码





  • 2008-5-617:54:52org.apache.catalina.core.AprLifecycleListenerinit

  • 信息:LoadedAPRbasedApacheTomcatNativelibrary1.1.10.

  • 2008-5-617:54:52org.apache.catalina.core.AprLifecycleListenerinit

  • 信息:APRcapabilities:IPv6[false],sendfile[true],acceptfilters[false],r

  • andom[true].

  • 2008-5-617:54:52org.apache.coyote.http11.Http11AprProtocolinit

  • 信息:InitializingCoyoteHTTP/1.1onhttp-8080

  • 2008-5-617:54:52org.apache.coyote.ajp.AjpAprProtocolinit

  • 信息:InitializingCoyoteAJP/1.3onajp-30008

  • 2008-5-617:54:52org.apache.catalina.startup.Catalinaload

  • 信息:Initializationprocessedin973ms

  • 2008-5-617:54:52org.apache.catalina.core.StandardServicestart
  • 信息:StartingserviceCatalina

  • 2008-5-617:54:52org.apache.catalina.core.StandardEnginestart

  • 信息:StartingServletEngine:ApacheTomcat/6.0.16

  • 2008-5-617:54:52org.apache.coyote.http11.Http11AprProtocolstart

  • 信息:StartingCoyoteHTTP/1.1onhttp-8080

  • 2008-5-617:54:53org.apache.coyote.ajp.AjpAprProtocolstart

  • 信息:StartingCoyoteAJP/1.3onajp-30008

  • 2008-5-617:54:53org.apache.catalina.startup.Catalinastart

  • 信息:Serverstartupin310ms



2008-5-6 17:54:52 org.apache.catalina.core.AprLifecycleListener init
信息: Loaded APR based Apache Tomcat Native library 1.1.10.
2008-5-6 17:54:52 org.apache.catalina.core.AprLifecycleListener init
信息: APR capabilities: IPv6 [false], sendfile [true], accept filters [false], r
andom [true].
2008-5-6 17:54:52 org.apache.coyote.http11.Http11AprProtocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2008-5-6 17:54:52 org.apache.coyote.ajp.AjpAprProtocol init
信息: Initializing Coyote AJP/1.3 on ajp-30008
2008-5-6 17:54:52 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 973 ms
2008-5-6 17:54:52 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2008-5-6 17:54:52 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.16
2008-5-6 17:54:52 org.apache.coyote.http11.Http11AprProtocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2008-5-6 17:54:53 org.apache.coyote.ajp.AjpAprProtocol start
信息: Starting Coyote AJP/1.3 on ajp-30008
2008-5-6 17:54:53 org.apache.catalina.startup.Catalina start
信息: Server startup in 310 ms

  -----------------------------------------------------------------------------------------
  下面是测试结果:
  tomcat + apache 测试结果:

Java代码





  • D:\Apache2.2\bin>ab-n10000-c800http://127.0.0.1/index.jsp


  • ServerSoftware:Apache/2.2.4

  • ServerHostname:127.0.0.1

  • ServerPort:80

  • DocumentPath:/index.jsp

  • DocumentLength:41078bytes


  • ConcurrencyLevel:800

  • Timetakenfortests:34.46875seconds

  • Completerequests:10000

  • Failedrequests:0

  • Writeerrors:0

  • Totaltransferred:413090000bytes

  • HTMLtransferred:410780000bytes

  • Requestspersecond:293.71[#/sec](mean)

  • Timeperrequest:2723.750[ms](mean)

  • Timeperrequest:3.405[ms](mean,acrossallconcurrentrequests)

  • Transferrate:11848.61[Kbytes/sec]received

  • ConnectionTimes(ms)
  • minmean[+/-sd]medianmax

  • Connect:001.8015

  • Processing:1520343425.192123265

  • Waiting:020253423.892123250

  • Total:1520343425.192123265

  • Percentageoftherequestsservedwithinacertaintime(ms)

  • 50%921

  • 66%1343

  • 75%1656

  • 80%1875

  • 90%5078

  • 95%9421

  • 98%15828

  • 99%18171

  • 100%23265(longestrequest)


  • D:\Apache2.2\bin>ab-n10000-c1000http://127.0.0.1/index.jsp


  • ServerSoftware:Apache/2.2.4

  • ServerHostname:127.0.0.1

  • ServerPort:80

  • DocumentPath:/index.jsp

  • DocumentLength:323bytes


  • ConcurrencyLevel:1000

  • Timetakenfortests:24.265625seconds

  • Completerequests:10000

  • Failedrequests:3953

  • (Connect:0,Length:3953,Exceptions:0)

  • Writeerrors:0

  • Non-2xxresponses:8686

  • Totaltransferred:58651479bytes

  • HTMLtransferred:56541921bytes

  • Requestspersecond:412.11[#/sec](mean)

  • Timeperrequest:2426.563[ms](mean)

  • Timeperrequest:2.427[ms](mean,acrossallconcurrentrequests)

  • Transferrate:2360.38[Kbytes/sec]received

  • ConnectionTimes(ms)
  • minmean[+/-sd]medianmax

  • Connect:001.7015

  • Processing:015734416.43123984

  • Waiting:015634402.53123984

  • Total:015734416.53123984

  • Percentageoftherequestsservedwithinacertaintime(ms)

  • 50%31

  • 66%62

  • 75%62

  • 80%62

  • 90%7031

  • 95%13234

  • 98%18218

  • 99%19859

  • 100%23984(longestrequest)



D:\Apache2.2\bin>ab -n 10000 -c 800 http://127.0.0.1/index.jsp
Server Software:        Apache/2.2.4
Server Hostname:        127.0.0.1
Server Port:            80
Document Path:          /index.jsp
Document Length:        41078 bytes
Concurrency Level:      800
Time taken for tests:   34.46875 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      413090000 bytes
HTML transferred:       410780000 bytes
Requests per second:    293.71 [#/sec] (mean)
Time per request:       2723.750 [ms] (mean)
Time per request:       3.405 [ms] (mean, across all concurrent requests)
Transfer rate:          11848.61 [Kbytes/sec] received
Connection Times (ms)
min  mean[+/-sd] median   max
Connect:        0    0   1.8      0      15
Processing:    15 2034 3425.1    921   23265
Waiting:        0 2025 3423.8    921   23250
Total:         15 2034 3425.1    921   23265
Percentage of the requests served within a certain time (ms)
50%    921
66%   1343
75%   1656
80%   1875
90%   5078
95%   9421
98%  15828
99%  18171
100%  23265 (longest request)
D:\Apache2.2\bin>ab -n 10000 -c 1000 http://127.0.0.1/index.jsp
Server Software:        Apache/2.2.4
Server Hostname:        127.0.0.1
Server Port:            80
Document Path:          /index.jsp
Document Length:        323 bytes
Concurrency Level:      1000
Time taken for tests:   24.265625 seconds
Complete requests:      10000
Failed requests:        3953
(Connect: 0, Length: 3953, Exceptions: 0)
Write errors:           0
Non-2xx responses:      8686
Total transferred:      58651479 bytes
HTML transferred:       56541921 bytes
Requests per second:    412.11 [#/sec] (mean)
Time per request:       2426.563 [ms] (mean)
Time per request:       2.427 [ms] (mean, across all concurrent requests)
Transfer rate:          2360.38 [Kbytes/sec] received
Connection Times (ms)
min  mean[+/-sd] median   max
Connect:        0    0   1.7      0      15
Processing:     0 1573 4416.4     31   23984
Waiting:        0 1563 4402.5     31   23984
Total:          0 1573 4416.5     31   23984
Percentage of the requests served within a certain time (ms)
50%     31
66%     62
75%     62
80%     62
90%   7031
95%  13234
98%  18218
99%  19859
100%  23984 (longest request)
  tomcat 单独测试结果 (250并发会经常失败,200比较正常,偶尔有少量错误):

Java代码





  • D:\Apache2.2\bin>ab-n1000-c250http://127.0.0.1:8080/index.jsp

  • ThisisApacheBench,Version2.0.40-dev<$Revision:1.146$>apache-2.0

  • Copyright1996AdamTwiss,ZeusTechnologyLtd,http://www.zeustech.net/

  • Copyright2006TheApacheSoftwareFoundation,http://www.apache.org/


  • Benchmarking127.0.0.1(bepatient)

  • Completed100requests
  • Sendrequestfailed!
  • Sendrequestfailed!
  • Sendrequestfailed!
  • Sendrequestfailed!
  • Sendrequestfailed!

  • Completed200requests
  • Sendrequestfailed!

  • apr_socket_recv:远程主机强迫关闭了一个现有的连接。(730054)

  • Totalof223requestscompleted


  • D:\Apache2.2\bin>ab-n1000-c250http://127.0.0.1:8080/index.jsp


  • ServerSoftware:Apache-Coyote/1.1

  • ServerHostname:127.0.0.1

  • ServerPort:8080

  • DocumentPath:/index.jsp

  • DocumentLength:41078bytes


  • ConcurrencyLevel:250

  • Timetakenfortests:2.390625seconds

  • Completerequests:1000

  • Failedrequests:0

  • Writeerrors:0

  • Totaltransferred:41292000bytes

  • HTMLtransferred:41078000bytes

  • Requestspersecond:418.30[#/sec](mean)

  • Timeperrequest:597.656[ms](mean)

  • Timeperrequest:2.391[ms](mean,acrossallconcurrentrequests)

  • Transferrate:16867.56[Kbytes/sec]received

  • ConnectionTimes(ms)
  • minmean[+/-sd]medianmax

  • Connect:001.9015

  • Processing:109575314.15151218

  • Waiting:62550315.04531156

  • Total:109575314.15151218

  • Percentageoftherequestsservedwithinacertaintime(ms)

  • 50%515

  • 66%609

  • 75%921

  • 80%1031

  • 90%1062

  • 95%1125

  • 98%1140

  • 99%1140

  • 100%1218(longestrequest)



D:\Apache2.2\bin>ab -n 1000 -c 250 http://127.0.0.1:8080/index.jsp
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 100 requests
Send request failed!
Send request failed!
Send request failed!
Send request failed!
Send request failed!
Completed 200 requests
Send request failed!
apr_socket_recv: 远程主机强迫关闭了一个现有的连接。   (730054)
Total of 223 requests completed
D:\Apache2.2\bin>ab -n 1000 -c 250 http://127.0.0.1:8080/index.jsp
Server Software:        Apache-Coyote/1.1
Server Hostname:        127.0.0.1
Server Port:            8080
Document Path:          /index.jsp
Document Length:        41078 bytes
Concurrency Level:      250
Time taken for tests:   2.390625 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      41292000 bytes
HTML transferred:       41078000 bytes
Requests per second:    418.30 [#/sec] (mean)
Time per request:       597.656 [ms] (mean)
Time per request:       2.391 [ms] (mean, across all concurrent requests)
Transfer rate:          16867.56 [Kbytes/sec] received
Connection Times (ms)
min  mean[+/-sd] median   max
Connect:        0    0   1.9      0      15
Processing:   109  575 314.1    515    1218
Waiting:       62  550 315.0    453    1156
Total:        109  575 314.1    515    1218
Percentage of the requests served within a certain time (ms)
50%    515
66%    609
75%    921
80%   1031
90%   1062
95%   1125
98%   1140
99%   1140
100%   1218 (longest request)
  单独测试tomcat基本上只能达到240+左右的并发,tomcat+apache 900+并发,如果是静态页面tomcat并发1000+没有任何问题。
  tomcat基本上都保持在 20% - 45% 之间 , 内存在 80M -- 600M +之间 ,根据并发和请求的大小,内存的变法比较明显,cpu基本保存在这里,apache占用的cpu基本上是在 15% - 40%。
  因为JRockit收费,所以就没有测试。(主要是真实部署的时候会采用这些配置,收费的公司目前也不会购买!^_^)

运维网声明 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-335453-1-1.html 上篇帖子: Tomcat/Weblogic下的路径问题 下篇帖子: Tomcat的class加载的优先顺序
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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