论坛首页 Java企业应用论坛

tomcat 优化到每秒并发1000

浏览 185543 次
该帖已经被评为精华帖
作者 正文
   发表时间:2008-05-06  

现在系统部署只能达到240+ , tomcat + apache 也只能到 900 + ,看到robbin的发帖能达到1000 ,不知道该如何配置,特来请教:
http://www.iteye.com/post/370111?page=8
robbin 写道
既然你用tomcat4都可以达到并发600,那tomcat5.5在同样环境下经过调优完全可以达到1000,看来问题还是在于你们tomcat没有配置好。

附带环境配置如下:

 

  环境配置如下: (jdk没有用 -server)

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

 
    <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

set JAVA_OPTS=-Xms1400m -Xmx1400m -Djava.awt.headless=true

 

index.jsp (除了下面这些代码,还有200行html代码,没有一个图片)

<%
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 启动信息如下:

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 测试结果:

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比较正常,偶尔有少量错误):

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收费,所以就没有测试。(主要是真实部署的时候会采用这些配置,收费的公司目前也不会购买!^_^)

 

不知道大家如何配置tomcat能并发1000左右 ????????

   发表时间:2008-05-06  
真实应用环境中没有数据库操作吗?这样的测试只对没有数据库操作的应用有参考意义。
0 请登录后投票
   发表时间:2008-05-06  
mobilefeather 写道
真实应用环境中没有数据库操作吗?这样的测试只对没有数据库操作的应用有参考意义。

本帖的目的是为了将tomcat的性能发挥出来,for循环的本意就是替代数据库的操作,当然和实际的数据库操作还是有区别的,至少目前关注的不是数据库性能,而且调优tomcat性能。
0 请登录后投票
   发表时间:2008-05-06  
我在JavaEye的数据库服务器上面简单测试了一把,没有做任何优化的工作,用ab测试,并发1000个请求很轻松,一点问题都没有。

系统配置:
CPU: AMD Opteron 2GHz × 2
内存: 4G RAM (其中MySQL使用了2G)
OS: SuSE Linux Enterprise Server SP3 x86_64 bit, Kernel 2.6.5
JDK: Sun HotSpot 1.5.0-10 x86_64 bit
Tomcat: 5.5.12 (APR)

Tomcat配置:

server.xml
  <Connector port="8080" maxHttpHeaderSize="8192" useBodyEncodingForURI="true"
               maxThreads="1000" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               compression="on" compressionMinSize="2048" 
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
               connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8"/>


catalina.sh这个文件啥都没有改,懒得指定JVM参数进行优化了。

测试文件就用你贴出来的那个,用ab并发1000个请求,发送10000个请求,轻轻松松跑完测试,没有一个request fail。

我特别需要声明的是,这台服务器的CPU是很古老的型号了,而且上面还跑着异常繁忙的JavaEye后台数据库。因此在这台服务器上面做测试,性能数据受到影响是可以预见的。而且我没有对JVM参数做任何优化,也没有对Tomcat进行任何特别的优化。即便如此,轻松的支撑1000个并发,这还是直接用ab去压tomcat,没有走lighttpd。我另外也测试了一下走lighttpd,速度稍微慢一点,但是1000并发也毫无问题。

Tomcat启动信息:
May 6, 2008 10:16:15 PM org.apache.coyote.http11.Http11AprProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
May 6, 2008 10:16:16 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1375 ms
May 6, 2008 10:16:16 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
May 6, 2008 10:16:16 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.12
May 6, 2008 10:16:16 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
May 6, 2008 10:16:16 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
May 6, 2008 10:16:22 PM org.apache.coyote.http11.Http11AprProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
May 6, 2008 10:16:22 PM org.apache.catalina.storeconfig.StoreLoader load
INFO: Find registry server-registry.xml at classpath resource
May 6, 2008 10:16:22 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6944 ms


apache/bin/ab  -c 1000 -n 10000 http://cvs.iteye.com:8080/test.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 cvs.iteye.com (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


Server Software:        Apache-Coyote/1.1
Server Hostname:        cvs.iteye.com
Server Port:            8080

Document Path:          /test.jsp
Document Length:        79 bytes

Concurrency Level:      1000
Time taken for tests:   15.329142 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      3100000 bytes
HTML transferred:       790000 bytes
Requests per second:    652.35 [#/sec] (mean)
Time per request:       1532.914 [ms] (mean)
Time per request:       1.533 [ms] (mean, across all concurrent requests)
Transfer rate:          197.47 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  343 1293.1      1    9046
Processing:     1  514 1416.6     83    7206
Waiting:        0  509 1416.8     79    7206
Total:          1  857 2012.5     89    9608

Percentage of the requests served within a certain time (ms)
  50%     89
  66%    147
  75%    212
  80%    326
  90%   3124
  95%   6078
  98%   8935
  99%   9049
 100%   9608 (longest request)
5 请登录后投票
   发表时间:2008-05-06  

楼主用的cpu 貌似32位的,操作系统 是windows
robbin用的cpu 貌似64位的,操作系统 是linux.

java在linux及64位下可以发挥的非常好。

0 请登录后投票
   发表时间:2008-05-06  
补充两句:

你用apache可以支撑到900+不意味着apache可以帮你提升tomcat的并发能力,而是因为apache默认情况下最大只支持256个并发,你超过256个并发以后,在apache这一端都要排队,无形之中降低了你tomcat的并发负载的压力。特别是看你的测试数据,使用apache以后,Requests per second从597ms一下上升到2.7秒就是明证,请求都被阻塞在apache那里排队去了。

我还没有升级到最新版本的JDK和最新版本的Tomcat,否则我估计我的测试性能还应该有更好的提升。另外我这硬件条件远不如你的测试硬件环境。所以你的测试环境没有道理不应该支持1000个并发,而且应该是异常轻松。其实从你250个并发的测试来看,虽然request fail了一些,但是Requests per second并不高,这不是一个正常的现象。我觉得可能是你的Tomcat配置有问题,或者是Windows操作系统的线程调度性能不佳导致的。



0 请登录后投票
   发表时间:2008-05-06  
codeutil 写道

楼主用的cpu 貌似32位的,操作系统 是windows
robbin用的cpu 貌似64位的,操作系统 是linux.

java在linux及64位下可以发挥的非常好。



嘿嘿,俺是64位的CPU,64位的Linux操作系统,再配上64位的JDK,齐活了,那性能真不是盖的!
0 请登录后投票
   发表时间:2008-05-07  
robbin 写道


<Connector port="8080" maxHttpHeaderSize="8192" useBodyEncodingForURI="true"
               maxThreads="1000" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               compression="on" compressionMinSize="2048" 
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
               connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="UTF-8"/>




改用Robin的配置,实际上和我的tomcat配置基本上没有区别,tomcat用5.5.20的,一下是并发 200的情况:

D:\Apache2.2\bin>ab -n 10000 -c 200 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)
Send request failed!
Send request failed!
Send request failed!
Send request failed!
Send request failed!
apr_socket_recv: 远程主机强迫关闭了一个现有的连接。   (730054)
Total of 817 requests completed

D:\Apache2.2\bin>ab -n 10000 -c 200 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 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests


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:      200
Time taken for tests:   24.125000 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      412920000 bytes
HTML transferred:       410780000 bytes
Requests per second:    414.51 [#/sec] (mean)
Time per request:       482.500 [ms] (mean)
Time per request:       2.413 [ms] (mean, across all concurrent requests)
Transfer rate:          16714.69 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   1.8      0      15
Processing:   109  479 275.8    375    1375
Waiting:       46  388 275.0    343    1203
Total:        109  480 275.8    375    1375

Percentage of the requests served within a certain time (ms)
  50%    375
  66%    421
  75%    437
  80%    453
  90%   1015
  95%   1125
  98%   1265
  99%   1281
 100%   1375 (longest request)


tomcat 用到的cpu 40% 左右,线程数 300左右,比tomcat6的并发少了50个左右。

在测试中tomcat最高占用的线程数是 1400+ ,一开始就是给1000个并发,虽然会失败,但是tomcat用到的线程数会一下上升到1400左右。

如果将jdk换成-server,发现tomcat的性能并没有提高,反而cpu使用会到 80% ,用到的内存和线程基本上都是一样的。


0 请登录后投票
   发表时间:2008-05-07  
codeutil 写道

楼主用的cpu 貌似32位的,操作系统 是windows
robbin用的cpu 貌似64位的,操作系统 是linux.

java在linux及64位下可以发挥的非常好。



现在没有64位的机器可以用来测试,所有现在没有办法在liunx下 64位上做测试。

jdk都是没有优化,tomcat的参数都是一样修改的,居然差别这么大~ 不知道是不是应为64位和liunx的影响。
0 请登录后投票
   发表时间:2008-05-09  
在我的双核1.6上 按照你们这个配置,这个测试的文件.
跑了一下,性能达差别太大了.是什么原因?
tomcat6,jdk6
SET JPDA_OPTS-Xms1400m -Xmx1400m -Djava.awt.headless=true 

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="2000" minSpareThreads="1000"/> 
<Connector port="8080" maxHttpHeaderSize="8192" useBodyEncodingForURI="true" maxThreads="2000" minSpareThreads="25" maxSpareThreads="75"  enableLookups="false" edirectPort="8443" acceptCount="2048" compression="on" compressionMinSize="2048"  connectionTimeout="20000" URIEncoding="UTF-8"/> 


D:\Apache\bin>ab -c 200 -n 1000 http://localhost:8080/docs/test.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 localhost (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Finished 1000 requests


Server Software:        Apache-Coyote/1.1
Server Hostname:        localhost
Server Port:            8080

Document Path:          /docs/test.jsp
Document Length:        105 bytes

Concurrency Level:      200
Time taken for tests:   28.234375 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      322000 bytes
HTML transferred:       105000 bytes
Requests per second:    35.42 [#/sec] (mean)
Time per request:       5646.875 [ms] (mean)
Time per request:       28.234 [ms] (mean, across all concurrent requests)
Transfer rate:          11.12 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   10  11.8     15     125
Processing:   297 5401 3078.8   5390   11438
Waiting:      234 4716 2880.1   4656   10437
Total:        312 5411 3079.3   5406   11453

Percentage of the requests served within a certain time (ms)
  50%   5406
  66%   7468
  75%   8265
  80%   8515
  90%   9609
  95%  10015
  98%  10546
  99%  10781
100%  11453 (longest request)



0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics