Learning redis

Audrius Bugas
Audrius BugasChief Architect at HomeToGo
Learning Redis
The hard way…
Audrius Bugas
Chief architect @ HomeToGo
audrius@hometogo.com
* Kiekvienas komandos narys svarbiausias
Learning redis
4
redis.io
“Redis is an open source (BSD licensed), in-memory data structure
store, used as a database, cache and message broker. It supports
data structures such as strings, hashes, lists, sets, sorted sets with
range queries, bitmaps, hyperloglogs and geospatial indexes with
radius queries”
5
Stage #1
•5-6 application servers

•Single dedicated redis server

•Graceful degradation

•RDB persistence
6
Stage #2
•> 20 application servers

•Search workers starts writing data to
redis
7
Problem #1 - system slowdown
•CPU [OK]

•Disk IOPS [OK]

•Redis response time > 200ms [Slow]

•Connection rate [High]
8
Solution - redis sentinel
9
Solution - stop using databases
10
• SELECT is still an
operations

• flushDB actually ended
up bad. Twice…
Problem #2 - sentinel down
•CPU [OK]

•Disk IOPS [OK]

•Memory [OK]

•Connection rate [High]
11
https://github.com/nrk/predis/pull/527
Really???
Solution - extend
13
Problem #3 - write operations timeout
• CPU [OK]

• Disk IOPS [OK]

• Connection rate [OK]

• Redis response time [OK]

• Write operations timeouts rate > 5% [High]
14
Solution - use reds pipelining
15
Solution - use reds pipelining
16
Write operations timeouts still there…
• Redis write operation performance 6ms vs
10ms before [OK]

• Write operations timeouts rate > 5% [High]
17
Solution - disconnect when done
Problem #4- periodical redis response time
spike
• CPU [OK]

• CPU spikes. ~3 h intervals [Warning]

• Connection rate [OK]

• Redis response time spikes > 500ms. ~3 h
intervals [Warning]
19
Solution - stop using KEYS, SCAN on prod
• On large databases operations leads to
blocking redis

• Change key salt instead of trying find and
delete records

• Always use ttl. Redis has pretty good eviction
policies
20
Problem #5 - periodical redis response time
spike
• CPU [OK]

• CPU spikes. ~1 min intervals [Warning]

• Connection rate [OK]

• Redis response time spikes > 400ms. ~1 min
intervals [Warning]
21
RDB snapshotting
22
Solution - use redis cluster
• Smaller resident set size

• Complicated redis sentinel setup operations

• Exceptions while syncing

• Timeouts while syncing
23
24
Cluster gotchas
• Choosing right node is entirely client responsibility

• Cluster delivers redirects in case wrong node used for
operation

• Potential connection rate problem again!!!
• Map caching/updating is also client responsibility

• Multi-key operation problem
25
phpredis extension
Problem #6 - WTF???
27
“This looks like a classic proxy problem”
28
twemproxy
29
twemproxy
https://github.com/twitter/twemproxy
• Does not support cluster

• Implements own sharding

• No rebalancing
Let’s build our own proxy!
Proxy features
32
• FAST Response time 7ms vs 4ms without proxy

• jruby

• multithreaded 

• Supports Redis Cluster

• Auto hash map refresh

• For now only commands subset
https://github.com/hometogo/redis-proxy
Thank you
Audrius Bugas
Chief architect @ HomeToGo
audrius@hometogo.com
www.linkedin.com/in/audriusb
1 of 34

More Related Content

Featured(20)

ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani30.3K views
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
Project for Public Spaces & National Center for Biking and Walking6.9K views
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago25.1K views
9 Tips for a Work-free Vacation9 Tips for a Work-free Vacation
9 Tips for a Work-free Vacation
Weekdone.com7.2K views
I Rock Therefore I Am. 20 Legendary Quotes from PrinceI Rock Therefore I Am. 20 Legendary Quotes from Prince
I Rock Therefore I Am. 20 Legendary Quotes from Prince
Empowered Presentations142.8K views
How to Map Your FutureHow to Map Your Future
How to Map Your Future
SlideShop.com275.1K views
Read with Pride | LGBTQ+ ReadsRead with Pride | LGBTQ+ Reads
Read with Pride | LGBTQ+ Reads
Kayla Martin-Gant1.1K views

Learning redis