Skip to content

Instantly share code, notes, and snippets.

@gcpantazis
Created March 3, 2014 05:35
Show Gist options
  • Save gcpantazis/9318992 to your computer and use it in GitHub Desktop.
Save gcpantazis/9318992 to your computer and use it in GitHub Desktop.
Quick set of scripts to get some performance tests out of redis pubsub.
'use strict';
var redis = require('redis'),
url = require('url'),
clientUrlParsed = url.parse(process.env.REDIS_POST_EVENT_BUS),
clientPost = redis.createClient(clientUrlParsed.port, clientUrlParsed.hostname, {
'auth_pass': clientUrlParsed.auth.split(':')[1]
}),
clientReturn = redis.createClient(clientUrlParsed.port, clientUrlParsed.hostname, {
'auth_pass': clientUrlParsed.auth.split(':')[1]
});
clientPost.on('error', function(err) {
console.log('clientPost Error ' + err);
});
clientReturn.on('error', function(err) {
console.log('clientReturn Error ' + err);
});
clientReturn.on('message', function() {
clientPost.publish('returnChan', 'got it');
});
clientReturn.subscribe('postChan');
'use strict';
var redis = require('redis'),
url = require('url'),
clientUrlParsed = url.parse(process.env.REDIS_POST_EVENT_BUS),
clientPost = redis.createClient(clientUrlParsed.port, clientUrlParsed.hostname, {
'auth_pass': clientUrlParsed.auth.split(':')[1]
}),
clientReturn = redis.createClient(clientUrlParsed.port, clientUrlParsed.hostname, {
'auth_pass': clientUrlParsed.auth.split(':')[1]
});
clientPost.on('error', function(err) {
console.log('clientPost Error ' + err);
});
clientReturn.on('error', function(err) {
console.log('clientReturn Error ' + err);
});
var getRandomString = function(len) {
var str = '',
itrs = Math.floor(len / 11);
for (var i = 0; i < itrs; i++) {
str += Math.random().toString(36).substring(7);
}
return str;
};
var pongs = 0,
groups = 0;
var howManyTries = 140000,
size = 500;
var startTime = new Date();
clientReturn.on('message', function() {
pongs++;
if (pongs === 1000) {
pongs = 0;
groups++;
console.log((new Date()) - startTime, groups);
if (groups === howManyTries / 1000) {
console.log('Processed ' + howManyTries + ' ' + size / 1000 + 'KB posts in ' + ((new Date()) - startTime) / 1000 + ' seconds.');
console.log(howManyTries / (((new Date()) - startTime) / 1000) + ' ops/sec.');
}
}
});
clientReturn.subscribe('returnChan');
for (var i = 0; i <= howManyTries; i++) {
clientPost.publish('postChan', getRandomString(size));
}
startTime = new Date();
console.log('done posting');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment