客戶要求我執行的許多連接如何挑選一個大EC2實例(16GB內存,4核至強)socket.io實例句柄粗略計算的最高金額。的Node.js + socket.io確定每個實例
我更新了簡單socket.io基準的樣品。
Serever:
var io = require('socket.io').listen(80);
var exec = require('child_process').exec;
io.configure(function() {
io.set('log level', 1);
var transport = process.argv.length >= 2 ? process.argv[2] : null;
if (transport) {
io.set('transports', [transport]);
}
});
var payload = "Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item " +
"Payload: Payload line item ";
var users = 0;
function roundNumber(num, precision) {
return parseFloat(Math.round(num * Math.pow(10, precision))/Math.pow(10, precision));
}
setInterval(function() {
io.sockets.emit("message", payload);
console.log("Users: " + users);
}, 3000);
io.sockets.on('connection', function(socket) {
users++;
socket.on('disconnect', function() {
users--;
})
});
客戶
var io = require('socket.io-client');
var message = "o bispo de constantinopla nao quer se desconstantinopolizar";
var receivedMessages = 0;
function user(shouldBroadcast, host, port) {
var socket = io.connect('http://' + host + ':' + port, {
'force new connection': true
});
socket.on("message", function(){
receivedMessages += 1;
})
};
var argvIndex = 2;
var users = parseInt(process.argv[argvIndex++]);
var rampUpTime = parseInt(process.argv[argvIndex++]) * 1000; // in seconds
var newUserTimeout = rampUpTime/users;
var shouldBroadcast = process.argv[argvIndex++] === 'broadcast' ? true : false;
var host = process.argv[argvIndex++] ? process.argv[argvIndex - 1] : 'localhost';
var port = process.argv[argvIndex++] ? process.argv[argvIndex - 1] : '3000';
for(var i=0; i<users; i++) {
setTimeout(function() { user(shouldBroadcast, host, port); }, i * newUserTimeout);
};
setInterval(function() {
console.log("Messages received: " + receivedMessages);
receivedMessages = 0;
}, 3000);
我跑這個樣品,客戶開始對中例如,服務器上的大。我每3秒鐘得到4500條消息的結果數量。
但網絡,CPU和RAM的使用在2-10%範圍內。
是否有可能提高服務的連接數?
服務器操作系統是Windows Server 2008 R2。
所以CPU不是瓶頸,可能你的IO在某個地方。 – UpTheCreek 2013-03-15 13:38:32
相關問題:[我可以通過socket.emit發送多少數據?](http://stackoverflow.com/q/12977719/201952) – josh3736 2013-03-15 14:35:32