-
Notifications
You must be signed in to change notification settings - Fork 3
/
benchmark.js
40 lines (32 loc) · 977 Bytes
/
benchmark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var io = require('socket.io-client');
var i, clients = 0, sent = 0, received = 0;
var TOTAL_CLIENTS = process.argv[2] || 10000;
console.log("Total clients: " + TOTAL_CLIENTS);
console.log("\nclients\tsent\treceived\tsent/c\treceived/c");
setInterval(function() {
console.log([clients, sent, received, '',
Math.round(sent/clients), Math.round(received/clients)].join("\t"));
sent = 0;
received = 0;
}, 1000);
function sendMessage(socket) {
socket.emit('messages.create', {'name':'john', 'content':'meh'}, function() {
console.log('Sent message');
++sent;
sendMessage(socket);
});
}
function connectClient(i) {
setTimeout(function() {
var socket = io.connect('http://localhost:3000', { 'force new connection': true });
++clients;
socket.on('message', function(msg) {
socket.emit('messages.create', msg);
++received;
});
sendMessage(socket);
}, i*10);
}
for (i=0; i<TOTAL_CLIENTS; ++i) {
connectClient(i);
}