Skip to content

Instantly share code, notes, and snippets.

@alekseyl
Last active May 18, 2018 09:00
Show Gist options
  • Save alekseyl/6da343bc2372063794d649e8c6eb381e to your computer and use it in GitHub Desktop.
Save alekseyl/6da343bc2372063794d649e8c6eb381e to your computer and use it in GitHub Desktop.
compare redis performance for ruby hmethods VS methods
def calc_me_redis_perfomance_hash_zipping( zip_max = 128, sample_size = 10000 )
Redis.include(MeRedis)
redis = Redis.new
Redis.configure do |c|
c.zip_crumbs = :user
c.integers_to_base62 = true
c.hash_max_ziplist_entries = zip_max
end
get = []
me_get = []
100000.times do |i|
get << "muse:#{i}"
me_get << "user:#{i}"
end
redis.flushdb
redis.pipelined{ get.each{ |key| redis.incr( key ) } }
redis.pipelined{ me_get.each{ |key| redis.me_incr( key ) } }
Benchmark.ips do |bm|
bm.report( 'incr' ) { redis.pipelined{ get.sample(sample_size).each{ |key| redis.incr( key ) } } }
bm.report( 'me_incr' ) { redis.pipelined{ me_get.sample(sample_size).each{ |key| redis.me_incr( key) } } }
bm.compare!
end
Benchmark.ips do |bm|
bm.report( 'get' ) { redis.pipelined{ get.sample(sample_size).each{ |key| redis.get( key) } } }
bm.report( 'me_get' ) { redis.pipelined{ me_get.sample(sample_size).each{ |key| redis.me_get( key ) } } }
bm.compare!
end
Benchmark.ips do |bm|
bm.report( 'set' ) { redis.pipelined{ get.sample(sample_size).each{ |key| redis.set( key, SecureRandom.urlsafe_base64(rand(20) ) ) } } }
bm.report( 'me_set' ) { redis.pipelined{ me_get.sample(sample_size).each{ |key| redis.me_set( key, SecureRandom.urlsafe_base64(rand(20) ) ) } } }
bm.compare!
end
Benchmark.ips do |bm|
bm.report( 'mget' ) { redis.mget( *get.sample(sample_size) ) }
bm.report( 'me_mget' ) { redis.me_mget( *me_get.sample(sample_size) ) }
bm.compare!
end
Benchmark.ips do |bm|
bm.report( 'mset' ) { redis.mset( *get.sample(sample_size*2) ); }
bm.report( 'me_mset' ) { redis.me_mset( *me_get.sample(sample_size *2) ) }
bm.compare!
end
end
Research.calc_me_redis_perfomance_hash_zipping( 128, 1 )
incr: 7512.3 i/s
me_incr: 6635.9 i/s - same-ish: difference falls within error
get: 7150.1 i/s
me_get: 6409.2 i/s - same-ish: difference falls within error
set: 6703.6 i/s
me_set: 6024.4 i/s - 1.11x slower
mget: 9581.0 i/s
me_mget: 6406.2 i/s - 1.50x slower
mset: 9572.3 i/s
me_mset: 5581.9 i/s - 1.71x slower
Research.calc_me_redis_perfomance_hash_zipping( 128, 10 )
incr: 3190.4 i/s
me_incr: 2050.0 i/s - 1.56x slower
get: 3002.0 i/s
me_get: 2221.1 i/s - 1.35x slower
set: 2739.9 i/s
me_set: 1863.5 i/s - 1.47x slower
mget: 6892.1 i/s
me_mget: 2099.3 i/s - 3.28x slower
mset: 2285.9 i/s
me_mset: 1137.7 i/s - 2.01x slower
Research.calc_me_redis_perfomance_hash_zipping( 128, 100 )
incr: 382.6 i/s
me_incr: 271.2 i/s - same-ish: difference falls within error
get: 314.8 i/s
me_get: 230.7 i/s - same-ish: difference falls within error
set: 299.4 i/s
me_set: 232.1 i/s - same-ish: difference falls within error
mget: 945.6 i/s
me_mget: 254.0 i/s - 3.72x slower
mset: 897.0 i/s
me_mset: 202.5 i/s - 4.43x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment