Tomcat優(yōu)化身堡,配置優(yōu)化
1.內(nèi)存優(yōu)化
JAVA_OPTS="-server -Xms2048M -Xmx2048M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$CATALINA_HOME/logs/heap.dump"
2.并發(fā)優(yōu)化
${tomcat}/webapps/docs/config/http.html
maxConnections:最大并發(fā)連接數(shù)团赁,NIO和NIO2默認(rèn)10000著淆,APR/native模式是8192惨险,The maximum number of connections that the server will accept and process at any given time
acceptCount: 隊(duì)列最大排隊(duì)數(shù)句各,默認(rèn)值是100寞缝,The maximum queue length for incoming connection requests when all possible request processing threads are in use.
maxThreads:最大工作線(xiàn)程數(shù),The maximum number of request processing threads to be created by this Connector
minSpareThreads:最小空閑的工作線(xiàn)程所刀。The minimum number of threads always kept running
3.其他優(yōu)化,
${tomcat}/webapps/docs/config/host.html
autoDeploy:This flag value indicates if Tomcat should check periodically for new or updated web applications while Tomcat is running
${tomcat}/webapps/docs/config/http.html
enableLookups:false
${tomcat}/webapps/docs/config/context.html:
reloadable:默認(rèn)false捞挥,開(kāi)發(fā)階段可以設(shè)置true浮创,負(fù)載很重
4. connector:apr
http://apr.apache.org/
依賴(lài):
APR 1.2+ development headers (libapr1-dev package)
OpenSSL 1.0.2+ development headers (libssl-dev package)
JNI headers from Java compatible JDK 1.4+
GNU development environment (gcc, make)
yum install apr* openssl-devel gcc make
tar zxvf apr-1.4.5.tar
cd apr-1.4.5
./configure --prefix=/usr/local/apr
make
make install
tar -zxvf apr-iconv-1.2.1.tar.gz
cd apr-iconv-1.2.1
./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr
make
make install
yum install expat-devel
tar zxvf apr-util-1.3.12.tar.gz
cd apr-util-1.3.12
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install
安裝openssl 1.0.2
./config --prefix=/usr/local/openssl
修改Makefile:
vi Makefile
將原來(lái)的:CFLAG= -DOPENSSL_THREADS
修改為: CFLAG= -fPIC -DOPENSSL_THREADS
也就是添加-fPIC
執(zhí)行執(zhí)行:
make && make install
cd bin
tar -zxvf tomcat-native.tar.gz
cd tomcat-native-1.2.12-src
cd native
./configure --with-apr=/usr/local/apr --with-ssl=/usr/local/openssl
make
make install
catalina.sh:
JAVA_OPTS="$JAVA_OPTS -Djava.library.path=/usr/local/apr/lib
注意:開(kāi)啟了apr之后,jvm用到的native內(nèi)存會(huì)增大砌函,因此要適當(dāng)調(diào)大Metaspace空間,添加JVM選項(xiàng):-XX:MetaspaceSize=128m
JAVA_OPTS="-server -Xms2048M -Xmx2048M -XX:MetaspaceSize=128M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$CATALINA_HOME/logs/heap.dump"
server.xml:
<Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol"
connectionTimeout="20000"
redirectPort="8443" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="off" />
LVS四層負(fù)載均衡
LVS + Keepalived高可用