58
redis cluster or: distributed systems are hard Jan-Erik Rediger 28. Mai 2015

Redis Cluster - or: distributed systems are hard

Embed Size (px)

Citation preview

Page 1: Redis Cluster - or: distributed systems are hard

redis clusteror: distributed systems are hard

Jan-Erik Rediger28. Mai 2015

Page 2: Redis Cluster - or: distributed systems are hard

who am i?

Hi, I’m Jan-Erik

� Student of Computer Science, RWTH� first Redis-related project: 2010 (an Erlang client)� Maintainer of

� try.redis.io� hiredis� hiredis-rb, hiredis-py, hiredis-node

Page 3: Redis Cluster - or: distributed systems are hard

redis

Page 4: Redis Cluster - or: distributed systems are hard

redis

Redis is an open source, BSD licensed,advanced key-value cache and store. It isoften referred to as a data structure serversince keys can contain strings, hashes, lists, sets,sorted sets, bitmaps and hyperloglogs.

Page 5: Redis Cluster - or: distributed systems are hard

redis

SET redis rocks

HSET meetup.42 name PHPUGDUS

SADD meetups-in-dus 42:PHPUGDUS

ZADD meetups-in-nrw 20150628 PHPUGDUS

LPUSH trivago "meetup host"

Page 6: Redis Cluster - or: distributed systems are hard

limits

Must fit into RAM

No redundancy

Single-threaded

Page 7: Redis Cluster - or: distributed systems are hard

limits

Must fit into RAM

No redundancy

Single-threaded

Page 8: Redis Cluster - or: distributed systems are hard

limits

Must fit into RAM

No redundancy

Single-threaded

Page 9: Redis Cluster - or: distributed systems are hard

overcoming limits

� Sharding� Split data set across nodes� e.g. via Twemproxy or Codis

� Replication� Failover for HA� Sentinel or another system� Scale reads to more instances

Page 10: Redis Cluster - or: distributed systems are hard

overcoming limits

� Sharding� Split data set across nodes� e.g. via Twemproxy or Codis

� Replication� Failover for HA� Sentinel or another system� Scale reads to more instances

Page 11: Redis Cluster - or: distributed systems are hard
Page 12: Redis Cluster - or: distributed systems are hard

redis cluster

Page 13: Redis Cluster - or: distributed systems are hard

redis cluster

� It’s still Redis

� must be fast� must scale� must be simple to use� must give some guarantees

� but it’s a Distributed System

Page 14: Redis Cluster - or: distributed systems are hard

redis cluster

� It’s still Redis� must be fast

� must scale� must be simple to use� must give some guarantees

� but it’s a Distributed System

Page 15: Redis Cluster - or: distributed systems are hard

redis cluster

� It’s still Redis� must be fast� must scale

� must be simple to use� must give some guarantees

� but it’s a Distributed System

Page 16: Redis Cluster - or: distributed systems are hard

redis cluster

� It’s still Redis� must be fast� must scale� must be simple to use

� must give some guarantees

� but it’s a Distributed System

Page 17: Redis Cluster - or: distributed systems are hard

redis cluster

� It’s still Redis� must be fast� must scale� must be simple to use� must give some guarantees

� but it’s a Distributed System

Page 18: Redis Cluster - or: distributed systems are hard

redis cluster

� It’s still Redis� must be fast� must scale� must be simple to use� must give some guarantees

� but it’s a Distributed System

Page 19: Redis Cluster - or: distributed systems are hard

cap - pick two

Page 20: Redis Cluster - or: distributed systems are hard

cp - consistent & partition tolerant

� Higher Latency� Wait for majority of

ACKs

Page 21: Redis Cluster - or: distributed systems are hard

ap - available & partition tolerant

� Eventual Consistency� might require merges

Page 22: Redis Cluster - or: distributed systems are hard

so what is it?

Page 23: Redis Cluster - or: distributed systems are hard

sharding + replication

Page 24: Redis Cluster - or: distributed systems are hard

replication: asynchronous

Page 25: Redis Cluster - or: distributed systems are hard

full mesh

� Heartbeats� Gossip� Failover� Config update

Page 26: Redis Cluster - or: distributed systems are hard

redirections

Page 27: Redis Cluster - or: distributed systems are hard

slot configuration

� Key space split into 16384 slots� Every node serves a subset of the slots� Every node knows the node�slot mapping

Page 28: Redis Cluster - or: distributed systems are hard

single-key operations

> GET redis1) "rocks"

> GET kjdopiqh(error) MOVED 12182 127.0.0.1:7002

Page 29: Redis Cluster - or: distributed systems are hard

multi-key operations

� All keys in same slot: it’s fine

> MGET foo10 foo54061) "hello"1) "world"

Page 30: Redis Cluster - or: distributed systems are hard

multi-key operations

� Keys in different slots: sorry, not possible

> MGET foo bar(error) CROSSSLOT Keys in request don't hash

to the same slot

Page 31: Redis Cluster - or: distributed systems are hard

multi-key operations with hash tags

� Ensure keys map to the same slot

> MGET {foo}.meetup {foo}.city1) "PHPUG"2) "Düsseldorf"

Page 32: Redis Cluster - or: distributed systems are hard

failure detection

Page 33: Redis Cluster - or: distributed systems are hard

node times out: pfail

Page 34: Redis Cluster - or: distributed systems are hard

all remaining nodes see pfail

Page 35: Redis Cluster - or: distributed systems are hard

pfail → fail

Page 36: Redis Cluster - or: distributed systems are hard

force fail, trigger failover

Page 37: Redis Cluster - or: distributed systems are hard

failover

Page 38: Redis Cluster - or: distributed systems are hard

actual failover

Page 39: Redis Cluster - or: distributed systems are hard

actual failover

Page 40: Redis Cluster - or: distributed systems are hard

is it consistent?

Eventually…

� Last Failover wins� Mechanisms to avoid unbound data loss

Page 41: Redis Cluster - or: distributed systems are hard

is it consistent?

Eventually…

� Last Failover wins� Mechanisms to avoid unbound data loss

Page 42: Redis Cluster - or: distributed systems are hard

is it consistent?

Eventually…

� Last Failover wins� Mechanisms to avoid unbound data loss

Page 43: Redis Cluster - or: distributed systems are hard

failure modes

Page 44: Redis Cluster - or: distributed systems are hard

failure: crashes

Page 45: Redis Cluster - or: distributed systems are hard

failure: network split

Page 46: Redis Cluster - or: distributed systems are hard

failure: network split

Page 47: Redis Cluster - or: distributed systems are hard

creating a cluster

Page 48: Redis Cluster - or: distributed systems are hard

configuration

port 7001cluster-enabled yescluster-config-file nodes.confcluster-node-timeout 5000

Page 49: Redis Cluster - or: distributed systems are hard

let them meet

CLUSTER MEET 127.0.0.1 7001

* on every node ;)

Page 50: Redis Cluster - or: distributed systems are hard

more convenient

./redis-trib.rb create --replicas 1 \127.0.0.1:7000 127.0.0.1:7001 \127.0.0.1:7002 127.0.0.1:7003 \127.0.0.1:7004 127.0.0.1:7005

Page 51: Redis Cluster - or: distributed systems are hard

more commands you want to know

CLUSTER ADDSLOTS 42 43 44

CLUSTER SETSLOT 42 NODE ff7831dfe

CLUSTER SETSLOT 42 MIGRATING ff7831dfe

CLUSTER SETSLOT 42 IMPORTING ff7831dfe

Page 52: Redis Cluster - or: distributed systems are hard

and some more

CLUSTER NODES

CLUSTER FAILOVER

CLUSTER REPLICATE ff7831dfe

Page 53: Redis Cluster - or: distributed systems are hard

all cluster commands

redis.io/commands#cluster

Page 54: Redis Cluster - or: distributed systems are hard

nodes.conf

ff7831dfe7fc73f741d5c4663a8020e654f88f22127.0.0.1:7001 myself,master - 0 0 1connected 0-5460

94f5710dab37058784824dc9d2ddb27a693f1336127.0.0.1:7013 slave

a46ff091f49bd28149594dfd2272ebb3aedcdd59 01415873239710 6 connected

vars currentEpoch 6 lastVoteEpoch 0

Page 55: Redis Cluster - or: distributed systems are hard

available clients

� Ruby: redic-cluster� Ruby: redis-rb-cluster� Python: redis-py-cluster� PHP: Predis� Java: Jedis� JavaScript: thunk-redis� .NET: StackExchange.Redis

Page 56: Redis Cluster - or: distributed systems are hard

sources

� redis.io - official site & documentation� cluster-spec - official spec docu� cluster-tutorial - a tutorial� mattsta/redis-cluster-playground - easy to play

around with cluster

Page 57: Redis Cluster - or: distributed systems are hard
Page 58: Redis Cluster - or: distributed systems are hard

the end

Get the slides here:

http://slidr.io/badboy/redis-cluster

Reach me on Twitter: @badboy_

Jan-Erik Rediger - 28. Mai 2015 - PHPUGDUS