锁定老帖子 主题:tomcat 优化到每秒并发1000
该帖已经被评为精华帖
|
|
---|---|
作者 | 正文 |
发表时间:2008-05-11
我总觉得32位系统设置2000的并发线程不是很合理。32位JVM最多只能寻址4G,大部分要给heap,那么留给stack有多少?
假如一条thread的stack是1M,那么2000条thread就要吃掉2G的内存。。。貌似以前看到资料说,Windows下面每个进程能allocate给stack的内存空间最多只能2G. 懒得去确认了,有好事者可以自行查证。 另,用一些profiler工具去看看吧。 |
|
返回顶楼 | |
发表时间:2008-05-11
jacklondon 写道 每秒 1000 根本不算什么?
人家性能测试,都是用每秒完成多少个事务,比你这里的简单页面强多了。 对于一般的动态页面系统,需要设置一个前置的查询缓冲器,比如 Apache , 因为查询页面,特别是首页,每次都动态生成,其实并不必要,大多数页面,都可以缓存 5 秒钟以上的。最最简单地,使用 Apache 反向代理,配置上 Apache cache, 就可以提高性能。不用更改服务器配置,不用对代码进行更改。 似乎作者的优化方向有问题。 虽然 Apache cache 是 Apache 最近几个版本才有的功能,但也有超过一年多了。也不算什么稀罕的技术。google 上,一搜一大把。 你了Apache cache那那些每次页显示数据都不同的动态页面呢?使用cache是在没有办法的情况下的方法。 |
|
返回顶楼 | |
发表时间:2008-05-11
edge 写道 用windows的话,著名的MaxUserPort和TcpTimedWaitDelay得先调,不然没法对比
我调整"MaxUserPort"=20000 "TcpTimedWaitDelay"=30 后测试了一下xp CPU PD 820 响应时间有所提高,达到了 60. |
|
返回顶楼 | |
发表时间:2008-05-12
哈哈,终于优化到420了。
|
|
返回顶楼 | |
发表时间:2008-05-12
这个我家里的PC机,512内存
tomact是5.XX版本, 静态页面1000并发照样跑的很欢 根本不需要调优 |
|
返回顶楼 | |
发表时间:2008-05-12
为什么 我测试就不行呢
测试机器是xp,tomcat 在win2003 上面 两台机器的"MaxUserPort"=20000 "TcpTimedWaitDelay"=30 也调整了 60 个并发还能跑 80就出错了 D:\Program Files\Apache Group\Apache2\bin>ab -n 8000 -c 60 http://10.4.68.220:80 80/docs/test.jsp This is ApacheBench, Version 2.0.40-dev <$Revision: 1.121.2.1 $> apache-2.0 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking 10.4.68.220 (be patient) Completed 800 requests Completed 1600 requests Completed 2400 requests Completed 3200 requests Completed 4000 requests Completed 4800 requests Completed 5600 requests Completed 6400 requests Completed 7200 requests Finished 8000 requests Server Software: Apache-Coyote/1.1 Server Hostname: 10.4.68.220 Server Port: 8080 Document Path: /docs/test.jsp Document Length: 395 bytes Concurrency Level: 60 Time taken for tests: 10.984375 seconds Complete requests: 8000 Failed requests: 0 Write errors: 0 Total transferred: 4896000 bytes HTML transferred: 3160000 bytes Requests per second: 728.31 [#/sec] (mean) Time per request: 82.383 [ms] (mean) Time per request: 1.373 [ms] (mean, across all concurrent requests) Transfer rate: 435.25 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 3.7 0 62 Processing: 15 80 38.2 62 250 Waiting: 0 75 35.7 62 250 Total: 15 81 38.4 62 250 Percentage of the requests served within a certain time (ms) 50% 62 66% 78 75% 93 80% 125 90% 140 95% 156 98% 171 99% 187 100% 250 (longest request) D:\Program Files\Apache Group\Apache2\bin>ab -n 8000 -c 80 http://10.4.68.220:80 80/docs/test.jsp This is ApacheBench, Version 2.0.40-dev <$Revision: 1.121.2.1 $> apache-2.0 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking 10.4.68.220 (be patient) |
|
返回顶楼 | |
发表时间:2008-05-12
xtcn 写道 Tomcat本身一般不会成为瓶颈:)
应用或DB操作,这些才是重点~~ 这个问题已经说过,本帖的目的是将tomcat的性能发挥出来。 fxsjy 写道 我觉得ab测试和实际生产环境的测试差别很大,不是很能说明问题的。
ab和实际环境是差别很大,实际上的压力只会比AB大,觉得不会比ab小,用ab是为了快速测试,如果ab能承受大的压力,用lr也不会存太大的问题。 acdc 写道 我总觉得32位系统设置2000的并发线程不是很合理。32位JVM最多只能寻址4G,大部分要给heap,那么留给stack有多少? 假如一条thread的stack是1M,那么2000条thread就要吃掉2G的内存。。。貌似以前看到资料说,Windows下面每个进程能allocate给stack的内存空间最多只能2G. 懒得去确认了,有好事者可以自行查证。 另,用一些profiler工具去看看吧。 是的,设置2000是不合理,tomcat是动态thread的,2000只是为了不限制线程数,实际上是不可能用到2000的,这个对性能基本上影响不大。 fxsjy 写道 每秒 1000 根本不算什么?
人家性能测试,都是用每秒完成多少个事务,比你这里的简单页面强多了。 对于一般的动态页面系统,需要设置一个前置的查询缓冲器,比如 Apache , 因为查询页面,特别是首页,每次都动态生成,其实并不必要,大多数页面,都可以缓存 5 秒钟以上的。最最简单地,使用 Apache 反向代理,配置上 Apache cache, 就可以提高性能。不用更改服务器配置,不用对代码进行更改。 似乎作者的优化方向有问题。 虽然 Apache cache 是 Apache 最近几个版本才有的功能,但也有超过一年多了。也不算什么稀罕的技术。google 上,一搜一大把。 实际本帖的目的是发挥tomcat的性能,所以cache的使用并不再讨论范围。 smilerain 写道 哈哈,终于优化到420了。。
不知道是否可以贴出你的配置参数? agapple 写道 这个我家里的PC机,512内存
tomact是5.XX版本, 静态页面1000并发照样跑的很欢 根本不需要调优 静态页面1K是不会有任何问题,现在的问题是我需要的是动态页面并发到1K。 |
|
返回顶楼 | |
发表时间:2008-05-12
看下我的测试结果: 这是一个简单的搜索页面,使用compass(底层为lucene)做搜索,页面都是动态生成,不过就没涉及DB , 1000的并发也不赖 环境,win32 , Intel双核,2GB内存, 我们的PC机, tomact 5.0.28 内存使用达到336 - 360 MB , CPU达到60% , tomact线程为900左右(从任务管理器看) D:\Program Files\Apache Software Foundation\Apache2.2\bin>ab -c 1000 -n 4000 http://localhost:8080/laster/search/search.ht m?keyword=%E7%94%B7%E7%94%9F 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 400 requests Completed 800 requests Completed 1200 requests Completed 1600 requests Completed 2000 requests Completed 2400 requests Completed 2800 requests Completed 3200 requests Completed 3600 requests Finished 4000 requests Server Software: Apache-Coyote/1.1 Server Hostname: localhost Server Port: 8080 Document Path: /laster/search/search.htm?keyword=%E7%94%B7%E7%94%9F Document Length: 5324 bytes Concurrency Level: 1000 Time taken for tests: 28.558656 seconds Complete requests: 4000 Failed requests: 0 Write errors: 0 Total transferred: 21960000 bytes HTML transferred: 21296000 bytes Requests per second: 140.06 [#/sec] (mean) Time per request: 7139.664 [ms] (mean) Time per request: 7.140 [ms] (mean, across all concurrent requests) Transfer rate: 750.91 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 19.6 0 514 Processing: 2386 6592 1785.5 6753 10091 Waiting: 2386 6555 1850.7 6753 10091 Total: 2386 6594 1785.9 6753 10091 Percentage of the requests served within a certain time (ms) 50% 6753 66% 6987 75% 7268 80% 8094 90% 9062 95% 9576 98% 9732 99% 9919 100% 10091 (longest request) 以apache + tomact 做测试, 结果如下: apache版本 2.2.6(win32) + mod_jk(1.2.26) , 参数配置: ThreadsPerChild 800 MaxRequestsPerChild 0 这时的tomact线程只有100多点,响应时间明显提高了 D:\Program Files\Apache Software Foundation\Apache2.2\bin>ab -c 1000 -n 4000 http://localhost/laster/search/search.htm?key word=%E7%94%B7%E7%94%9F 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 400 requests Completed 800 requests Completed 1200 requests Completed 1600 requests Completed 2000 requests Completed 2400 requests Completed 2800 requests Completed 3200 requests Completed 3600 requests Finished 4000 requests Server Software: Apache/2.2.6 Server Hostname: localhost Server Port: 80 Document Path: /laster/search/search.htm?keyword=%E7%94%B7%E7%94%9F Document Length: 323 bytes Concurrency Level: 1000 Time taken for tests: 16.779356 seconds Complete requests: 4000 Failed requests: 2337 (Connect: 0, Length: 2337, Exceptions: 0) Write errors: 0 Non-2xx responses: 1663 Total transferred: 13762890 bytes HTML transferred: 12979337 bytes Requests per second: 238.39 [#/sec] (mean) Time per request: 4194.839 [ms] (mean) Time per request: 4.195 [ms] (mean, across all concurrent requests) Transfer rate: 800.98 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 29.3 0 529 Processing: 568 3816 1057.2 3978 5741 Waiting: 347 2378 1118.4 2069 4716 Total: 568 3819 1057.1 3986 5741 Percentage of the requests served within a certain time (ms) 50% 3986 66% 4250 75% 4395 80% 4491 90% 5110 95% 5251 98% 5335 99% 5389 100% 5741 (longest request)
|
|
返回顶楼 | |
发表时间:2008-05-12
agapple 写道
看下我的测试结果: 这是一个简单的搜索页面,使用compass(底层为lucene)做搜索,页面都是动态生成,不过就没涉及DB , 1000的并发也不赖 环境,win32 , Intel双核,2GB内存, 我们的PC机, tomact 5.0.28 内存使用达到336 - 360 MB , CPU达到60% , tomact线程为900左右(从任务管理器看) D:\Program Files\Apache Software Foundation\Apache2.2\bin>ab -c 1000 -n 4000 http://localhost:8080/laster/search/search.ht m?keyword=%E7%94%B7%E7%94%9F 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 400 requests Completed 800 requests Completed 1200 requests Completed 1600 requests Completed 2000 requests Completed 2400 requests Completed 2800 requests Completed 3200 requests Completed 3600 requests Finished 4000 requests Server Software: Apache-Coyote/1.1 Server Hostname: localhost Server Port: 8080 Document Path: /laster/search/search.htm?keyword=%E7%94%B7%E7%94%9F Document Length: 5324 bytes Concurrency Level: 1000 Time taken for tests: 28.558656 seconds Complete requests: 4000 Failed requests: 0 Write errors: 0 Total transferred: 21960000 bytes HTML transferred: 21296000 bytes Requests per second: 140.06 [#/sec] (mean) Time per request: 7139.664 [ms] (mean) Time per request: 7.140 [ms] (mean, across all concurrent requests) Transfer rate: 750.91 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 19.6 0 514 Processing: 2386 6592 1785.5 6753 10091 Waiting: 2386 6555 1850.7 6753 10091 Total: 2386 6594 1785.9 6753 10091 Percentage of the requests served within a certain time (ms) 50% 6753 66% 6987 75% 7268 80% 8094 90% 9062 95% 9576 98% 9732 99% 9919 100% 10091 (longest request) 以apache + tomact 做测试, 结果如下: apache版本 2.2.6(win32) + mod_jk(1.2.26) , 参数配置: ThreadsPerChild 800 MaxRequestsPerChild 0 这时的tomact线程只有100多点,响应时间明显提高了 D:\Program Files\Apache Software Foundation\Apache2.2\bin>ab -c 1000 -n 4000 http://localhost/laster/search/search.htm?key word=%E7%94%B7%E7%94%9F 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 400 requests Completed 800 requests Completed 1200 requests Completed 1600 requests Completed 2000 requests Completed 2400 requests Completed 2800 requests Completed 3200 requests Completed 3600 requests Finished 4000 requests Server Software: Apache/2.2.6 Server Hostname: localhost Server Port: 80 Document Path: /laster/search/search.htm?keyword=%E7%94%B7%E7%94%9F Document Length: 323 bytes Concurrency Level: 1000 Time taken for tests: 16.779356 seconds Complete requests: 4000 Failed requests: 2337 (Connect: 0, Length: 2337, Exceptions: 0) Write errors: 0 Non-2xx responses: 1663 Total transferred: 13762890 bytes HTML transferred: 12979337 bytes Requests per second: 238.39 [#/sec] (mean) Time per request: 4194.839 [ms] (mean) Time per request: 4.195 [ms] (mean, across all concurrent requests) Transfer rate: 800.98 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 29.3 0 529 Processing: 568 3816 1057.2 3978 5741 Waiting: 347 2378 1118.4 2069 4716 Total: 568 3819 1057.1 3986 5741 Percentage of the requests served within a certain time (ms) 50% 3986 66% 4250 75% 4395 80% 4491 90% 5110 95% 5251 98% 5335 99% 5389 100% 5741 (longest request)
+apahce 你有一半以上失败了! Complete requests: 4000 Failed requests: 2337 (Connect: 0, Length: 2337, Exceptions: 0) 详细能配置贴出来看看~ windows 2000 的主配置,tomcat的主要配置。 |
|
返回顶楼 | |
发表时间:2008-05-12
对于windows的MaxUserPort 和TcpTimedWaitDelay 我采用的都是默认值,未作任何变动 tomact配置如下: <Connector port="8080" maxThreads="1200" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true" useBodyEncodingForURI="true" />
catalina.bat调整: set JAVA_OPTS=-Xms256m -Xmx512m -Djava.awt.headless=true 跑了下首页的测试jsp,结果如下: D:\Program Files\Apache Software Foundation\Apache2.2\bin>ab -c 1000 -n 10000 http://localhost:8080/Hession/index.jsp
|
|
返回顶楼 | |