Skip to content

Instantly share code, notes, and snippets.

@mgunneras
Created July 23, 2010 17:29
Show Gist options
  • Save mgunneras/487753 to your computer and use it in GitHub Desktop.
Save mgunneras/487753 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
// Use to load test Faye node.js comet server
// $ ./bayeux_load_client.js [number_of_clients]
var repl = require('repl');
var sys = require('sys');
var faye = require('./faye-node');
var room = '/chat/demo';
var endpoint = 'http://aws01:80/faye';
var clientCreationDelay = 50;
var reportDelay = 3 * 1000;
var clientLimit = process.argv[2] || 500;
var clients = [];
var messages_received = 0;
function stats () {
return('LIMIT: ' + clientLimit + ' CONNECTED: ' + clients.length + ' MESSAGES RECEIVED ' + messages_received);
}
var message_handler = function(message) {
messages_received++;
}
var create_client = function () {
var client = get_client();
client.connect(function(){
setTimeout(function() {
client.subscribe(room, message_handler);
},5);
clients.push(client);
if (clients.length < clientLimit) {
setTimeout(create_client, clientCreationDelay);
}
});
}
var get_client = function () {
return new faye.Client(endpoint, {timeout:90});
}
setInterval(function() {
sys.puts(stats());
}, reportDelay);
create_client();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment