caching solutions with redis
DESCRIPTION
Caching solutions with Redis - presentation held by Bogdan Hadadea at Open Coffee Tech meetupTRANSCRIPT
Caching Solutions:Redis
with Bogdan Hadadea
1. General Description: Redis
• NoSQL key-value date store• Like MongoDB, but better• Built-in persistence• More data types
o Stringo Hasho Seto List
• Built-in pub/sub feature• Highly scalable
1. General Description: Redis
• Creator: Salvatore Sanfilippo• Released: 2009• Written in ANSI C• Single threaded• Open Source• Backed by VMWare• Early adopted by GitHub
2. Usage: Redis – Who?
• StackOverflow – 3 layers of cachingo Local cacheo Site cacheo Global cache
• Blizzard – 8 node Redis installo 16GB/instanceo For storing auction house and serving avatars
• Amazon ElastiCache, Redis-to-goo Cache in the cloudo Cache hosting
2. Usage: Redis – What for?
• Redis for cacheo Good to place sessions – hasheso A fine place for high score tracking – sorted sets
• Redis as databaseo Persistence to disko High performance
• Redis as message buso Based on Pub/Sub functionalityo Queues with list structureso Resque – Ruby library for creating background jobs
3. Architecture: Redis – Overview
3. Architecture: Redis
• Request/Response Protocols:o Redis is a TCP server using the client-server model
Request/Response protocol
• Pipelining:o Process multiple requests even if response not read yeto Not paying the RTT (Round Trip Time) for every command
• Limitations:o Responses stored in a queueo Recommended max: 10k commands
• Benchmark: ‘Ping’ – 10k times
3. Architecture: Redis
• Scriptingo Lua interpreter built in ver. > 2.6o Using EVAL and EVALSHAo Conversion between Lua and Redis data typeso redis.call() & redis.pcall()
o Atomicity of scriptso Emitting Redis logs from scriptso EVALSHA in the context of pipelining
3. Architecture: Redis
• Replication: o Master-slave: exact copieso Asynchronous replicationo Master – multiple slaveso Non-blocking replication – master sideo Non-blocking replication – slave side – old dataseto Slaves accept connections from other slaveso Replication for scalabilityo Replication for cost savingo Full/Partial synchronizationo Configure: slaveof 192.168.1.1 6379o Read-only slaveso Slave authentication to mastero Write only when N replicas
3. Architecture: Redis
• Redis Transactions:o No rollbacko Optimistic locking
3. Architecture: Redis
• Publisher/Subscriber messaging paradigmo Decoupling pub-subo Pattern matching subscriptions
• Redis clusteringo Not production ready
• Memory optimizationo Encoding of small data – up to 5x less spaceo Using 32bit instances
• Using hashes to abstract a key-value on top of Redis
4. Comparison: Memcached
4. Comparison: Memcached
5. Conclusion
• Focused on speed• Reliable as database• Steeper learning curve than other solutions• Still improving