Created
March 3, 2014 05:35
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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