如何加大tomcat连接数
在tomcat配置文件server.xml中的 <Connector ... /> 配置中,和连接数相关的参数有:
minSpareThreads:最小空闲连接线程数,用于提高系统处理性能
maxSpareThreads:最大空闲连接线程数,即:并发处理的最大请求数
maxThreads:允许的最大连接数,应大于等于maxThreads,默认值为200
enableLookups:是否反查域名,取值为:true或false。为了提高处理能力,应设置为false
connectionTimeout:网络连接超时,单位:毫秒。设置为0表示永不超时,这样设置有隐患的。通常可设置为30000毫秒。
maxThreads="500" minSpareThreads="20" maxSpareThreads="50"
useBodyEncodingForURI="true"
URIEncoding="UTF-8"
disableUploadTimeout="true"
web server允许的最大连接数还受制于操作系统的内核参数设置,通常Windows是2000个左右,Linux是1000个左右。Unix中如何设置这 些参数,请参阅Unix常用监控和管理命令
tomcat4中的配置示例:
<Connector className= "org.apache.coyote.tomcat4.CoyoteConnector "
port= "8080 " minSpareThreads= "10" maxSpareThreads= "50"
enableLookups= "false" maxThreads= "1024" debug= "0 " connectionTimeout= "30000 " />
对于其他端口的侦听配置,以此类推。
设置使用内存,bin 下创建setenv.sh
#!/bin/bash
#
# This script is invoked within catalina.sh, so we can inspect/manipulate all command line args of catalina.sh
#
#JAVA_HOME=/opt/jdk
#export JAVA_HOME
[ -z "$CATALINA_BASE" ] && CATALINA_BASE=$CATALINA_HOME
CATALINA_OPTS="$CATALINA_OPTS -Dappserver.home=$CATALINA_HOME -Dappserver.base=$CATALINA_BASE"
CATALINA_OPTS="$CATALINA_OPTS -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true"
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=utf8 -XX:ThreadStackSize=256 $JAVA_OPTS"
# dir path of Tomcat Native Library (TNL) libtcnative.1.so
#TNL_PATH=/usr/local/apr/lib
#
# LD_LIBRARY_PATH muste set correctly for Tomcat to use APR native library for HTTP/AJP connections
#
#LD_LIBRARY_PATH=$TNL_PATH:$LD_LIBRARY_PATH
#export LD_LIBRARY_PATH
# Boost performance (applicable for Solaris only)
#LD_PRELOAD=/usr/lib/amd64/libumem.so
LD_PRELOAD=/lib/libumem.so
export LD_PRELOAD
#
# parameters for normal startup
#
#HEAP_MIN=1536m
#HEAP_MAX=2048m
#HEAP_NEW=768m
#HEAP_NEW_MAX=1024m
HEAP_MIN=1024m
HEAP_MAX=2048m
HEAP_NEW=768m
HEAP_NEW_MAX=1024m
JMX_PORT=9901
ENABLE_JMX=0
ENABLE_TNL=0
ENABLE_GCINFO=1
# Note: bin/startup.sh invokes "catalina.sh start"
# Note: bin/shutdown.sh invokes "catalina.sh stop"
if [ "$1" = "stop" ]; then
# use minimal resource
HEAP_MIN=16m
HEAP_MAX=64m
HEAP_NEW=4m
HEAP_NEW_MAX=32m
ENABLE_JMX=0
ENABLE_TNL=0
fi
JAVA_OPTS="$JAVA_OPTS /
-server /
-Xms$HEAP_MIN -Xmx$HEAP_MAX /
-XX:NewSize=$HEAP_NEW -XX:MaxNewSize=$HEAP_NEW_MAX /
-XX:MaxPermSize=512m /
-XX:+UseConcMarkSweepGC /
-XX:+UseParNewGC /
-XX:+AggressiveOpts /
-XX:+UseFastAccessorMethods /
-XX:+UseBiasedLocking /
-Dlog.home=$CATALINA_BASE/logs/ /
"
if [ "$ENABLE_GCINFO" = "1" ]; then
JAVA_OPTS="$JAVA_OPTS /
-verbose:gc /
-XX:+PrintGCTimeStamps /
-XX:+PrintGCDetails /
"
fi
#
# enable JMX remote management if JMX_PORT defined
#
if [ "$ENABLE_JMX" = "1" ]; then
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote /
-Dcom.sun.management.jmxremote.port=$JMX_PORT /
-Dcom.sun.management.jmxremote.authenticate=false /
-Dcom.sun.management.jmxremote.ssl=false /
-Dcom.sun.management.jmxremote.access.file=$CATALINA_BASE/conf/jmxremote.access /
-Dcom.sun.management.jmxremote.access.file=$CATALINA_BASE/conf/jmxremote.access
"
fi
#
# Enable Tomcat Native Library (libtcnative.1.so) for best http/ajp performance
#
if [ "$ENABLE_TNL" = "1" ]; then
JAVA_OPTS="$JAVA_OPTS -Djava.library.path=$TNL_PATH"
echo "Enable TNL $TNL_PATH"
fi