tomcat 優化到每秒併發1000

現在系統部署只能達到240+ , tomcat + apache 也只能到 900 + ,看到robbin的發帖能達到1000 ,不知道該如何配置,特來請教:
http://www.javaeye.com/post/370111?page=8
robbin 寫道
既然你用tomcat4都可以達到併發600,那tomcat5.5在同樣環境下經過調優完全可以達到1000,看來問題還是在於你們tomcat沒有配置好。

附帶環境配置如下:

 

  環境配置如下: (jdk沒有用 -server)

Java代碼 複製代碼
  1. windows 2003 企業版 sp2   
  2.   
  3. Intel(R) Xeon(R) 4 CPU 5130 @ 2.0GHz 4.00GB 內存   
  4.   
  5. apache_2.2.8-win32-x86   
  6.   
  7. mod_jk-apache-2.0.59  
  8.   
  9. jdk-1_5_0_14-windows-i586-p.exe -client   
  10.   
  11. 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代碼 複製代碼
  1. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="2000" minSpareThreads="1000"/>  
  2.   
  3.   
  4. <Connector port="8080" protocol="HTTP/1.1"    
  5.            connectionTimeout="2000"    
  6.            redirectPort="8443"  enableLookups="false"    
  7.   acceptCount="5000" maxThreads="2000"/>  

catalina.bat

Java代碼 複製代碼
  1. set JAVA_OPTS=-Xms1400m -Xmx1400m -Djava.awt.headless=true  
set JAVA_OPTS=-Xms1400m -Xmx1400m -Djava.awt.headless=true

 

index.jsp (除了下面這些代碼,還有200行html代碼,沒有一個圖片)

Java代碼 複製代碼
  1. <%   
  2. for(int i=0;i<1000;i++){   
  3.    request.setAttribute("key_"+i,"value_"+i);      
  4. }   
  5.   
  6.   
  7. for(int i=0;i<100;i++){   
  8.    request.getSession().setAttribute("key_"+i,"value_"+i);     
  9. }   
  10. %>   
  11. <br />   
  12. <%=request.getSession().getAttribute("key_0")%>   
  13. <%=request.getSession().getAttribute("key_0")%>   
  14. <%=request.getSession().getAttribute("key_0")%>   
  15. <%=request.getSession().getAttribute("key_0")%>   
  16. <%=request.getSession().getAttribute("key_0")%>   
  17. <%=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代碼 複製代碼
  1. 2008-5-6 17:54:52 org.apache.catalina.core.AprLifecycleListener init   
  2. 信息: Loaded APR based Apache Tomcat Native library 1.1.10.   
  3. 2008-5-6 17:54:52 org.apache.catalina.core.AprLifecycleListener init   
  4. 信息: APR capabilities: IPv6 [false], sendfile [true], accept filters [false], r   
  5. andom [true].   
  6. 2008-5-6 17:54:52 org.apache.coyote.http11.Http11AprProtocol init   
  7. 信息: Initializing Coyote HTTP/1.1 on http-8080  
  8. 2008-5-6 17:54:52 org.apache.coyote.ajp.AjpAprProtocol init   
  9. 信息: Initializing Coyote AJP/1.3 on ajp-30008  
  10. 2008-5-6 17:54:52 org.apache.catalina.startup.Catalina load   
  11. 信息: Initialization processed in 973 ms   
  12. 2008-5-6 17:54:52 org.apache.catalina.core.StandardService start   
  13. 信息: Starting service Catalina   
  14. 2008-5-6 17:54:52 org.apache.catalina.core.StandardEngine start   
  15. 信息: Starting Servlet Engine: Apache Tomcat/6.0.16  
  16. 2008-5-6 17:54:52 org.apache.coyote.http11.Http11AprProtocol start   
  17. 信息: Starting Coyote HTTP/1.1 on http-8080  
  18. 2008-5-6 17:54:53 org.apache.coyote.ajp.AjpAprProtocol start   
  19. 信息: Starting Coyote AJP/1.3 on ajp-30008  
  20. 2008-5-6 17:54:53 org.apache.catalina.startup.Catalina start   
  21. 信息: Server startup in 310 ms  
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代碼 複製代碼
  1. D:/Apache2.2/bin>ab -n 10000 -c 800 http://127.0.0.1/index.jsp   
  2.   
  3. Server Software:        Apache/2.2.4  
  4. Server Hostname:        127.0.0.1  
  5. Server Port:            80  
  6.   
  7. Document Path:          /index.jsp   
  8. Document Length:        41078 bytes   
  9.   
  10. Concurrency Level:      800  
  11. Time taken for tests:   34.46875 seconds   
  12. Complete requests:      10000  
  13. Failed requests:        0  
  14. Write errors:           0  
  15. Total transferred:      413090000 bytes   
  16. HTML transferred:       410780000 bytes   
  17. Requests per second:    293.71 [#/sec] (mean)   
  18. Time per request:       2723.750 [ms] (mean)   
  19. Time per request:       3.405 [ms] (mean, across all concurrent requests)   
  20. Transfer rate:          11848.61 [Kbytes/sec] received   
  21.   
  22. Connection Times (ms)   
  23.               min  mean[+/-sd] median   max   
  24. Connect:        0    0   1.8      0      15  
  25. Processing:    15 2034 3425.1    921   23265  
  26. Waiting:        0 2025 3423.8    921   23250  
  27. Total:         15 2034 3425.1    921   23265  
  28.   
  29. Percentage of the requests served within a certain time (ms)   
  30.   50%    921  
  31.   66%   1343  
  32.   75%   1656  
  33.   80%   1875  
  34.   90%   5078  
  35.   95%   9421  
  36.   98%  15828  
  37.   99%  18171  
  38.  100%  23265 (longest request)   
  39.   
  40. D:/Apache2.2/bin>ab -n 10000 -c 1000 http://127.0.0.1/index.jsp   
  41.   
  42. Server Software:        Apache/2.2.4  
  43. Server Hostname:        127.0.0.1  
  44. Server Port:            80  
  45.   
  46. Document Path:          /index.jsp   
  47. Document Length:        323 bytes   
  48.   
  49. Concurrency Level:      1000  
  50. Time taken for tests:   24.265625 seconds   
  51. Complete requests:      10000  
  52. Failed requests:        3953  
  53.    (Connect: 0, Length: 3953, Exceptions: 0)   
  54. Write errors:           0  
  55. Non-2xx responses:      8686  
  56. Total transferred:      58651479 bytes   
  57. HTML transferred:       56541921 bytes   
  58. Requests per second:    412.11 [#/sec] (mean)   
  59. Time per request:       2426.563 [ms] (mean)   
  60. Time per request:       2.427 [ms] (mean, across all concurrent requests)   
  61. Transfer rate:          2360.38 [Kbytes/sec] received   
  62.   
  63. Connection Times (ms)   
  64.               min  mean[+/-sd] median   max   
  65. Connect:        0    0   1.7      0      15  
  66. Processing:     0 1573 4416.4     31   23984  
  67. Waiting:        0 1563 4402.5     31   23984  
  68. Total:          0 1573 4416.5     31   23984  
  69.   
  70. Percentage of the requests served within a certain time (ms)   
  71.   50%     31  
  72.   66%     62  
  73.   75%     62  
  74.   80%     62  
  75.   90%   7031  
  76.   95%  13234  
  77.   98%  18218  
  78.   99%  19859  
  79.  100%  23984 (longest request)  
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代碼 複製代碼
  1. D:/Apache2.2/bin>ab -n 1000 -c 250 http://127.0.0.1:8080/index.jsp   
  2. This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0  
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/   
  4. Copyright 2006 The Apache Software Foundation, http://www.apache.org/   
  5.   
  6. Benchmarking 127.0.0.1 (be patient)   
  7. Completed 100 requests   
  8. Send request failed!   
  9. Send request failed!   
  10. Send request failed!   
  11. Send request failed!   
  12. Send request failed!   
  13. Completed 200 requests   
  14. Send request failed!   
  15. apr_socket_recv: 遠程主機強迫關閉了一個現有的連接。   (730054)   
  16. Total of 223 requests completed   
  17.   
  18. D:/Apache2.2/bin>ab -n 1000 -c 250 http://127.0.0.1:8080/index.jsp   
  19.   
  20. Server Software:        Apache-Coyote/1.1  
  21. Server Hostname:        127.0.0.1  
  22. Server Port:            8080  
  23.   
  24. Document Path:          /index.jsp   
  25. Document Length:        41078 bytes   
  26.   
  27. Concurrency Level:      250  
  28. Time taken for tests:   2.390625 seconds   
  29. Complete requests:      1000  
  30. Failed requests:        0  
  31. Write errors:           0  
  32. Total transferred:      41292000 bytes   
  33. HTML transferred:       41078000 bytes   
  34. Requests per second:    418.30 [#/sec] (mean)   
  35. Time per request:       597.656 [ms] (mean)   
  36. Time per request:       2.391 [ms] (mean, across all concurrent requests)   
  37. Transfer rate:          16867.56 [Kbytes/sec] received   
  38.   
  39. Connection Times (ms)   
  40.               min  mean[+/-sd] median   max   
  41. Connect:        0    0   1.9      0      15  
  42. Processing:   109  575 314.1    515    1218  
  43. Waiting:       62  550 315.0    453    1156  
  44. Total:        109  575 314.1    515    1218  
  45.   
  46. Percentage of the requests served within a certain time (ms)   
  47.   50%    515  
  48.   66%    609  
  49.   75%    921  
  50.   80%   1031  
  51.   90%   1062  
  52.   95%   1125  
  53.   98%   1140  
  54.   99%   1140  
  55.  100%   1218 (longest request)  
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收費,所以就沒有測試。(主要是真實部署的時候會採用這些配置,收費的公司目前也不會購買!^_^)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章