Skip to content

Instantly share code, notes, and snippets.

@ktheory
Created August 25, 2014 22:56
Show Gist options
  • Save ktheory/948f19cc07afc8c70691 to your computer and use it in GitHub Desktop.
Save ktheory/948f19cc07afc8c70691 to your computer and use it in GitHub Desktop.
Redis hash benchmarks

Determine the memory impact of storing indicator counts in one big hash, or several smaller hashes.

See the redis memory docs for the advantages of several smaller hashes.

Test 1: One big hash

Store 10mm values in one big hash. Code:

r = Redis.new
N = 10_000_000
r.pipelined { N.times {|n| r.hincrby('aaron-hash', n, rand(N)) } }

###Memory usage: 803MB

$ redis-cli info |grep used_memory_human
used_memory_human:803.36M

Test 2: smaller hashes

hash-max-ziplist-entries is 512.

Code:

r.pipelined { N.times {|n| k = "aaron-hash:#{n/512}"; r.hincrby(k, n, rand(N)) } }

Memory usage: 109MB (~7x compression)

$ redis-cli info |grep used_memory_human
used_memory_human:109.45M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment