Search code examples
redisbenchmarkingin-memory-database

Why is Redis SET performance better than GET?


According to the Redis benchmarks , Redis can perform 100'000 SET operations/s, and 80'000 GET operations/s. Redis being an in-memory DB, this seems surprising because typically one would expect that memory writes are somewhat slower than reads, e.g. considering that SETs need to allocate memory prior to being able to write a value.

Can someone explain why SET is faster than GET?


Solution

  • Actually this is only an effect that by default you measure more I/O than the actual command execution time. If you start enabling pipelining in the benchmark, it is a bit more the measure of the actual command performance, and the numbers will change:

    $ redis-benchmark -q -n 1000000 -P 32 set foo bar
    set foo bar: 338964.03
    $ redis-benchmark -q -n 1000000 -P 32 get foo
    get foo: 432713.09 requests per second
    

    Now GET is faster :-)

    We should include pipelining in our benchmark doc page.

    EDIT: This is even more evident here:

    redis 127.0.0.1:6379> info commandstats
    # Commandstats
    cmdstat_get:calls=1001568,usec=221845,usec_per_call=0.22
    cmdstat_set:calls=831104,usec=498235,usec_per_call=0.60
    

    This command provides CPU time to serve the request internally, without accounting for I/O. SET is three times slower to process.