论坛首页 Java企业应用论坛

tomcat 优化到每秒并发1000

浏览 185854 次
该帖已经被评为精华帖
作者 正文
   发表时间:2008-08-31  
这样测试我个人觉得是有问题的。

建议使用LoadRunner来测试。通过指定一定用户量(比如100)来看TPS(Transaction per second)能达到多少。
0 请登录后投票
   发表时间:2008-09-01  
webeasymail 写道

现在系统部署只能达到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左右 ????????

 

0 请登录后投票
   发表时间:2008-09-03  
我的是P4 3G + 1G内存的PC机,系统XP,63并发可以通过,超过这个数量马上显示:
apr_poll:由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作

啥原因啊?
0 请登录后投票
   发表时间:2008-11-14  
这个测试意义不大

一般WIN2003和LINUX不需要啥优化就可以上到1000

但是实际上并发能稳定200就不错,一般的机器
0 请登录后投票
   发表时间:2008-11-15  
robbin 写道
我在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配置:

至少有两点优势:
x64,linux kernel 2.6,多线程性能比楼主的win 32强
tomcat有APR优化,性能也比纯java的强
0 请登录后投票
   发表时间:2008-11-25   最后修改:2008-11-25
环境配置
os:windows xp sp2
cup:intel T2080@1.73GHz
memory:1G
jdk:jdk-1_5_0_12-windows-i586-p
tomcat:5.5.27
apache:apache_2.2.10-win32-x86-no_ssl

对tomcat不做任何参数修改
ab -n 10000 -c 1000 http://127.0.0.1:8080/tomcat-connect-test/index.jsp

This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)

Test aborted after 10 failures

apr_socket_connect(): No connection could be made because the target machine act
ively refused it.   (730061)

tomcat控制台显示oom
严重: Error processing request
java.lang.OutOfMemoryError: Java heap space


在tomcat的startup.bat中添加参数
SET JAVA_OPTS=-Xms256m -Xmx256m -Djava.awt.headless=true

再次执行ab测试
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to 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
Completed 10000 requests
Finished 10000 requests


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

Document Path:          /tomcat-connect-test/index.jsp
Document Length:        705 bytes

Concurrency Level:      1000
Time taken for tests:   21.250 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      9557187 bytes
HTML transferred:       7050000 bytes
Requests per second:    470.59 [#/sec] (mean)
Time per request:       2125.000 [ms] (mean)
Time per request:       2.125 [ms] (mean, across all concurrent requests)
Transfer rate:          439.21 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1  19.2      0     500
Processing:   109 1933 869.0   1484    4234
Waiting:       63 1122 765.2   1000    3484
Total:        109 1934 869.9   1500    4234

Percentage of the requests served within a certain time (ms)
  50%   1500
  66%   1938
  75%   2453
  80%   2734
  90%   3453
  95%   3797
  98%   3828
  99%   3828
 100%   4234 (longest request)


tomcat控制台显示
严重: All threads (150) are currently busy, waiting. Increase maxThreads (150) or check the servlet status


apache+tomcat暂时没做测试
0 请登录后投票
   发表时间:2008-11-26   最后修改:2008-11-26
apache+tomcat测试

环境配置:
tomcat:5.0.28
apache:apache_2.2.4-win32-x86-no_ssl

在tomcat的startup.bat中添加参数
SET JAVA_OPTS=-Xms256m -Xmx256m -Djava.awt.headless=true


修改server.xml中8009端口配置
    <Connector port="8009"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               debug="0" connectionTimeout="20000" 
               disableUploadTimeout="true" protocol="AJP/1.3" />


ab -n 10000 -c 1000 http://127.0.0.1:8181/tomcat-connect-test/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/2.2.4
Server Hostname:        127.0.0.1
Server Port:            8181

Document Path:          /tomcat-connect-test/index.jsp
Document Length:        705 bytes

Concurrency Level:      1000
Time taken for tests:   103.968750 seconds
Complete requests:      10000
Failed requests:        3
   (Connect: 3, Length: 0, Exceptions: 0)
Write errors:           0
Total transferred:      9730000 bytes
HTML transferred:       7050000 bytes
Requests per second:    96.18 [#/sec] (mean)
Time per request:       10396.875 [ms] (mean)
Time per request:       10.397 [ms] (mean, across all concurrent requests)
Transfer rate:          91.38 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    9  69.7      0    1015
Processing:   359 10003 2537.5  10156   28828
Waiting:      359 6266 3074.4   6046   27359
Total:        359 10013 2536.9  10156   28828

Percentage of the requests served within a certain time (ms)
  50%  10156
  66%  10265
  75%  10531
  80%  10578
  90%  12046
  95%  12578
  98%  13593
  99%  14046
 100%  28828 (longest request)


tomcat控制台显示
2008-11-26 1:01:05 org.apache.jk.common.ChannelSocket processConnection
信息: connection timeout reached


貌似效果还不如直接跑tomcat
0 请登录后投票
   发表时间:2008-12-20   最后修改:2008-12-20
TOMCAT单挑

环境:
Tomcat 6.0
Red Hat Enterprise Linux Server release 5 (Tikanga)
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)

...
CPU3: Intel(R) Xeon(R) CPU           E5450  @ 3.00GHz stepping 06
checking TSC synchronization across 4 CPUs: passed.
Brought up 4 CPUs


ab -n 10000 -c 1000 http://localhost/sysmanage/login.jsp


This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
 
Benchmarking localhost (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
Completed 10000 requests
Finished 10000 requests
 
 
Server Software:        Apache-Coyote/1.1
Server Hostname:        localhost
Server Port:            80
 
Document Path:          /sysmanage/login.jsp
Document Length:        5656 bytes
 
Concurrency Level:      1000
Time taken for tests:   0.916 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      59000716 bytes
HTML transferred:       56627872 bytes
Requests per second:    10922.24 [#/sec] (mean)
Time per request:       91.556 [ms] (mean)
Time per request:       0.092 [ms] (mean, across all concurrent requests)
Transfer rate:          62931.65 [Kbytes/sec] received
 
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   2.9      2      22
Processing:     1    9  10.8      8     104
Waiting:        0    6  11.1      4     104
Total:          3   11  11.0     10     107
 
Percentage of the requests served within a certain time (ms)
  50%     10
  66%     11
  75%     11
  80%     12
  90%     14
  95%     16
  98%     23
  99%    100
 100%    107 (longest request)


汗,换个多一点的
ab -n 100000 -c 1000 http://localhost/sysmanage/login.jsp



ab -n 100000 -c 1000 http://localhost/sysmanage/login.jsp
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
 
Benchmarking localhost (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests
 
 
Server Software:        Apache-Coyote/1.1
Server Hostname:        localhost
Server Port:            80
 
Document Path:          /sysmanage/login.jsp
Document Length:        5656 bytes
 
Concurrency Level:      1000
Time taken for tests:   9.726 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      589512148 bytes
HTML transferred:       565803616 bytes
Requests per second:    10281.79 [#/sec] (mean)
Time per request:       97.259 [ms] (mean)
Time per request:       0.097 [ms] (mean, across all concurrent requests)
Transfer rate:          59191.80 [Kbytes/sec] received
 
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   66 746.7      2    9019
Processing:     0   13  32.7      9     644
Waiting:        0    8  31.9      5     638
Total:          3   79 770.2     11    9656
 
Percentage of the requests served within a certain time (ms)
  50%     11
  66%     12
  75%     12
  80%     13
  90%     15
  95%     32
  98%     65
  99%     98
 100%   9656 (longest request)

还是很快。。。

Requests per second:    10281.79 [#/sec] (mean)
还是蛮吓人的。。。
感觉是不是可以抛弃apache了?
0 请登录后投票
   发表时间:2009-01-05   最后修改:2009-01-05
测试内容为LZ提供的index页

第一次测试tomcat 配置:
    <Connector port="80" maxHttpHeaderSize="8192"  
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />

第一次测试tomcat 配置:
    <Connector port="80" maxHttpHeaderSize="8192"  
               maxThreads="1000" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />



两次测试结果:
D:\Apache2.2\bin>ab -n 10000 -c 1000 http://192.168.0.240/ab.jsp
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.0.240 (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
Completed 10000 requests
Finished 10000 requests


Server Software:        Apache-Coyote/1.1
Server Hostname:        192.168.0.240
Server Port:            80

Document Path:          /ab.jsp
Document Length:        85 bytes

Concurrency Level:      1000
Time taken for tests:   138.813 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      3160000 bytes
HTML transferred:       850000 bytes
Requests per second:    72.04 [#/sec] (mean)
Time per request:       13881.250 [ms] (mean)
Time per request:       13.881 [ms] (mean, across all concurrent requests)
Transfer rate:          22.23 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   14 196.2      0    3063
Processing:    78 13114 3561.3  12766   21563
Waiting:       31 7155 4508.2   6297   18672
Total:         78 13128 3563.1  12766   21563

Percentage of the requests served within a certain time (ms)
  50%  12766
  66%  15516
  75%  15609
  80%  15656
  90%  15781
  95%  18609
  98%  18719
  99%  18828
100%  21563 (longest request)

D:\Apache2.2\bin>ab -n 10000 -c 1000 http://192.168.0.240/ab.jsp
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.0.240 (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
Completed 10000 requests
Finished 10000 requests


Server Software:        Apache-Coyote/1.1
Server Hostname:        192.168.0.240
Server Port:            80

Document Path:          /ab.jsp
Document Length:        85 bytes

Concurrency Level:      1000
Time taken for tests:   130.781 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      3160000 bytes
HTML transferred:       850000 bytes
Requests per second:    76.46 [#/sec] (mean)
Time per request:       13078.125 [ms] (mean)
Time per request:       13.078 [ms] (mean, across all concurrent requests)
Transfer rate:          23.60 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   13 190.4      0    3156
Processing:    63 12267 3583.2  12703   18797
Waiting:       31 6921 4352.0   6391   15813
Total:         63 12280 3585.3  12703   18797

Percentage of the requests served within a certain time (ms)
  50%  12703
  66%  13016
  75%  15578
  80%  15609
  90%  15719
  95%  15828
  98%  18656
  99%  18719
100%  18797 (longest request)

D:\Apache2.2\bin>


结论:tomcat没有配置成1000,用默认的配置150个也通过了测试,测试结果比较后差异不大? 
      是我哪里没配置好,还是AB测试本来就不精确?

0 请登录后投票
   发表时间:2009-01-06  
sunwei_07 写道
我的是P4 3G + 1G内存的PC机,系统XP,63并发可以通过,超过这个数量马上显示:
apr_poll:由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作

啥原因啊?



我这里也有一样的问题
0 请登录后投票
论坛首页 Java企业应用版

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