redis acc

93
REDIS Management & Cell Architecture [email protected]

Upload: dae-myung-kang

Post on 15-Jan-2015

10.118 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Redis acc

REDIS Management & Cell Architecture

[email protected]

Page 2: Redis acc

Redis.io

Page 3: Redis acc

Redis/Twemproxy Contributor

카카오 홈 개발자

Page 4: Redis acc

Agenda REDIS Management REDIS HA CELL Architecture

Page 5: Redis acc

Agenda REDIS Management REDIS HA CELL Architecture

Page 6: Redis acc

Redis Single Threaded In Memory

Persistent Replication

Collections

Page 7: Redis acc

Redis is Single Threaded!

Page 8: Redis acc

Single Thread Means!

Page 9: Redis acc

Don’t execute long task.

Page 10: Redis acc

Example: Keys command Flushall/flushdb command

Page 11: Redis acc

O(n)

Page 12: Redis acc

Keys *

di = dictGetSafeIterator(c->db->dict); allkeys = (pattern[0] == '*' && pattern[1] == '\0'); while((de = dictNext(di)) != NULL) { …… stringmatchlen(pattern,plen,key,sdslen(key),0) }

Page 13: Redis acc

Memcache’s flush is faster than Redis’s flush.

Page 14: Redis acc

Memcache’s flush is faster than

Redis’s flush?

Page 15: Redis acc

FlushAll-Redis for (i = 0; i < ht->size && ht->used > 0; i++) { dictEntry *he, *nextHe; if ((he = ht->table[i]) == NULL) continue; while(he) { nextHe = he->next; dictFreeKey(d, he); dictFreeVal(d, he); zfree(he); ht->used--; he = nextHe; } }

Page 16: Redis acc

FlushAll-Memcache

if (exptime > 0) settings.oldest_live = realtime(exptime) - 1; else /* exptime == 0 */ settings.oldest_live = current_time - 1;

Page 17: Redis acc

FlushAll-Memcache if (settings.oldest_live != 0 && settings.oldest_live <= current_time && it->time <= settings.oldest_live) { do_item_unlink(it, hv); do_item_remove(it); it = NULL; }

Page 18: Redis acc

FlushAll

Cache Item Count Time

Memcache 1,000,000 1~2ms

Redis 1,000,000 1000ms(1 second)

Page 19: Redis acc

Redis Single Threaded In Memory

Persistent Replication

Collections

Page 20: Redis acc

In Memory Fast but can’t store big data. 32bit: Maximum 3G Data in Memory 64bit: No Max memory. using swap memory in OS.

Page 21: Redis acc

Redis Single Threaded In Memory

Persistent Replication

Collections

Page 22: Redis acc

Collections Memcached supports just K-V List Set Sorted Set Hash

Page 23: Redis acc

Don’t insert too many items into one collections.

Page 24: Redis acc

Delete collections

Item Count Time

list 1,000,000 1000ms(1 second)

set

Sorted set

hash

Page 25: Redis acc

Redis Single Threaded In Memory

Persistent Replication

Collections

Page 26: Redis acc

Redis can make its memory snapshot.

Page 27: Redis acc

RDB is not Relation DBMS.

Page 28: Redis acc

RDB is redis snapshot name.

Page 29: Redis acc

Fork()

Page 30: Redis acc

RDB - BAD • Bad Performance in Large memory.

• Twice memory problem.

• Denying write problem when storing RDB fails.

• If you just want Cache. Turn off RDB

Page 31: Redis acc

RDB – Large Memory • Performance is relevant to Memory

Size.

17.1 GB 34.2 GB

68.4 GB

117 GB

Page 32: Redis acc

RDB – Twice Memory • fork() and COW(copy on write) Issue

–In Write Heavy System:

Page 33: Redis acc

RDB – Twice Memory

Page 34: Redis acc

RDB – Twice Memory

Page 35: Redis acc

RDB – Twice Memory

Page 36: Redis acc

Real Case Study • Background

–Can’t write to Redis Server

–Sentinel doesn’t find Server’s failure.

Page 37: Redis acc

Real Case Study • Reason –If redis fails to save RDB, Redis basically

denies write operations from client.

–“MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.”

Page 38: Redis acc

Real Case Study • Reason if (server.stop_writes_on_bgsave_err &&

server.saveparamslen > 0 && server.lastbgsave_status == REDIS_ERR && c->cmd->flags & REDIS_CMD_WRITE) { flagTransaction(c); addReply(c, shared.bgsaveerr); return REDIS_OK; }

Page 39: Redis acc

Real Case Study • Solution #1

• Solution #2

config set stop-writes-on-bgsave-error no

Turn off RDB Setting

Page 40: Redis acc

AOF

Page 41: Redis acc

AOF is append only file.

Page 42: Redis acc

AOF memorizes all requests.

Page 43: Redis acc

AOF *3\r\n$3\r\nset\r\n$1\r\nA\r\n$3\r\n123\r\n*3\r\n$3\r\nset\r\n$1\r\nB\r\n$3\r\n123\r\n*3\r\n$3\r\nset\r\n$1\r\nC\r\n$3\r\n123\r\n

Page 44: Redis acc

AOF *3 $3 Set $1 A ……

Page 45: Redis acc

AOF Rewrite When size of AOF grows than redis rewrite memory state to AOF.

Page 46: Redis acc

Redis Single Threaded In Memory

Persistent Replication

Collections

Page 47: Redis acc

Redis support master/slave replication

Page 48: Redis acc

Replication •Support Chained Replication

Master 1st Slave 2nd Slave

1st slave is master of 2nd slave

Page 49: Redis acc

Replication

Master Slave replicationCron

Health check

Page 50: Redis acc

Replication

Master Slave replicationCron

Health check

Page 51: Redis acc

Replication

Master Slave replicationCron

When master reruns, Resync with Master

Page 52: Redis acc

Mistake: Replication

Master Slave replicationCron

Slave will has no data after resyncing

If master has no data.

Page 53: Redis acc

Replication Don’t forget “slave of no one”

Page 54: Redis acc

When Redis forks… 1. BGSAVE(RDB) 2. AOF Rewrite(AOF) 3. Replication(RDB) even though, you turned it off

Page 55: Redis acc

Agenda REDIS Management REDIS HA CELL Architecture

Page 56: Redis acc

Redis Sentinel

Page 57: Redis acc

What Redis Sentinel

do?

Page 58: Redis acc

1. Check Redis Liveness

Page 59: Redis acc

1. Check Redis Liveness -Subjective Down -Objective Down

Page 60: Redis acc

2. Choose good slave.

Page 61: Redis acc

Good Slave NOT SDOWN, ODOWN, DISCONNECTED

NOT DEMOTE

Ping reply > info_validity_time

Slave_priority != 0

Info reply > info_validity_time

Page 62: Redis acc

Choose new master

Sort Slave Priority

Runid

Page 63: Redis acc

3. Promote it

Page 64: Redis acc

Promoting Send Slaveof no one to new master

Send Slaveof [new master ip] [addr] to Other redis

Notify new master to clietns +switch-master

Set DEMOTE mark to old-Master

Page 65: Redis acc

Is Sentinel Really Good?

Page 66: Redis acc

Not Mature #1

Page 67: Redis acc

Sentinel Conf port 26379 sentinel monitor mymaster 127.0.0.1 6379 2 sentinel down-after-milliseconds mymaster 2000 sentinel can-failover mymaster yes sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 900000

Page 68: Redis acc

Quorum Count sentinel monitor mymaster 127.0.0.1 6379 2

We should check this count.

Page 69: Redis acc

Sentinel Conf sentinel down-after-milliseconds mymaster 2000

If this value is Too small, It can cause some trouble.

-sdown/+sdown loop

Page 70: Redis acc

Compare with Zookeeper Conf tickTime=2000 dataDir=/var/zookeeper clientPort=2181 initLimit=5 syncLimit=2 server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888

Page 71: Redis acc

Not Mature #2

Page 72: Redis acc

If redis is down, when redis is loading data(RDB,

AOF), sentinel can’t register redis.

Page 73: Redis acc

Even though, Sentinel is not mature. It is useful.

Page 74: Redis acc

Redis Failover

Page 75: Redis acc
Page 76: Redis acc

Twemproxy

Page 77: Redis acc

Twemproxy Redis

Redis

Redis

Client

Client

Client

Client

Client

Client

hashing

Page 78: Redis acc

Twemproxy Pros

One connection per server Zero Copy Multi Hashing Algorithm Support Nickname

Page 79: Redis acc

Twemproxy Cons

Not Support Full Command of Redis(Pub/Sub or MULTI)

Not Support HA

Page 80: Redis acc

Twemproxy

Redis

Redis

Redis

Twemproxy

Twemproxy

L4

Page 82: Redis acc

HA Proxy

HA Proxy

VRRP Twemproxy

Twemproxy

Twemproxy

Redis Master

Redis Slave

Redis Slave

Shard

Redis Master

Redis Slave

Redis Slave

Shard Sentinel

Agent Pub/Sub

Restart

Page 83: Redis acc

Sharding

Page 84: Redis acc

Sharding

WEB/AS

Master Master Master User A Data User C Data User D Data

User B Data User X Data User Z Data

User Y Data User E Data User F Data

Page 85: Redis acc

Cell Architecture

Cell 0 Cell 1 Cell 2

User Cell Info Server

ID: CharSyam

CellID: 1, Status: Normal

Get/set

Page 86: Redis acc

Cell Architecture

A Cell is Full-Set Can serve Users

Page 87: Redis acc

Cell Examples #1

WEB/AS

Master Slave

WEB/AS WEB/AS

Page 88: Redis acc

Cell Examples #2

WEB/AS WEB/AS WEB/AS

Master

Slave Slave Slave

READ only WRITE only

Page 89: Redis acc

Failure of Cell Architecture

Cell 0 Cell 1 Cell 2

User Cell Info Server

ID: CharSyam

CellID: 1, Status: Normal

Can’t Service

Page 90: Redis acc

Failure of Cell Architecture

Cell 0 Cell 1 Cell 2

User Cell Info Server

ID: CharSyam

Can’t response

Get/set

Page 91: Redis acc

• Benefits

–Easy to extend

–Failure is limited to some Users in same cell.

–Can deploy specific feature to some cell users.

• Liabilities

–To need more servers.

• To build full-set

Cell Architecture

Page 92: Redis acc

Q&A

Page 93: Redis acc

Thank you