31
Tech Planet 리뷰 Redis Session From Line [email protected]

Techplanetreview redis

Embed Size (px)

Citation preview

Page 1: Techplanetreview redis

Tech Planet 리뷰 Redis Session From Line

[email protected]

Page 2: Techplanetreview redis

시작하기 전에…

• 테크플래닛 2015에서 본 세션에 대한 리뷰입니다.

– 즉 제가 발표한 내용이 아닙니다.

• 해당 내용은 LINE 에서 발표해 주신 내용입니다.

• 강의자료는 여기서 보실 수 있습니다.

– http://readme.skplanet.com/wp-content/uploads/1-6-%EC%84%9C%EC%9B%90%ED%95%84_LINE_LINE-Redis-Clusters.pdf

Page 3: Techplanetreview redis

목차

1. MaxMemory와 Dict Expand 이슈

2. CPU affinity

Page 4: Techplanetreview redis

MaxMemory와 Dict Expand 이슈

Page 5: Techplanetreview redis

Redis Dict 다시 살펴보기

Page 6: Techplanetreview redis

Redis Dict – Redis 기본 자료 구조.

Page 7: Techplanetreview redis

Redis Dict – Hash Table의 확장 #2

Page 8: Techplanetreview redis

Redis Dict – Hash Table의 확장 #3

Page 9: Techplanetreview redis

Redis Dict – Hash Table의 확장 #3

Page 10: Techplanetreview redis

2배씩 늘어납니다.

Page 11: Techplanetreview redis

zmalloc

Page 12: Techplanetreview redis

zmalloc

• 그냥 일반적인 malloc(jemalloc, malloc, tcmalloc) 에 현재 메모리를 얼마나 할당하고 있는지 사용량만 저장함

• used_memory 변수가 증가됨.

Page 13: Techplanetreview redis

freeMemoryIfNeeded

Page 14: Techplanetreview redis

freeMemoryIfNeeded

• Redis 커맨드를 처리하는 processCommand 안에서 maxmemory 설정이 있으면 항상 해당 작업을 호출한다.

• used_memory + Need_memory < maxmemory 가 되도록 메모리 해제 정책에 따라서 메모리 해제를 진행함.

– 언제까지?

– 위의 공식이 성립할때까지…

Page 15: Techplanetreview redis

다시 돌아가서…

Page 16: Techplanetreview redis

아이템이 10억 개.

Page 17: Techplanetreview redis

10억 * 4bytes * 2배 = 8,000,000,000

= 8G

Page 18: Techplanetreview redis

메모리 8G가 갑자기 추가됩니다.

Page 19: Techplanetreview redis

Maxmemory 가 12G 이고, usedmemory 가 8G이면?

Page 20: Techplanetreview redis

4G 정도를 free 해야한다.

Page 21: Techplanetreview redis

시간이 얼마나 걸릴까?

Page 22: Techplanetreview redis

실제로 저도 이런 이슈를 겪어보지는 못했습니다.

Page 23: Techplanetreview redis

다만 원인은 이해가 갑니다. 앞의 내용 때문이죠.

Page 24: Techplanetreview redis

해결책은?

Page 25: Techplanetreview redis

LINE은 미리 시작 hash table 크기를 엄청 키워놓고 시작…

Page 26: Techplanetreview redis

최상 위의 db[i].dict 을 dictExpand를 통해서 미리 키워둔다.

Page 27: Techplanetreview redis

CPU Affinity

Page 28: Techplanetreview redis

NIC Interrupt CPU 와 Redis Process 가 명시적으로 할당되는 CPU를 따로 설정

Page 29: Techplanetreview redis

High Load 상황에서 CPU Usage가 20~30% 까지도 차이가 남.

Page 30: Techplanetreview redis

라인 규모로 Heavy 하게 쓸때 도움이 될듯.

Page 31: Techplanetreview redis

Q & A