Hi, I'm trying to get some performance data in order to choose when to use redis, but I can't seem to get a consistent benchmark result.
I'm comparing the durations (ms) of a mongoose find, redis set/get with parsing an object (6kb text) and redis get/set with a long value:
mongoFind [6.800445,4.400399,3.351903,31.413145,83.322476,87.343173,62.329214,2.742115,1.852713,2.542614]
redisSetObject [2.873609,2.091907,10.87749,0.884921,1.191235,2.332975,1.021124,0.822983,1.055066,1.176622]
redisGetObject [1.900724,1.239943,1.382232,1.126001,0.554803,0.699953,0.714505,0.482456,0.506765,0.64612]
redisSetLong [0.779387,0.571763,0.440567,0.803045,2.436041,4.322287,17.469914,0.312463,0.388022,0.46824]
redisGetLong [0.700649,0.881971,5.043164,0.741424,0.884584,0.807541,1.255212,0.280573,0.359213,0.518526]
Can somebody explain me why such disparities between iterations? I was expecting minimum variation in redis and also get/set long to be faster than get/set object. Some variations I tried:
- single runs: makes the mongo results more consistent
- get/set long first: it seemed to become faster then get/set object, but not always, still big discrepancies.
const perfTest = function* () {
for (let i = 0; i < 10; i++) {
start = process.hrtime();
const company = yield Companies.findOne({ cod: 'a000001' });
// console.log('DDV', process.hrtime(start)[1] / 1000000);
durations.mongoFind.push(process.hrtime(start)[1] / 1000000);
start = process.hrtime();
yield redisClient.setex('testObject', 3600, JSON.stringify(company));
durations.redisSetObject.push(process.hrtime(start)[1] / 1000000);
start = process.hrtime();
yield redisClient.setex('testLong', 3600, Date.now());
durations.redisSetLong.push(process.hrtime(start)[1] / 1000000);
start = process.hrtime();
let parsedCompany = yield redisClient.get('testObject');
parsedCompany = JSON.parse(parsedCompany);
durations.redisGetObject.push(process.hrtime(start)[1] / 1000000);
start = process.hrtime();
let dateTime = yield redisClient.get('testLong');
durations.redisGetLong.push(process.hrtime(start)[1] / 1000000);
}
};
Thanks