关于tomcat优化记录与思路

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

改了tomcat 内存配置,开启了nio+epoll,结果仍很差看。。。css


vi bin/catalina.shhtml

?java

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.xmlmysql

?算法

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压力测试结果:sql

?apache

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测试结果:tomcat

?多线程

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 服务的链接数你多去看看链接池的东西。

相关文章
相关标签/搜索