Created
October 3, 2011 11:15
-
-
Save cameronmccloud/1258906 to your computer and use it in GitHub Desktop.
Socket.io chat server stress test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.info("Socket.io chat test client"); | |
io = require('socket.io-client'); | |
for (var socket_n = 0; socket_n < 100; socket_n++) { | |
(function() { | |
var j = socket_n; | |
socket = io.connect('http://mytestserver:3000', {'force new connection': true}); | |
socket.my_nick = process.pid.toString() + "_" + j.toString(); | |
(function() { | |
var inner_socket = socket; | |
inner_socket.on('connect', function () { | |
console.info("Connected[" + j + "] => " + inner_socket.my_nick); | |
inner_socket.emit('nickname', inner_socket.my_nick, function (set) { }); | |
var interval = Math.floor(Math.random()*10001) + 5000; | |
setInterval(function() { | |
inner_socket.emit('user message', "Regular timer message every " + interval + " ms"); | |
}, interval); | |
}); | |
})(); | |
socket.on('user message', function (from, msg) { | |
//console.info(from + "::" + msg); | |
}); | |
socket.socket.on('error', function (err_msg) { | |
console.error("Connection Error:" + err_msg); | |
}); | |
socket.on('nicknames', function (nicknames) { | |
var number_of_users = 0; | |
for (var i in nicknames) { | |
number_of_users++; | |
} | |
console.info("There are " + number_of_users + " users logged in."); | |
}); | |
socket.on('announcement', function (msg) { | |
console.info("ANN: " + msg); | |
}); | |
socket.on('disconnect', function () { | |
console.info("Disconnected"); | |
}); | |
})(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Cameron, any news on this?
I have the same issue... I've also created a simple chat application and a benchmark script, but it doesn't go over 20 or so clients...
If you want to see what I have done:
'node benchmark ?' to see benchmark parameters...
I'm using node 0.4.12.
I'm trying to isolate the problem... for now, I will test to see if the problem is related to JSON parsing, since we are generating a lot of messages, and we are running all the clients on the same machine, so every client has to parse all the messages, from all other clients.