Skip to content

Instantly share code, notes, and snippets.

@shripadk
Created November 29, 2011 21:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shripadk/1406702 to your computer and use it in GitHub Desktop.
Save shripadk/1406702 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();
@dshaw
Copy link

dshaw commented Nov 30, 2011

WebSocketClient is from SockJS?

@shripadk
Copy link
Author

Nope. Its websocket module on NPM... https://github.com/Worlize/WebSocket-Node.git

@dshaw
Copy link

dshaw commented Nov 30, 2011

Thanks. How many socket connections are you getting? The Worlize client is stable running on Node v0.6?

@shripadk
Copy link
Author

I'm getting 48.5K concurrency before the ephemeral ports run out. I also discovered that the proxy that i'm using bouncy has some memory leak. So if I fix that / find some better proxy i'll rerun the tests again :) If the mem leak is fixed my estimate is that I can easily have 48.5x3K active connections (note these are just active connections... none of them are broadcasting anything... that will be my next test) on a single node instance.

@dshaw
Copy link

dshaw commented Nov 30, 2011

Sweet.

@shripadk
Copy link
Author

ok the mem leak is fixed. https://github.com/substack/bouncy/pull/12

going to run the test again tomorrow and update with the results :)

@gleber
Copy link

gleber commented May 24, 2012

@shripadk any updates on this? Were you able to get 150 000 000 connections out of it? :o

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