Skip to content

Instantly share code, notes, and snippets.

@gcpantazis
Created March 4, 2014 00:38
Show Gist options
  • Save gcpantazis/9337878 to your computer and use it in GitHub Desktop.
Save gcpantazis/9337878 to your computer and use it in GitHub Desktop.
Brutish, unoptimized test of IronMQ with NodeJS.
'use strict';
//Testing IronMQ
var _ = require('underscore');
var msgBus = require('iron_mq');
var imq = new msgBus.Client({
'token': process.env.IRON_MQ_TOKEN,
'project_id': process.env.IRON_MQ_ID
});
var pub = imq.queue('pub'),
sub = imq.queue('sub');
var startTime = new Date();
var durationSeconds = 5,
postsPerSecond = 1000,
checksPerSecond = 3;
var checkPub = function() {
pub.get({
n: 100
}, function(error, messages) {
var ids = [];
_.each(messages, function(message) {
ids.push(message.id);
});
pub.del_multiple(ids, function() {
sub.post(ids, function() {
checkPub();
});
});
});
};
// Fire up three pub check cycles.
checkPub();
checkPub();
checkPub();
var j = 0;
var checkSub = function() {
sub.get({
n: 100
}, function(error, messages) {
var ids = [];
_.each(messages, function(message) {
ids.push(message.id);
});
if (ids.length > 0) {
sub.del_multiple(ids, function() {
j = j + ids.length;
console.log(j);
if (j === durationSeconds * postsPerSecond) {
console.log(durationSeconds * postsPerSecond + ' messages processed in ' + (((new Date()) - startTime) / 1000) + ' seconds.');
}
checkSub();
});
} else {
checkSub();
}
});
};
// Fire up three sub check cycles.
checkSub();
checkSub();
checkSub();
for (var k = 1; k <= durationSeconds; k++) {
setTimeout(function() {
var messageBuffer = [];
for (var l = 1; l <= postsPerSecond; l++) {
messageBuffer.push('testMessage');
}
pub.post(messageBuffer, function() {});
}, 1000 * k);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment