我是node.js / socket.io的新手,并尝试构建一个需要承受大量并发持久连接的高性能套接字服务器。为了测试限制,我建立了一个创建10k websockets的客户端,我没有遇到任何问题。但是,当我将此数字增加到20k时,会导致问题。服务器和客户端在同一台机器上运行(Windows 10)。
我遇到的问题:
一旦我超过16k并发连接,我的客户端会收到以下错误消息:
engine.io-client:套接字套接字错误 {"类型":" TransportError""描述" {"代码":" ENOBUFS"&#34 ;错误号":" ENOBUFS""系统调用":"连接""地址":" 127.0.0.1& #34;"端口":5433,"类型":"错误""目标" {"结构域&#34 ;:空," _events":{}," _eventsCount&#34:4," _socket":空," _ultron":空,& #34; _closeReceived":假,"与BytesReceived":0," readyState的":0,"支撑" {"二进制" :真}"扩展&#34 ;: {}," _isServer":假," URL":" WS://127.0.0.1:5433 / socket.io/?EIO=3&transport=websocket","protocolVersion":13,"binaryType":"buffer"}}} + 0毫秒
我已尝试以下方法解决此问题:
--max-old-space-size=8192
备注:
我为客户使用的代码:
var helper=require("./helpers/helper.js");
function log(text){
console.log("[CLIENT] " + text);
}
var blocked = require("blocked");
blocked(function(ms){
console.log("[WARNING] Last client tick took " + ms + "ms!! Clients may not react fast enough....");
}, {threshold: 150});
function createClient(){
var socket = require('socket.io-client')('http://127.0.0.1:5433', {transports:['websocket']});
socket.on('response', function (data) {
console.log("server:" + JSON.stringify(data));
});
socket.on('sessionCheckResponse', function (data) {
//console.log("server:" + JSON.stringify(data));
});
socket.connect();
setInterval(function () {
socket.emit("sessionCheck", "aaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccc");
}, 2500);
}
for(var i=0; i<17000; i++)
createClient();
答案 0 :(得分:0)
可在此处找到解决方案(在注册表中编辑MaxUserPort值),仅适用于Windows环境:https://support.microsoft.com/en-us/kb/196271