Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Benchmarkt socket.io

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:

  • 7 GB of memory
  • 20 EC2 Compute Units (8 virtual cores with 2.5 EC2 Compute Units each)
  • 1690 GB of instance storage
  • 64-bit platform
  • I/O Performance: High
  • API name: c1.xlarge

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?

like image 360
CodeChiller Avatar asked Jun 11 '12 09:06

CodeChiller


2 Answers

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.

like image 80
Joes Avatar answered Oct 04 '22 23:10

Joes


I didn't benchmark Socket.IO myself, but I know of 2 good resources that might help you, so check them out:

  • http://drewww.github.com/socket.io-benchmarking/
  • http://blog.mixu.net/2011/11/22/performance-benchmarking-socket-io-0-8-7-0-7-11-and-0-6-17-and-nodes-native-tcp/
like image 20
alessioalex Avatar answered Oct 05 '22 00:10

alessioalex