以下內(nèi)容來源于互聯(lián)網(wǎng),具體出處不詳
據(jù)說服務(wù)器運(yùn)行TOMCAT+JDK環(huán)境能負(fù)載到動(dòng)態(tài)1W的并發(fā),貼上他的配置,以后有機(jī)會(huì)在測試!
java 環(huán)境配置:
export JAVA_OPTS="-server -Xms8g -Xmx8g -Xss128k -XX:ParallelGCThreads=20 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=31"
sysctl.conf的配置:
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_tw_buckets = 180000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 327680
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.ip_local_port_range = 1024 650000
net.ipv4.tcp_keepalive_time = 5
net.ipv4.tcp_keepalive_probes=2
net.ipv4.tcp_keepalive_intvl=2
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recyle = 1
net.ipv4.tcp_max_syn_backlog=8192
net.ipv4.tcp_no_metrics_save = 0
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
fs.file-max = 9553600
net.ipv4.netfilter.ip_conntrack_max = 655360
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 60
net.ipv4.tcp_max_tw_buckets = 60000
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
tomcat的SERVER.XML配置:
server.conf 配置
<Connector port="8188" protocol="HTTP/1.1"
maxThreads="30000"
minSpareThreads="512"
maxSpareThreads="2048"
enableLookups="false"
redirectPort="8443" acceptCount="35000"
debug="0"
connectionTimeout="40000"
disableUploadTimeout="true"
URIEncoding="UTF-8" />
參數(shù)說明:
connectionTimeout - 網(wǎng)絡(luò)連接超時(shí),單位:毫秒。設(shè)置為0表示永不超時(shí),這樣設(shè)置有隱患的。通??稍O(shè)置為30000毫秒。
keepAliveTimeout - 長連接最大保持時(shí)間(毫秒)。此處為15秒。
maxKeepAliveRequests - 最大長連接個(gè)數(shù)(1表示禁用,-1表示不限制個(gè)數(shù),默認(rèn)100個(gè)。一般設(shè)置在100~200之間)
maxHttpHeaderSize - http請求頭信息的最大程度,超過此長度的部分不予處理。一般8K。
URIEncoding - 指定Tomcat容器的URL編碼格式。
acceptCount - 指定當(dāng)所有可以使用的處理請求的線程數(shù)都被使用時(shí),可以放到處理隊(duì)列中的請求數(shù),超過這個(gè)數(shù)的請求將不予處理,默認(rèn)為10個(gè)。
disableUploadTimeout - 上傳時(shí)是否使用超時(shí)機(jī)制
enableLookups - 是否反查域名,取值為:true或false。為了提高處理能力,應(yīng)設(shè)置為false
bufferSize - defines the size (in bytes) of the buffer to be provided for input streams created by this connector. By default, buffers of 2048 bytes are provided.
maxSpareThreads - 最大空閑連接數(shù),一旦創(chuàng)建的線程超過這個(gè)值,Tomcat就會(huì)關(guān)閉不再需要的socket線程 The default value is 50.
maxThreads - 最多同時(shí)處理的連接數(shù),Tomcat使用線程來處理接收的每個(gè)請求。這個(gè)值表示Tomcat可創(chuàng)建的最大的線程數(shù)。 minSpareThreads - 最小空閑線程數(shù),Tomcat初始化時(shí)創(chuàng)建的線程數(shù) .
minProcessors - 最小空閑連接線程數(shù),用于提高系統(tǒng)處理性能,默認(rèn)值為10。
maxProcessors - 最大連接線程數(shù),即:并發(fā)處理的最大請求數(shù),默認(rèn)值為75。
修改啟動(dòng)時(shí)內(nèi)存參數(shù)
window下, 在catalina.bat最前面:
set JAVA_OPTS=-XX:PermSize=64M -XX:MaxPermSize=128m -Xms512m -Xmx1024m
一定加在catalina.bat最前面。
linux下,在catalina.sh最前面增加:
JAVA_OPTS="-XX:PermSize=64M -XX:MaxPermSize=128m -Xms512m -Xmx1024m -Duser.timezone=Asia/Shanghai"
注意:前后二者區(qū)別,有無set,有無雙引號。
寫Socket做測試
以下是Groovy代碼
content ='''GET /index.jsp HTTP/1.1
Accept-Language: zh-cn
Connection: Keep-Alive
Host: 192.168.0.53
Content-Length: 36
'''
def sleepTime=1000
Socket socket = new Socket('localhost',8080)
println 'is keep alive? ' + socket.getKeepAlive()
println 'sleep ' + sleepTime + ' ms.'
Thread.sleep(sleepTime)
println 'is closed? ' + socket.isClosed()
println 'sleep ' + sleepTime + ' ms.'
//Thread.sleep(sleepTime)
println 'write socket begin======'
writeStream(content, socket.getOutputStream())
println 'read socket begin======'
println readStream(socket.getInputStream())[0..300]
void writeStream(content, stream) {
OutputStream buf = new BufferedOutputStream(stream);
OutputStreamWriter out = new OutputStreamWriter(buf, "UTF-8");
out.write(content)
out.flush();
print content
//out.close();
}
String readStream(stream){
String sResult=''
byte[] buffer = new byte[1024];
int readCount = stream.read(buffer);
while (readCount != -1) {
sResult += new String(buffer, 0,
readCount, "utf-8");
readCount = stream.read(buffer);
}
stream.close()
return sResult
}