基准socket.io [英] Benchmarkt socket.io
问题描述
我想对我的socket.io服务器进行基准测试.我想测试服务器可以处理多少个并行连接和消息.
I want to benchmark my socket.io server. I want to test how many parallel connections and messages the server can handle.
但是当我用大约200个websocket启动基准测试后,我的socket.io服务器崩溃了.
But my socket.io server crash after some minutes when I start the benchmark with about 200 websockets.
我试图使用node.js的集群模块将进程共享给核心.当我使用集群模块时,某些连接会在一段时间后断开.
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的内存
- 20个EC2计算单元(8个虚拟内核,每个虚拟内核具有2.5个EC2计算单元)
- 1690 GB的实例存储空间
- 64位平台
- I/O性能:高
- API名称: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());
}
}
这是socket.io-server的代码:
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");
});
socket.io上是否存在任何安全机制,可以阻止许多并行消息和连接形成一个客户端?
Is there any security mechanisms on socket.io that blocks so many parallel messages and connections form a client?
有人可以帮助我吗?
推荐答案
我对Socket.IO和SockJS服务器实现进行了基准测试.
I benchmarked Socket.IO and SockJS server implementations.
结果可在此处找到: http://mrjoes.github. com/2011/12/15/sockjs-bench.html
测试套件在这里: https://github.com/mrjoes/sock-benchmarking
用Java语言编写,支持3种传输方式:Socket.IO 0.7 +,SockJS 0.2+,原始Websocket. 没有编译的二进制文件,但是您可以让Eclipse对其进行编译,也可以只使用命令行javac.
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.
这篇关于基准socket.io的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!