tomcat调优小技巧(1)

配置:Intel Xeon E5 2.4G*6核,16G内存,Redhat Linux X64,jdk 7(server),tomcat 8.9

改了tomcat 内存配置,开启了nio+epoll,结果仍不好看。。。

vi bin/catalina.sh

[html]  view plain  copy
  1. CATALINA_OPTS='-Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.EPollSelectorProvider'  
  2. JAVA_OPTS= -Xms800M -Xmx1500M -XX:PermSize=128M -XX:MaxPermSize=300M  


vi conf/server.xml

[html]  view plain  copy
  1. <Connector port="7080" protocol="org.apache.coyote.http11.Http11NioProtocol"  
  2.                connectionTimeout="20000"  
  3.                redirectPort="7443"   
  4.                acceptorThreadCount="6"  
  5.                acceptCount="800"  
  6.                maxThreads="400"  
  7.                compression="on"  
  8.                compressionMinSize="2048"  
  9.                noCompressionUserAgents="gozilla,traviata"   
  10.                compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"/>  


采用jfinal+beetl模板,apache ab压力测试结果:

[html]  view plain  copy
  1. D:\tools\Apache2.2\bin>ab -n 1000 -c 50 http://192.168.xx.xxx:7080/jfinalBeetl  
  2. This is ApacheBench, Version 2.3 <$Revision: 655654 $>  
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/  
  4. Licensed to The Apache Software Foundation, http://www.apache.org/  
  5.   
  6. Benchmarking 192.168.xx.xxx (be patient)  
  7. Completed 100 requests  
  8. Completed 200 requests  
  9. Completed 300 requests  
  10. Completed 400 requests  
  11. Completed 500 requests  
  12. Completed 600 requests  
  13. Completed 700 requests  
  14. Completed 800 requests  
  15. Completed 900 requests  
  16. Completed 1000 requests  
  17. Finished 1000 requests  
  18.   
  19.   
  20. Server Software:        Apache-Coyote/1.1  
  21. Server Hostname:        192.168.xx.xxx  
  22. Server Port:            7080  
  23.   
  24. Document Path:          /jfinalBeetl  
  25. Document Length:        327 bytes  
  26.   
  27. Concurrency Level:      50  
  28. Time taken for tests:   0.656 seconds  
  29. Complete requests:      1000  
  30. Failed requests:        0  
  31. Write errors:           0  
  32. Non-2xx responses:      1000  
  33. Total transferred:      146000 bytes  
  34. HTML transferred:       0 bytes  
  35. Requests per second:    1523.81 [#/sec] (mean)  
  36. Time per request:       32.813 [ms] (mean)  
  37. Time per request:       0.656 [ms] (mean, across all concurrent requests)  
  38. Transfer rate:          217.26 [Kbytes/sec] received  
  39.   
  40. Connection Times (ms)  
  41.               min  mean[+/-sd] median   max  
  42. Connect:        0    0   2.6      0      16  
  43. Processing:     0   32   6.3     31      47  
  44. Waiting:        0   20  11.2     16      47  
  45. Total:          0   32   6.4     31      47  
  46.   
  47. Percentage of the requests served within a certain time (ms)  
  48.   50%     31  
  49.   66%     31  
  50.   75%     31  
  51.   80%     31  
  52.   90%     47  
  53.   95%     47  
  54.   98%     47  
  55.   99%     47  
  56.  100%     47 (longest request)  


未采用beetl,apache ab测试结果:

[html]  view plain  copy
  1. D:\tools\Apache2.2\bin>ab -n 1000 -c 50 http://192.168.xx.xxx:7080/Root  
  2. This is ApacheBench, Version 2.3 <$Revision: 655654 $>  
  3. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/  
  4. Licensed to The Apache Software Foundation, http://www.apache.org/  
  5.   
  6. Benchmarking 192.168.xx.xxx (be patient)  
  7. Completed 100 requests  
  8. Completed 200 requests  
  9. Completed 300 requests  
  10. Completed 400 requests  
  11. Completed 500 requests  
  12. Completed 600 requests  
  13. Completed 700 requests  
  14. Completed 800 requests  
  15. Completed 900 requests  
  16. Completed 1000 requests  
  17. Finished 1000 requests  
  18.   
  19.   
  20. Server Software:        Apache-Coyote/1.1  
  21. Server Hostname:        192.168.xx.xxx  
  22. Server Port:            7080  
  23.   
  24. Document Path:          /Root  
  25. Document Length:        11430 bytes  
  26.   
  27. Concurrency Level:      50  
  28. Time taken for tests:   1.297 seconds  
  29. Complete requests:      1000  
  30. Failed requests:        0  
  31. Write errors:           0  
  32. Total transferred:      11571000 bytes  
  33. HTML transferred:       11430000 bytes  
  34. Requests per second:    771.08 [#/sec] (mean)  
  35. Time per request:       64.844 [ms] (mean)  
  36. Time per request:       1.297 [ms] (mean, across all concurrent requests)  
  37. Transfer rate:          8713.10 [Kbytes/sec] received  
  38.   
  39. Connection Times (ms)  
  40.               min  mean[+/-sd] median   max  
  41. Connect:        0    1   4.1      0      16  
  42. Processing:    16   62   9.7     63      94  
  43. Waiting:        0   29  18.1     31      78  
  44. Total:         16   63   9.5     63      94  
  45.   
  46. Percentage of the requests served within a certain time (ms)  
  47.   50%     63  
  48.   66%     63  
  49.   75%     63  
  50.   80%     63  
  51.   90%     78  
  52.   95%     78  
  53.   98%     78  
  54.   99%     78  
  55.  100%     94 (longest request)  


麻,再改进一下,估计能到2000多,曾听某网友说,调优后的tomcat项目能到3000,不知道是怎么做的。。。

哪位亲给说说。。。

以下由 明月照大江网友提供:

[html]  view plain  copy
  1. 我看了一下,tomcat给的几个参数,你先别忙着上集群,试试这些,tomcat8  
  2. 1.Executor 配置  
  3. 1.1 maxThreads ,默认是200,把这个设置这个数值,可以再高一些。400,800都试试。会有瓶颈。  
  4. 2.HTTP Connector 设置  
  5. 2.1 acceptCount 默认是100,调高,翻几倍试试  
  6. 2.2 acceptorThreadCount 默认是1,调成CPU线程数,比如4核心8线程,就调成8.  
  7. 2.3 maxThreads 默认是200,调高  
  8. 2.4 processorCache 如果使用servlet3.0,配置到和 maxThread 一样  
  9. 任何和缓冲区相关的配置都可以调大。  
  10. JVM参数尽量调大,各代配合合适的内存回收算法。  
  11. etc  
  12. 详见:http://tomcat.apache.org/tomcat-8.0-doc/config/http.html  
  13. 压缩选项之类的可以看着来,其他的比如可以把NIO2改成 APR。  
  14. 以上是根据官网给的配置信息  “利用丰富的想象力” 得来的答案,没有经过任何测试。  
  15. 先榨干一个tomcat,再上集群!  


以下转自http://blog.csdn.net/lifetragedy/article/details/7708724:

[html]  view plain  copy
  1. Tomcat的优化分成两块:  
  2. Tomcat启动命令行中的优化参数即JVM优化  
  3. Tomcat容器自身参数的优化(这块很像ApacheHttp Server)  
  4.   
  5. catalina.sh  
  6. export JAVA_OPTS=.....  
  7. -server: 我不管你什么理由,只要你的tomcat是运行在生产环境中的,这个参数必须给我加上  
  8. –Xmn: 设置年轻代大小为512m。整个堆大小=年轻代大小 + 年老代大小 + 持久代大小。持久代一般固定大小为64m,所以增大年轻代后,将会减小年老代大小。此值对系统性能影响较大,Sun官方推荐配置为整个堆的3/8。  
  9. -Xss: 是指设定每个线程的堆栈大小。这个就要依据你的程序,看一个线程 大约需要占用多少内存,可能会有多少线程同时运行等。一般不易设置超过1M  

小总结:

当一个进程有 500 个线程在跑的话,那性能已经是很低很低了。Tomcat 默认配置的最大请求数是 150,也就是说同时支持 150 个并发,当然了,也可以将其改大。
当某个应用拥有 250 个以上并发的时候,应考虑应用服务器的集群。
具体能承载多少并发,需要看硬件的配置,CPU 越多性能越高,分配给 JVM 的内存越多性能也就越高,但也会加重 GC 的负担。
操作系统对于进程中的线程数有一定的限制:
Windows 每个进程中的线程数不允许超过 2000
Linux 每个进程中的线程数不允许超过 1000
另外,在 Java 中每开启一个线程需要耗用 1MB 的 JVM 内存空间用于作为线程栈之用。
Tomcat的最大并发数是可以配置的,实际运用中,最大并发数与硬件性能和CPU数量都有很大关系的。更好的硬件,更多的处理器都会使Tomcat支持更多的并发。
Tomcat 默认的 HTTP 实现是采用阻塞式的 Socket 通信,每个请求都需要创建一个线程处理。这种模式下的并发量受到线程数的限制,但对于 Tomcat 来说几乎没有 BUG 存在了。
Tomcat 还可以配置 NIO 方式的 Socket 通信,在性能上高于阻塞式的,每个请求也不需要创建一个线程进行处理,并发能力比前者高。但没有阻塞式的成熟。
这个并发能力还与应用的逻辑密切相关,如果逻辑很复杂需要大量的计算,那并发能力势必会下降。如果每个请求都含有很多的数据库操作,那么对于数据库的性能也是非常高的。
对于单台数据库服务器来说,允许客户端的连接数量是有限制的。
并发能力问题涉及整个系统架构和业务逻辑。
系统环境不同,Tomcat版本不同、JDK版本不同、以及修改的设定参数不同。并发量的差异还是满大的。
maxThreads="1000" 最大并发数 
minSpareThreads="100"///初始化时创建的线程数
maxSpareThreads="500"///一旦创建的线程超过这个值,Tomcat就会关闭不再需要的socket线程。
acceptCount="700"// 指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理

猜你喜欢

转载自blog.csdn.net/w_dongqiang/article/details/80256884