測試環(huán)境
* 服務(wù)器:4核32G內(nèi)存籍胯,ubuntu 16.04
* 客戶端(16臺):2核4G內(nèi)存俐巴,ubuntu 16.04
服務(wù)器優(yōu)化參數(shù)
?最大文件打開數(shù)增大
默認(rèn)
cat /proc/sys/fs/file-max
3283596
ulimit -n
65535
修改
sudo vi /etc/security/limits.conf
root soft nofile 3283596
root hard nofile 3283596
* soft nofile 3283596
* hard nofile 3283596
端口范圍增大
默認(rèn)
sysctl -a|grep ip_local_port_range
net.ipv4.ip_local_port_range = 32768 60999
修改
sysctl -w net.ipv4.ip_local_port_range = 1024 65535
設(shè)置TCP 在關(guān)閉的時(shí)候不緩存指標(biāo)在 route cache
sysctl -w net.ipv4.tcp_no_metrics_save=1
服務(wù)器待測服務(wù)情況
* pm2 4實(shí)例管理的node websocket服務(wù)
* node開啟16個(gè)端口的websocket監(jiān)聽(3200-3015)
測試過程
* 客戶端模擬64000個(gè)websocket連接
* 16臺測試客戶端依次啟動(dòng)(當(dāng)前一臺達(dá)到64000后啟動(dòng)下一臺)
測試結(jié)果
服務(wù)端連接數(shù)情況
穩(wěn)定狀態(tài)下的負(fù)載情況
初始化pm2 node服務(wù)情況
結(jié)束后穩(wěn)定狀態(tài)下pm2 node服務(wù)情況
報(bào)錯(cuò)情況
{ Error: connect ETIMEDOUT 10.0.1.154:3208
at Object._errnoException (util.js:1024:11)
at _exceptionWithHostPort (util.js:1046:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '10.0.1.154',
port: 3208,
type: 'error',
target:
WebSocket {
domain: null,
_events:
{ message: [Object],
open: [Object],
close: [Object],
error: [Object] },
_eventsCount: 4,
_maxListeners: undefined,
_socket: null,
_ultron: null,
_closeReceived: false,
bytesReceived: 0,
readyState: 0,
supports: { binary: true },
extensions: {},
_binaryType: 'nodebuffer',
_isServer: false,
url: 'ws://10.0.1.154:3208/scene/push/6565',
protocolVersion: 13 } }