caching solutions with redis

14
Caching Solutions: Redis with Bogdan Hadadea

Upload: george-platon

Post on 06-May-2015

824 views

Category:

Technology


6 download

DESCRIPTION

Caching solutions with Redis - presentation held by Bogdan Hadadea at Open Coffee Tech meetup

TRANSCRIPT

Page 1: Caching solutions   with Redis

Caching Solutions:Redis

with Bogdan Hadadea

Page 2: Caching solutions   with Redis

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

Page 3: Caching solutions   with Redis

1. General Description: Redis

• Creator: Salvatore Sanfilippo• Released: 2009• Written in ANSI C• Single threaded• Open Source• Backed by VMWare• Early adopted by GitHub

Page 4: Caching solutions   with Redis

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

Page 5: Caching solutions   with Redis

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

Page 6: Caching solutions   with Redis

3. Architecture: Redis – Overview

Page 7: Caching solutions   with Redis

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

Page 8: Caching solutions   with Redis

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

Page 9: Caching solutions   with Redis

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

Page 10: Caching solutions   with Redis

3. Architecture: Redis

• Redis Transactions:o No rollbacko Optimistic locking

Page 11: Caching solutions   with Redis

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

Page 12: Caching solutions   with Redis

4. Comparison: Memcached

Page 13: Caching solutions   with Redis

4. Comparison: Memcached

Page 14: Caching solutions   with Redis

5. Conclusion

• Focused on speed• Reliable as database• Steeper learning curve than other solutions• Still improving