-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dropBufferSupport option to improve the performance (#293)
- Loading branch information
Showing
7 changed files
with
181 additions
and
177 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,221 +1,98 @@ | ||
'use strict'; | ||
|
||
var childProcess = require('child_process'); | ||
var nodeRedis = require('redis'); | ||
var IORedis = require('../'); | ||
var ndredis, ioredis; | ||
var Redis = require('../'); | ||
|
||
console.log('=========================='); | ||
console.log('ioredis: ' + require('../package.json').version); | ||
console.log('node_redis: ' + require('redis/package.json').version); | ||
console.log('redis: ' + require('../package.json').version); | ||
var os = require('os'); | ||
console.log('CPU: ' + os.cpus().length); | ||
console.log('OS: ' + os.platform() + ' ' + os.arch()); | ||
console.log('node version: ' + process.version); | ||
console.log('current commit: ' + childProcess.execSync('git rev-parse --short HEAD')); | ||
console.log('=========================='); | ||
|
||
var redisJD, redisJ, redisBD, redisB; | ||
var waitReady = function (next) { | ||
var pending = 2; | ||
ndredis.on('ready', function () { | ||
var pending = 4; | ||
function check() { | ||
if (!--pending) { | ||
next(); | ||
} | ||
}); | ||
} | ||
redisJD = new Redis({ parser: 'javascript', dropBufferSupport: true }); | ||
redisJ = new Redis({ parser: 'javascript', dropBufferSupport: false }); | ||
redisBD = new Redis({ parser: 'hiredis', dropBufferSupport: true }); | ||
redisB = new Redis({ parser: 'hiredis', dropBufferSupport: false }); | ||
redisJD.on('ready', check); | ||
redisJ.on('ready', check); | ||
redisBD.on('ready', check); | ||
redisB.on('ready', check); | ||
}; | ||
|
||
ioredis.on('ready', function () { | ||
if (!--pending) { | ||
next(); | ||
} | ||
}); | ||
var quit = function () { | ||
redisJD.quit(); | ||
redisJ.quit(); | ||
redisBD.quit(); | ||
redisB.quit(); | ||
}; | ||
|
||
suite('simple set', function () { | ||
suite('SET foo bar', function () { | ||
set('mintime', 5000); | ||
set('concurrency', 300); | ||
before(function (start) { | ||
ndredis = nodeRedis.createClient(); | ||
ioredis = new IORedis(); | ||
waitReady(start); | ||
}); | ||
|
||
bench('ioredis', function (next) { | ||
ioredis.set('foo', 'bar', next); | ||
}); | ||
|
||
bench('node_redis', function (next) { | ||
ndredis.set('foo', 'bar', next); | ||
bench('javascript parser + dropBufferSupport: true', function (next) { | ||
redisJD.set('foo', 'bar', next); | ||
}); | ||
|
||
after(function () { | ||
ndredis.quit(); | ||
ioredis.quit(); | ||
}); | ||
}); | ||
|
||
suite('simple get', function () { | ||
set('mintime', 5000); | ||
set('concurrency', 300); | ||
before(function (start) { | ||
ndredis = nodeRedis.createClient(); | ||
ioredis = new IORedis(); | ||
waitReady(function () { | ||
ndredis.set('foo', 'bar', start); | ||
}); | ||
bench('javascript parser', function (next) { | ||
redisJ.setBuffer('foo', 'bar', next); | ||
}); | ||
|
||
bench('ioredis', function (next) { | ||
ioredis.get('foo', next); | ||
bench('hiredis parser + dropBufferSupport: true', function (next) { | ||
redisBD.set('foo', 'bar', next); | ||
}); | ||
|
||
bench('node_redis', function (next) { | ||
ndredis.get('foo', next); | ||
bench('hiredis parser', function (next) { | ||
redisB.setBuffer('foo', 'bar', next); | ||
}); | ||
|
||
after(function () { | ||
ndredis.quit(); | ||
ioredis.quit(); | ||
}); | ||
after(quit); | ||
}); | ||
|
||
suite('simple get with pipeline', function () { | ||
suite('LRANGE foo 0 99', function () { | ||
set('mintime', 5000); | ||
set('concurrency', 300); | ||
before(function (start) { | ||
ndredis = nodeRedis.createClient(); | ||
ioredis = new IORedis(); | ||
waitReady(function () { | ||
ndredis.set('foo', 'bar', start); | ||
}); | ||
}); | ||
|
||
bench('ioredis', function (next) { | ||
var pipeline = ioredis.pipeline(); | ||
for (var i = 0; i < 10; ++i) { | ||
pipeline.get('foo'); | ||
} | ||
pipeline.exec(next); | ||
}); | ||
|
||
bench('node_redis', function (next) { | ||
var pending = 0; | ||
for (var i = 0; i < 10; ++i) { | ||
pending += 1; | ||
ndredis.get('foo', check); | ||
var redis = new Redis(); | ||
var item = []; | ||
for (var i = 0; i < 100; ++i) { | ||
item.push((Math.random() * 100000 | 0) + 'str'); | ||
} | ||
function check() { | ||
if (!--pending) { | ||
next(); | ||
} | ||
} | ||
}); | ||
|
||
after(function () { | ||
ndredis.quit(); | ||
ioredis.quit(); | ||
}); | ||
}); | ||
|
||
suite('lrange 100', function () { | ||
set('mintime', 5000); | ||
set('concurrency', 300); | ||
before(function (start) { | ||
ndredis = nodeRedis.createClient(); | ||
ioredis = new IORedis(); | ||
waitReady(function () { | ||
var item = []; | ||
for (var i = 0; i < 100; ++i) { | ||
item.push((Math.random() * 100000 | 0) + 'str'); | ||
} | ||
ndredis.del('foo'); | ||
ndredis.lpush('foo', item, start); | ||
}); | ||
}); | ||
|
||
bench('ioredis', function (next) { | ||
ioredis.lrange('foo', 0, 99, next); | ||
}); | ||
|
||
bench('node_redis', function (next) { | ||
ndredis.lrange('foo', 0, 99, next); | ||
}); | ||
|
||
after(function () { | ||
ndredis.quit(); | ||
ioredis.quit(); | ||
}); | ||
}); | ||
|
||
suite('publish', function () { | ||
set('mintime', 5000); | ||
set('concurrency', 300); | ||
|
||
before(function (start) { | ||
ndredis = nodeRedis.createClient(); | ||
ioredis = new IORedis(); | ||
waitReady(function () { | ||
start(); | ||
redis.del('foo'); | ||
redis.lpush('foo', item, function () { | ||
waitReady(start); | ||
}); | ||
}); | ||
|
||
bench('ioredis', function (next) { | ||
ioredis.publish('foo', 'bar', next); | ||
}); | ||
|
||
bench('node_redis', function (next) { | ||
ndredis.publish('foo', 'bar', next); | ||
bench('javascript parser + dropBufferSupport: true', function (next) { | ||
redisJD.lrange('foo', 0, 99, next); | ||
}); | ||
|
||
after(function () { | ||
ndredis.quit(); | ||
ioredis.quit(); | ||
}); | ||
}); | ||
|
||
suite('subscribe', function () { | ||
set('mintime', 5000); | ||
set('concurrency', 300); | ||
|
||
var ndpublisher = null; | ||
var iopublisher = null; | ||
var ndsubscriber = null; | ||
var iosubscriber = null; | ||
|
||
before(function (start) { | ||
ndredis = nodeRedis.createClient(); | ||
ioredis = new IORedis(); | ||
waitReady(function () { | ||
ndsubscriber = ndredis; | ||
ndsubscriber.subscribe('foo'); | ||
iosubscriber = ioredis; | ||
iosubscriber.subscribe('foo'); | ||
|
||
ndredis = nodeRedis.createClient(); | ||
ioredis = new IORedis(); | ||
waitReady(function () { | ||
ndpublisher = ndredis; | ||
iopublisher = ioredis; | ||
start(); | ||
}); | ||
}); | ||
bench('javascript parser', function (next) { | ||
redisJ.lrangeBuffer('foo', 0, 99, next); | ||
}); | ||
|
||
bench('ioredis', function (next) { | ||
iosubscriber.removeAllListeners('message'); | ||
ndsubscriber.removeAllListeners('message'); | ||
iosubscriber.on('message', next); | ||
iopublisher.publish('foo', 'bar'); | ||
bench('hiredis parser + dropBufferSupport: true', function (next) { | ||
redisBD.lrange('foo', 0, 99, next); | ||
}); | ||
|
||
bench('node_redis', function (next) { | ||
iosubscriber.removeAllListeners('message'); | ||
ndsubscriber.removeAllListeners('message'); | ||
ndsubscriber.on('message', next); | ||
ndpublisher.publish('foo', 'bar'); | ||
bench('hiredis parser', function (next) { | ||
redisB.lrangeBuffer('foo', 0, 99, next); | ||
}); | ||
|
||
after(function () { | ||
ndredis.quit(); | ||
ioredis.quit(); | ||
}); | ||
after(quit); | ||
}); |
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
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
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
Oops, something went wrong.