Skip to content

Instantly share code, notes, and snippets.

@scottgonzalez
Created May 2, 2010 03:31
Show Gist options
  • Save scottgonzalez/386871 to your computer and use it in GitHub Desktop.
Save scottgonzalez/386871 to your computer and use it in GitHub Desktop.
var http = require("http"),
querystring = require("querystring"),
sys = require("sys");
var channel = "http://chat.nodejitsu.com/chat",
speed = 5000,
spammers = 10;
for (var i = 0; i < spammers; i++ ) {
setTimeout(startSpamming, (speed / spammers) * i);
}
function startSpamming() {
var nick = "spammer" + Math.floor((Math.random() * 10000));
http.cat(channel + "/join?" + querystring.stringify({ nick: nick}), function(status, content) {
sys.puts("joined: " + sys.inspect(content));
var id = JSON.parse(content).id,
count = 0;
var interval = setInterval(function() {
var query = querystring.stringify({
id: id,
text: "spamming the chat " + (++count)
});
http.cat(channel + "/send?" + query);
sys.print(".");
if (!(count % 50)) {
sys.print("\n");
}
}, speed);
process.addListener("SIGINT", function() {
http.cat(channel + "/part?" + querystring.stringify({ id: id }), function() {
clearInterval(interval);
sys.puts("\nSent " + count + " messages.");
});
});
});
}
@scottgonzalez
Copy link
Author

script to spam a node-chat server, used for load testing

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