1. PRESENTED BY
Scaling Redis to 1M Ops/Sec
Presenter: Jane Paek
Redis Labs, Solution Architect Manager
jane@redislabs.com
2. PRESENTED BY
1 A Shard by Any Other Name?
2 Clustering / Partitioning Options
3 Patterns and Anti-Patterns to Scaling
Agenda:
2 Demo
3 Resources
3 Tools Available for Benchmarking
3. PRESENTED BY
What to Expect from a Single Redis Server Process
1 redis instance = 1 redis-server process = shard
Hostname : port
Localhost: 6379 Lists
Hashes
Bitmaps
Strings
Bit field
Streams
Hyperloglog
Sorted Sets
Sets
Geospatial Indexes
4. strings, ttl
lists, sets,
pub/sub
streams
search
ML
+
Graph Relationships
Graph
RAM + Flash
+ Disk
Client Location /
Proximity Geo
Intelligent Session
Management Hash, Sets
API Rate Limiting Hash
User SessionsHashes, Sets
Where Can You Place Redis?
Pub/Sub Messaging Pub/Sub
JSON Storage
JSON
medium.com
5. PRESENTED BY
Scaling Redis via Database Clustering
• Use multiple shards to create a logical redis database
Node 1
0-4K
Node 2
4K-8K
Node 3
8K – 12K
Node 4
12k - 16K
Logically Clustered Redis Database
?????
6. PRESENTED BY
Scaling Redis – Client Side Sharding - Range Partitioning
• Map ranges of objects into specific Redis instances
Node 1
Keys: a-g
Node 2
Keys: h-o
Node 3
Keys: p-t
Node 4
Keys: u-z
Logically Clustered Redis Database
“Get a”
Which shard holds a? node 1
Connect to node 1 for key a
7. PRESENTED BY
Scaling Redis - Client Side Sharding - Hash with Query Routing
• Redis Cluster API - Hash Keys via CRC16 mod # shards
Logically Clustered Redis Database
“Get a”
What is the hash slot for a? 15495
Which shard holds the slot? 4
Connect to node 4 for key a
Node 1
0-4K
Node 2
4K-8K
Node 3
8K – 12K
Node 4
12k - 16K
8. PRESENTED BY
Scaling Redis via Proxy-Side Sharding
• Clients connect to the Proxy
• Proxy handles the connection to the redis shards
• Single host and port (from the client view)
Node 1
0-4K
Node 2
4K-8K
Node 3
8K – 12K
Node 4
12k - 16K
Logically Clustered Redis Database
Proxy ( translates keys to slots to shards)
10. PRESENTED BY
Patterns and Anti-Patterns to Scaling
• Do
Use Pipelines
Use Unlink vs DEL
Use Connection Pooling
Aim for small value sizes <10kb
Understand time complexity O(1) vs
O(log(N)) vs O(N)
Shard using hash tags {keeptogether}
Monitor Slow Logs
• Be careful of..
Running keys * in prod
Sorted set queries
Persistence (rdb and AoF)
Caching keys without TTL
• Helps to avoid eviction
11. PRESENTED BY
Tools for Benchmarking – memtier-benchmark (Get/Set)
• Memtier-benchmark (Create by Redis Labs)
https://github.com/RedisLabs/memtier_benchmark
• Test Parameters and Options:
-d, -data-size=SIZE Object data size (default: 32)
-n, --requests=NUMBER Number of total requests per client (default: 10000)
-c, --clients=NUMBER Number of clients per thread (default: 50)
-t, --threads=NUMBER Number of threads (default: 4)
--test-time=SECS Number of seconds to run the test
--ratio=RATIO Set:Get ratio (default: 1:10)
--pipeline=NUMBER Number of concurrent pipelined requests (default: 1)
12. PRESENTED BY
Tools for Benchmarking – redis-benchmark (Part of redis distribution)
• Tests for PING, SET, GET, INCR, LISTS, HASH, MSET
• Can specify the command to benchmark
• Test Parameters and Options
-h <hostname> Server hostname (default 127.0.0.1)
-p <port> Server port (default 6379)
-a <password> Password for Redis Auth
-c <clients> Number of parallel connections (default 50)
-n <requests> Total number of requests (default 100000)
-d <size> Data size of SET/GET value in bytes (default 2)
-P <numreq> Pipeline <numreq> requests. Default 1 (no pipeline)
-t <tests> Only run the comma separated list of tests.
13. PRESENTED BY
Examples for redis-benchmark
$ redis-benchmark -h 127.0.0.1 –p 6379
$ redis-benchmark -t set,lpush -n 100000 -q
$ redis-benchmark -n 100000 -q script load "redis.call('set','foo','bar')"
Coming Soon
$ redis-benchmark --cluster -p 7000
$ redis-benchmark -p 7000 --threads 6 --cluster
# If the cluster has three masters, use two threads per master node
•
15. PRESENTED BY
Home of Redis Labs https://redislabs.com/get-started
Redis References https://redis.io
Redis Modules https://redislabs.com/community/redis-modules-hub
Redis Clients https://redis.io/clients
Redis Downloads https://redis.io/download
Redis University https://university.redislabs.com
New Classes April 16, 2019
Introduction to Redis Data Structures 101
Redis for Java Developers
RediSearch
Redis Streams
Redis Resources : Jane Paek - jane@redislabs.com