Memory Optimization
Sripathi Krishnan, CTO, HashedIn Technologies
Copyright © 2017 HashedIn Technologies Pvt. Ltd.
- Ensure the objects don’t have redundant data
- Users have recommended products
- If you cache users, ensure
recommended_products is just a reference
Copyright © 2017 HashedIn Technologies Pvt. Ltd.
- Default serialization libraries are not
efficient
- Use Protobuf / Message Pack / Others
- JSON must be compressed
Copyright © 2017 HashedIn Technologies Pvt. Ltd.
- Keys in redis have lots of overheads
- For smaller strings, combine them into a larger
hash
- Tweak hash-max-ziplist-entries and
hash-max-ziplist-value appropriately
Copyright © 2017 HashedIn Technologies Pvt. Ltd.
- Objects are usually saved in hashmap, but the
keys are redundant if every object has the
same keys
- “NamedTuple”: store objects in a list instead
- “C like struct”: Use Redis Bitfield command to
store fixed length values in a single string
Copyright © 2017 HashedIn Technologies Pvt. Ltd.
- Sets in Redis are normally stored as HashTables
- But if they only contain integers/longs, they are
stored in memory-efficient “intsets”
- 10x or more memory reduction if your IDs are
numeric only
Copyright © 2017 HashedIn Technologies Pvt. Ltd.
- Count Objects? Use HyperLogLog
- Check for Existence? Use Bloom Filter
You won’t get exact results, but sometimes the
memory savings are worth it.
Copyright © 2017 HashedIn Technologies Pvt. Ltd.
- Redis Strings can be used as a giant bitmap
- You can set/unset/toggle individual bits
Useful for things like access control - can this user
perform that operation?
Copyright © 2017 HashedIn Technologies Pvt. Ltd.
- Sorted Sets are very expensive memory-wise
- Tweak zset-max-ziplist-entries and
zset-max-ziplist-value if you are using lots of
smaller sorted sets
Copyright © 2017 HashedIn Technologies Pvt. Ltd.
- Sorted Sets are very expensive memory-wise
- Tweak zset-max-ziplist-entries and
zset-max-ziplist-value if you are using lots of
smaller sorted sets
Copyright © 2017 HashedIn Technologies Pvt. Ltd.
Take the guess work out of your memory analysis.
https://github.com/sripathikrishnan/redis-rdb-tools

Redis memory optimization sripathi, CTO hashedin

  • 1.
    Memory Optimization Sripathi Krishnan,CTO, HashedIn Technologies
  • 2.
    Copyright © 2017HashedIn Technologies Pvt. Ltd. - Ensure the objects don’t have redundant data - Users have recommended products - If you cache users, ensure recommended_products is just a reference
  • 3.
    Copyright © 2017HashedIn Technologies Pvt. Ltd. - Default serialization libraries are not efficient - Use Protobuf / Message Pack / Others - JSON must be compressed
  • 4.
    Copyright © 2017HashedIn Technologies Pvt. Ltd. - Keys in redis have lots of overheads - For smaller strings, combine them into a larger hash - Tweak hash-max-ziplist-entries and hash-max-ziplist-value appropriately
  • 5.
    Copyright © 2017HashedIn Technologies Pvt. Ltd. - Objects are usually saved in hashmap, but the keys are redundant if every object has the same keys - “NamedTuple”: store objects in a list instead - “C like struct”: Use Redis Bitfield command to store fixed length values in a single string
  • 6.
    Copyright © 2017HashedIn Technologies Pvt. Ltd. - Sets in Redis are normally stored as HashTables - But if they only contain integers/longs, they are stored in memory-efficient “intsets” - 10x or more memory reduction if your IDs are numeric only
  • 7.
    Copyright © 2017HashedIn Technologies Pvt. Ltd. - Count Objects? Use HyperLogLog - Check for Existence? Use Bloom Filter You won’t get exact results, but sometimes the memory savings are worth it.
  • 8.
    Copyright © 2017HashedIn Technologies Pvt. Ltd. - Redis Strings can be used as a giant bitmap - You can set/unset/toggle individual bits Useful for things like access control - can this user perform that operation?
  • 9.
    Copyright © 2017HashedIn Technologies Pvt. Ltd. - Sorted Sets are very expensive memory-wise - Tweak zset-max-ziplist-entries and zset-max-ziplist-value if you are using lots of smaller sorted sets
  • 10.
    Copyright © 2017HashedIn Technologies Pvt. Ltd. - Sorted Sets are very expensive memory-wise - Tweak zset-max-ziplist-entries and zset-max-ziplist-value if you are using lots of smaller sorted sets
  • 11.
    Copyright © 2017HashedIn Technologies Pvt. Ltd. Take the guess work out of your memory analysis. https://github.com/sripathikrishnan/redis-rdb-tools