配置: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 服務的鏈接數你多去看看鏈接池的東西。