cache governance

57
CACHE Governance [email protected]

Upload: dae-myung-kang

Post on 12-Jul-2015

1.305 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Cache governance

CACHE Governance

[email protected]

Page 2: Cache governance

오늘의 주제 캐시의 특성을 비교한다.

적절한 캐시를 선택한다.

Page 3: Cache governance

대상 Memcached

Arcus

Redis

Page 4: Cache governance

예외 다른 캐시들은 비교하지 않습니다.

Page 5: Cache governance

이유 안 써봐서, 잘 모릅니다.

Page 6: Cache governance

결론

Page 7: Cache governance

결론

M

A

R

자료구조

String K/V

Set/List B+ Tree

Set/List Sorted Set

MAX Size

Chunk 1MB

Chunk 1MB

512MB

복제

X

X

O

저장

X

X

O

Cluster

3rd party

자체

Redis Cluster

메모리 관리

slab

slab

malloc

Client

1

3

1

Page 8: Cache governance

자료구조

M

A

R

자료구조

String K/V

Set/List B+ Tree

Set/List Sorted Set

Page 9: Cache governance

Memcached Key/Value 만 지원

Atomic 한 incr/decr 지원

Page 10: Cache governance

Arcus Set/list/B+ Tree 지원

Collection 별 아이템 수 제한이 존재

Collection 별 개별 아이템 크기 제한이 존재(B+ Tree item은 4096 이하만…)

overflow 등에 대한 정책 결정 가능

Page 11: Cache governance

Arcus Prefix별 삭제 기능이 있음

Page 12: Cache governance

Redis Set/list/Sorted Set 지원

Collection에 대한 특별한 제약이 없음

HyperLogLog는 매우 파워풀…

Page 13: Cache governance

데이터 Size

M

A

R

MAX Size

Chunk 1MB

Chunk 1MB

512MB

Page 14: Cache governance

데이터 Size Memcached는 Key + Value Size

Chunk의 크기가 Item의 최대 크기

Redis는 Key, Value 따로 따로

Page 15: Cache governance

Replication

M

A

R

복제

X

X

O

Page 16: Cache governance

Replication Repcached. Mcrouter(facebook).

Arcus도 준비중.

Page 17: Cache governance

Replication Redis Diskless Repl >= 2.8.18

Redis의 Repl은 위험할 수도 있다. (fork 이슈)

Diskless Repl 이 생기면서 EC2 등에서 EBS를 사용할 때의 네트웍 부하를 줄일 수 있다.

Page 18: Cache governance

Persistent

M

A

R

저장

X

X

O

Page 19: Cache governance

Persistent Redis: AOF, RDB AOF, RDB는 모두 전체 데이터

AOF, RDB는 서로 상관없는 저장방식

Page 20: Cache governance

Cluster

M

A

R

Cluster

3rd party

자체

Redis Cluster

Page 21: Cache governance

Cluster Redis Cluster는 아직 검증이 안됬음.

Arcus Cluster는 Zookeeper와 연동

Memcache는 Moxi라는 것이 존재

Page 22: Cache governance

3rd Cluster Redis/Memcache 를 위한 Twemproxy 라는 것도 존재.

모든 명령을 지원하지 않음. - ex (인터섹션등의 콜렉션 간 명령)

Page 23: Cache governance

3rd Cluster Twemproxy를 쓸 때, python-memcached Library를 사용하면 delete_multi 호출이 제대로 안됨.

Page 24: Cache governance

3rd Cluster Redis/Memcache with Proxy

Client

Proxy

R/M

R/M

R/M

R/M

Proxy

Page 25: Cache governance

3rd Cluster Proxy를 거치면서 Hop 이 존재, Latency가 추가된다.

Page 26: Cache governance

Redis Cluster Redis Cluster

Client

Redis

Redis

Redis

Gossip

Slot 1

Slot 2

Slot 3

Page 27: Cache governance

Redis Cluster Redis Cluster

Client

Redis

Redis

Redis

Gossip

Slot 1

Slot 2

Slot 3

Set A 123

Page 28: Cache governance

Redis Cluster Redis Cluster

Client

Redis

Redis

Redis

Gossip

Slot 1

Slot 2

Slot 3

Slot3 is Redis3

Page 29: Cache governance

Redis Cluster Redis Cluster

Client

Redis

Redis

Redis

Gossip

Slot 1

Slot 2

Slot 3 Set A 123

Page 30: Cache governance

Redis Cluster Redis Cluster

Client

Redis

Redis

Redis

Gossip

Slot 1

Slot 2

Slot 3

OK

Page 31: Cache governance

Redis Cluster Redis Cluster는 라이브러리 지원이 필요함. 현재 Ruby/Jedis 정도만 지원.

Page 32: Cache governance

Arcus Arcus Cluster with Zookeeper

Client

Arcus

Arcus

Arcus

ZooKeeper

Page 33: Cache governance

Arcus Arcus Cluster with Zookeeper

Client

Arcus

Arcus

Arcus

ZooKeeper

Page 34: Cache governance

Arcus Arcus Cluster with Zookeeper

Client

Arcus

Arcus

Arcus

ZooKeeper

Arcus2 is dead

Page 35: Cache governance

Arcus 서버 목록 관리를 Zookeeper 사용

빌드시에 Zookeeper를 사용하지 않도록 하면 일반 memcache 처럼 사용가능

Page 36: Cache governance

메모리 관리?

M

A

R

메모리 관리

slab

slab

malloc

Page 37: Cache governance

메모리 관리? Redis 는 매번 메모리 할당을 하므로, 부하가 많을 경우, 튀는 경우가 발생.

실제로 Redis -> Arcus 는 전환시에 별 문제가 없었지만, Arcus -> Redis 는 전환시에 튀는 경우가 발생

Page 38: Cache governance

메모리 관리? Memcached/Arcus slab등을 통해서 잦은 메모리 할당이 없음.

Page 39: Cache governance

Slab Allocator Slab 0 Slab 1 Slab 2 … … Slab N

1mb 1mb 1mb 1mb 1mb 1mb 1mb 1mb

Slab Page List

Free Item List

Page 40: Cache governance

LRU List Slab 0 Slab 1 Slab 2 … … Slab N Head

Slab 0 Slab 1 Slab 2 … … Slab N Tail

Item

Item

Item 밑에 있는 아이템일 수록 사용한지 오래됨.

Page 41: Cache governance

Eviction Memcached는 slab별 LRU 만 지원

Redis 는 LRU, Random 등을 지원

Twitter에서 사용하는 Twemcache 의 경우는 Eviction 전략만 추가한 Memcached의 변종?

Page 42: Cache governance

LRU 관리 Memcached는 이전에는 LRU 관리에 이슈가 있었음.

LRU List를 뒤에서 부터 검색해서 메모리를 확보함

다양한 Expire 값을 설정하면, Expire가 짧은 아이템이 앞으로가, 뒤에서 찾지못하고 메모리 할당의 가능성이 큼.

Page 43: Cache governance

LRU 관리 Arcus는 뒤에서 부터 LRU List를 검색하더라도, 처음까지 전부 체크함.

모두 한번에 체크하는 것은 아니라, 매 텀마다, 이전 기록을 바탕으로 검색

Page 44: Cache governance

LRU 관리 최근 버전의 Memcache 는 LRU_Crawler라는 스레드가 추가됨.

Memcached는 독립 스레드에서, Arcus 는 해당 LRU동작을 확장

Page 45: Cache governance

LRU 관리 Redis 도 매 커맨드가 실행되기 전에 약 100여개 정도 랜덤하게 Eviction 정책에 따라서 Key를 지움.

Page 46: Cache governance

메모리 파편화 Memcached는 메모리 관리를 직접하므로 문제가 덜함.

Redis 는 Jemalloc등을 사용하지만, 메모리 할당을 직접 처리할 수 없으므로 메모리 파편화가 심해질 수 있다.

Page 47: Cache governance

메모리 파편화

Page 48: Cache governance

메모리 파편화 Memcache는 메모리를 자신이 관리하므로, 실제 메모리 부족 시, 기존 데이터를 지울 수 있다.

Redis는 Jemalloc에서는 메모리 Max를 알지 못하므로, 그냥 새로운 Chunk를 할당하게 된다.

Page 49: Cache governance

클라이언트

M

A

R

Client

1

3

1

Page 50: Cache governance

클라이언트 Arcus는 신뢰할 만한 클라이언트 라이브러리가 C/Java 두 가지 뿐임.

Memcached 와 Redis는 다양한 클라이언트가 존재.

Page 51: Cache governance

다시 결론

M

A

R

자료구조

String K/V

Set/List B+ Tree

Set/List Sorted Set

MAX Size

Chunk 1MB

Chunk 1MB

512MB

복제

X

X

O

저장

X

X

O

Cluster

3rd party

자체

Redis Cluster

메모리 관리

slab

slab

malloc

Client

1

3

1

Page 52: Cache governance

결론 서비스에 적합한 걸 적절히 골라쓰자.

실버 불렛 따위는 없음.

Page 53: Cache governance

Thank you!

Page 54: Cache governance

그외 이슈들 캐시는 얼마나 둬야 할까? 또는 사이징?

Multiget Hole 문제

로컬 캐쉬

Page 55: Cache governance

캐시 사이징 최근의 추세는 캐시빨…

데이터량, 처리 속도등을 고려해야 함

캐시 서버가 몇대까지 죽어도 괜찮을까?

장비가 많은것 보다는 좋은 장비에 여러 개 띄우는게 더 유리…

Page 56: Cache governance

로컬 캐쉬 보통은 Remote Cache

Network, Latency, 성능등의 이슈

적절한 로컬 캐쉬를 사용하면 유리

Expire Time을 짧게 가져감

Page 57: Cache governance

Multiget Hole 친구의 정보를 가져올 때…

캐시 서버가 1대에서 3대로 늘면…

정말 캐시 서버의 부하는 1/3일까요?

내 친구 모두를 가져오면…