问题
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?
回答1:
I benchmarked Socket.IO and SockJS server implementations.
Results can be found here: http://mrjoes.github.com/2011/12/15/sockjs-bench.html
Test suite is here: https://github.com/mrjoes/sock-benchmarking
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.
回答2:
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/
回答3:
You may check Akinji
It opens concurrent sockets to server and listens given message and print them
http://github.com/sonsuzdongu/akinji
python akinji.py -c 100 --host localhost --port 3000 --waitFor 100 --on "some msg"
来源:https://stackoverflow.com/questions/10977345/benchmarkt-socket-io