nginx location配置
location ^~ /wnhz/websocket/ {
proxy_connect_timeout 60s;——該指令設置與upstream server的連接超時時間,有必要記住,這個超時不能超過75秒
proxy_read_timeout 3600s;——該指令設置與代理服務器的讀超時時間。它決定了nginx會等待多長時間來獲得請求的響應。這個時間不是獲得整個response的時間,而是兩次reading操作的時間
proxy_send_timeout 60s; ——這個指定設置了發送請求給upstream服務器的超時時間。超時設置不是爲了整個發送期間,而是在兩次write操作期間。如果超時後,upstream沒有收到新的數據,nginx會關閉連接
proxy_http_version 1.1;——支持websocket
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_pass http://test/websocket/;
}
--------------------- 官方配置--------------------------------------
location /chat/ {
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
-----------------------------------------------------------------------
tomcat server.xml配置
<Connector port="9999" protocol="org.apache.coyote.http11.Http11NioProtocol" connectionTimeout="20000" acceptCount="150000"
maxThreads="2000" maxConnections="150000" enableLookups="false" redirectPort="8443" />
connectionTimeout——默認設置爲20秒。通過修改該參數,可以修改tomcat的請求超時時間
acceptCount——當tomcat的線程數達到maxThreads後,新的請求就會排隊等待,超過排隊數的請求會被拒絕,acceptCount最好大於等於maxThreads
maxThreads:
(1)、部署的程序偏計算型,主要利用cpu資源,應該將該參數設置小一點,減小同一時間搶佔cpu資源的線程個數。
(2)、部署的程序對io、數據庫佔用時間較長,線程處於等待的時間較長,應該將該參數調大一點,增加處理個數。
maxConnections——這個值表示最多可以有多少個socket連接到tomcat上。NIO模式下默認是10000
enableLookups——爲了消除DNS查詢對性能的影響我們可以關閉DNS查詢