Skip to content

Instantly share code, notes, and snippets.

@dshaw
Forked from shripadk/gist:1406702
Created November 30, 2011 09:05
Show Gist options
  • Save dshaw/1408474 to your computer and use it in GitHub Desktop.
Save dshaw/1408474 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var os = require('os');
var WebSocketClient = require('websocket').client;
var count = 0;
function recursion() {
var client = new WebSocketClient();
client.on('connectFailed', function(error) {
console.log("Connect Error: " + error.toString());
});
client.on('connect', function(connection) {
count++;
connection.on('error', function() {
console.log(arguments);
});
connection.on('close', function(code, err) {
count--;
console.log("Client closed at: "+count+". Reason : " + err);
process.exit(0);
})
if(count % 500 == 0) {
// sleep for 5 seconds
var f = os.freemem();
var t = os.totalmem();
console.log('RAM: ' + (f/t * 100) + ', LOAD AVG: ' + os.loadavg().join());
var sleepfor = 5000;
setTimeout(function() {
console.log('active connections: ' + count);
recursion();
}, sleepfor);
} else {
recursion();
}
});
var random_node_id = function() {
return Math.floor(Math.random()*90000) + 10000;
};
var random_client_id = function() {
return Math.floor(Math.random()*900) + 100;
};
client.connect("ws://127.0.0.1:8888/echo/"+random_node_id()+"/"+random_client_id()+"/websocket", 'echo-protocol');
};
recursion();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment