Skip to content

Instantly share code, notes, and snippets.

@cameronmccloud
Created October 3, 2011 11:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cameronmccloud/1258906 to your computer and use it in GitHub Desktop.
Save cameronmccloud/1258906 to your computer and use it in GitHub Desktop.
Socket.io chat server stress test
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");
});
})();
}
@michetti
Copy link

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:

  1. clone: https://github.com/michetti/holychat
  2. install dependencies with 'npm install -d'
  3. run app, 'node holychat.js'
  4. run benchmark 'node benchmark.js 60 200 100 500 0 0'

'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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment