Skip to content

Instantly share code, notes, and snippets.

@sawantakash321
Forked from ktheory/redis.md
Created February 4, 2019 21:40
Show Gist options
  • Save sawantakash321/51bd3b1fbc81fbfa04be5c62b954cf0b to your computer and use it in GitHub Desktop.
Save sawantakash321/51bd3b1fbc81fbfa04be5c62b954cf0b 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