配置:Intel Xeon E5 2.4G*6核,16G内存,Redhat Linux X64,jdk 7(server),tomcat 8.9
改了tomcat 内存配置,开启了nio+epoll,结果仍不好看。。。
vi bin/catalina.sh
1 2 | CATALINA_OPTS=‘-Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.EPollSelectorProvider‘ JAVA_OPTS= -Xms800M -Xmx1500M -XX:PermSize=128M -XX:MaxPermSize=300M |
vi conf/server.xml
1 2 3 4 5 6 7 8 9 10 | < Connector port = "7080" protocol = "org.apache.coyote.http11.Http11NioProtocol" connectionTimeout = "20000" redirectPort = "7443" acceptorThreadCount = "6" acceptCount = "800" maxThreads = "400" compression = "on" compressionMinSize = "2048" noCompressionUserAgents = "gozilla,traviata" compressableMimeType = "text/html,text/xml,text/javascript,text/css,text/plain" /> |
采用jfinal+beetl模板,apache ab压力测试结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | D:\tools\Apache2.2\bin>ab -n 1000 -c 50 http://192.168.xx.xxx:7080/jfinalBeetl 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.xx.xxx (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 Completed 1000 requests Finished 1000 requests Server Software: Apache-Coyote/1.1 Server Hostname: 192.168.xx.xxx Server Port: 7080 Document Path: /jfinalBeetl Document Length: 327 bytes Concurrency Level: 50 Time taken for tests: 0.656 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Non-2xx responses: 1000 Total transferred: 146000 bytes HTML transferred: 0 bytes Requests per second: 1523.81 [#/sec] (mean) Time per request: 32.813 [ms] (mean) Time per request: 0.656 [ms] (mean, across all concurrent requests) Transfer rate: 217.26 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 2.6 0 16 Processing: 0 32 6.3 31 47 Waiting: 0 20 11.2 16 47 Total: 0 32 6.4 31 47 Percentage of the requests served within a certain time (ms) 50% 31 66% 31 75% 31 80% 31 90% 47 95% 47 98% 47 99% 47 100% 47 (longest request) |
未采用beetl,apache ab测试结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | D:\tools\Apache2.2\bin>ab -n 1000 -c 50 http://192.168.xx.xxx:7080/Root 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.xx.xxx (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 Completed 1000 requests Finished 1000 requests Server Software: Apache-Coyote/1.1 Server Hostname: 192.168.xx.xxx Server Port: 7080 Document Path: /Root Document Length: 11430 bytes Concurrency Level: 50 Time taken for tests: 1.297 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 11571000 bytes HTML transferred: 11430000 bytes Requests per second: 771.08 [#/sec] (mean) Time per request: 64.844 [ms] (mean) Time per request: 1.297 [ms] (mean, across all concurrent requests) Transfer rate: 8713.10 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 4.1 0 16 Processing: 16 62 9.7 63 94 Waiting: 0 29 18.1 31 78 Total: 16 63 9.5 63 94 Percentage of the requests served within a certain time (ms) 50% 63 66% 63 75% 63 80% 63 90% 78 95% 78 98% 78 99% 78 100% 94 (longest request) |
麻,再改进一下,估计能到2000多,曾听某网友说,调优后的tomcat项目能到3000,不知道是怎么做的。。。
哪位亲给说说。。。
以下由 明月照大江网友提供:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 我看了一下,tomcat给的几个参数,你先别忙着上集群,试试这些,tomcat8 1.Executor 配置 1.1 maxThreads ,默认是200,把这个设置这个数值,可以再高一些。400,800都试试。会有瓶颈。 2.HTTP Connector 设置 2.1 acceptCount 默认是100,调高,翻几倍试试 2.2 acceptorThreadCount 默认是1,调成CPU线程数,比如4核心8线程,就调成8. 2.3 maxThreads 默认是200,调高 2.4 processorCache 如果使用servlet3.0,配置到和 maxThread 一样 任何和缓冲区相关的配置都可以调大。 JVM参数尽量调大,各代配合合适的内存回收算法。 etc 详见:http://tomcat.apache.org/tomcat-8.0-doc/config/http.html 压缩选项之类的可以看着来,其他的比如可以把NIO2改成 APR。 以上是根据官网给的配置信息 “利用丰富的想象力” 得来的答案,没有经过任何测试。 先榨干一个tomcat,再上集群! |
以下转自http://blog.csdn.net/lifetragedy/article/details/7708724:
1 2 3 4 5 6 7 8 9 | Tomcat的优化分成两块: Tomcat启动命令行中的优化参数即JVM优化 Tomcat容器自身参数的优化(这块很像ApacheHttp Server) catalina.sh export JAVA_OPTS=..... -server: 我不管你什么理由,只要你的tomcat是运行在生产环境中的,这个参数必须给我加上 –Xmn: 设置年轻代大小为512m。整个堆大小=年轻代大小 + 年老代大小 + 持久代大小。持久代一般固定大小为64m,所以增大年轻代后,将会减小年老代大小。此值对系统性能影响较大,Sun官方推荐配置为整个堆的3/8。 -Xss: 是指设定每个线程的堆栈大小。这个就要依据你的程序,看一个线程 大约需要占用多少内存,可能会有多少线程同时运行等。一般不易设置超过1M |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
具体配置见官方文档:
https://tomcat.apache.org/tomcat-6.0-doc/config/http.html
事实上,tomcat 的最大连接数配的就是 tomcat 自己封装的线程池的最大线程数。这个最大连接数可能会满足你的需求,但不见得就是你的最优数目。
如果你的业务是计算密集型的:
在计算密集型应用中,线程池的大小应该等同于主机中 CPU 的数量。再添加更多线程将会打断请求的处理,因为线程的上下文切换也会延迟响应时间。一般来
说,如果你进程里有 1000 + 个线程,CPU 基本很多时间都浪费在线程切换上了。所以 tomcat 默认 200 最大连接数不是没有道理的。
非阻塞型 IO 应用将会是 CPU 密集型的,因为在请求得到处理的时候没有线程等待时间。
如果你的业务是 IO 密集型的:
决定 IO 等待应用的线程池大小会由于依赖于下游系统的响应时间而变得更加复杂,因为一个线程在其他系统响应之前始终是阻塞的
所以具体要看你具体业务处理类型了。
个人建议:对于并发数要求很高的,如果计算量很大(比如很多编解码操作),多申请 CPU 核数;对于产生对象很多的,多申请内存;而对于很多 IO 操作的,带宽一定要跟上,比如你只申请了 2MB,如果你的系统和外部交互频繁,个人经验,2MB 远远不够。
另外,mysql 服务的连接数你多去看看连接池的东西。
原文地址:http://024mj.blog.51cto.com/10252785/1763503