I want to benchmark my socket.io server. I want to test how many parallel connections and messages the server can handle.
But my socket.io server crash after some minutes when I start the benchmark with about 200 websockets.
I tried to use the cluster module of node.js to share the process to the cores. When I use the cluster module some connections become disconnected after some time.
The server that I use for the test is a virtual server on the amazon cloud with this properties:
Here is the code of the benchmark-client:
var fs = require('fs');
var io = require("socket.io-client");
var host = "http://localhost:3000";
var timeLog = fs.createWriteStream(__dirname+'/public/time.log',{flags:'a',mode:0666, encoding:'encoding'});
var count = 200;
var sockets = [];
var total = 0;
var countTime = 0;
var echo = exports;
echo.start = function() {
fs.writeFile('public/time.log',"",function(err){
if(err) throw err;
});
for(var i=0;i<count;i++){
var socket = io.connect(host,{"force new connection":true});
sockets.push(socket);
//console.log(i);
socket.on("message",function(message){
countTime++;
time = new Date().getTime()-message;
total+=time;
timeLog.write(time+"\n");
socket.send(new Date().getTime());
});
socket.on("disconnect",function(){
console.log("disconnect");
});
}
parallelSockets();
var j = 0;
}
function parallelSockets(){
for(var i = 0 ;i<count;i++){
sockets[i].send(new Date().getTime());
}
}
And here the code of the socket.io-server:
socket.on('message',function(message){
start = new Date().getTime();
socket.send(message);
end = new Date().getTime() - start;
logfile.write(end+"\n");
});
Is there any security mechanisms on socket.io that blocks so many parallel messages and connections form a client?
Can anybody help me?
I benchmarked Socket.IO and SockJS server implementations.
Here are the results
Test suite
Written in Java, supports 3 transports: Socket.IO 0.7+, SockJS 0.2+, raw Websockets. There's no compiled binary, but you can get Eclipse to compile it or just use command-line javac.
I didn't benchmark Socket.IO myself, but I know of 2 good resources that might help you, so check them out:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With