af83

More Redis Client Library Performance Benchmark, node.js with node-redis-client

update please view http://dev.af83.com/benchmark/more-more-redis-client-library-performance-benchmark-nodejs-noderedis-node-rocks/2011/01/0

Ok, so all of these interesting exchanges got me thinking. So I decided to do a quick port of this very small, unscientific benchmark to node to see how it will compare.

here's my very quick and dirty node.js redis benchmark

var sys = require("sys");
var redis_lib = require("../redis-node-client/lib/redis-client");
var redis = redis_lib.createClient();
var util = require('util');
redis.debugMode = false;   
console.log(util.inspect(process.memoryUsage()));

fast_iterations = process.argv[2] ||5000;
slow_iterations = process.argv[3] ||2500;
repeat = process.argv[4] || 3;
verbose = process.argv[5] || false;

callbacks=0;

start_time = new Date().getTime();
if (verbose)    sys.print("\n--- Benchmark for redis-node-client ---\n");

for (var j = 1; j < repeat; j++) {
    callbacks = callbacks + 2;
    redis.select(2, function (err){measure()});
    redis.flushdb( function (err){measure()});
    for (var i = 0; i < fast_iterations; i++) {
      (function (i) {
              callbacks = callbacks + 6;
              redis.set(i, 'bar' +i, function (err){measure()});
              redis.set("foo", 'bar', function (err){measure()});
              redis.get('baz', function (err){measure()}) ;
              redis.get('foo', function (err){measure()}) ;
              redis.del('foo', function (err){measure()});
              redis.mget([1, 'foo'], function (err){measure()});
      })(i);
    }
    ++callbacks;
    redis.flushdb(function (err){measure()});
    for(var i = 0; i < slow_iterations; i++){
        callbacks = callbacks +3;
        redis.set(i, 'bar' + i, function (err){measure()});
        redis.keys('*', function (err){measure()});
        redis.randomkey(function (err){measure()});
    }
    }
    
injection_ended_time = new Date().getTime();

function measure(){
--callbacks;
if (verbose && !(callbacks % 100)) sys.print (".") ;
if (callbacks<=0){    
    end_time = new Date().getTime();
    if (verbose) sys.print ("\nTests completed in " +  ( (end_time - start_time )/1000) /repeat+ " seconds in average\n");
    if (verbose) sys.print ("\nTests after injection completed in " +   ((end_time - injection_ended_time )/1000) /repeat+ " seconds in average\n");
    console.log(util.inspect(process.memoryUsage()));
    process.exit(1);
    
    }
}

and here are the results (precisely the same workload time node Benchmark.js 5000 1000 5 false)

{ rss: 11223040
, vsize: 3106287616
, heapTotal: 5136512
, heapUsed: 2744400
}

--- Benchmark for redis-node-client ---

Tests completed in 40.6248 seconds in average

Tests after injection completed in 39.9632 seconds in average
{ rss: 184610816
, vsize: 3233783808
, heapTotal: 139679616
, heapUsed: 27573088
}

real    3m23.239s
user    3m7.825s
sys 0m13.173s

As I restarted my machine in the meantime I reran the phpredis bench for a comparable baseline:

-- Bottom Line for phpredis: Tests completed in 2.716413 seconds in average, with 1.05 mb memory usage

real    0m16.332s
user    0m2.044s
sys 0m4.416s

whoaa something wrong in this picture?

Did I troll against php in the previous article?

What did I do fundamentally wrong here?

NB: using node v0.2.4 and the library from https://github.com/leepa/redis-node-client as I ran into this (https://github.com/fictorial/redis-node-client/issues#issue/26)

blog comments powered by Disqus