Upload
dae-myung-kang
View
782
Download
3
Embed Size (px)
Citation preview
KEYS *
di = dictGetSafeIterator(c->db->dict); allkeys = (pattern[0] == '*' && pattern[1] == '\0'); while((de = dictNext(di)) != NULL) { …… stringmatchlen(pattern,plen,key,sdslen(key),0) }
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; } }
FlushAll-Memcache
if (exptime > 0) settings.oldest_live = realtime(exptime) - 1; else /* exptime == 0 */ settings.oldest_live = current_time - 1;
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; }
RDB
Fork(), Cow(Copy on Write)
Heavy Write 시에 메모리 이슈가 발생할 수 있음.
Redis의 Replication은 무조건 Fork()를 하므로 주의
Write Error Case
stop-writes-on-bgsave-error
RDB 생성 옵션이 켜져 있을 때, RDB 생성이 어떤 이유로 실패하면, 위의 옵션으로 인해서 Write 작업이 금지됨.
Info는 되지만, Ping은 실패함
Write Error Case
“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.”
Write Error Case 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; }
AOF Rewrite - AOF 파일의 상태가 특정 조건(파일 사이즈가 얼마 이상일 경우)일 때 - AOF 파일을 현재 상태에 맞춰서 새롭게 생성 - AOF Rewrite도 Fork() 사용하므로 RDB 와 같은 이슈가 발생
메모리 파편화
Redis 는 매번 메모리 할당을 하므로, 부하가 많을 경우, 튀는 경우가 발생.
실제로 Redis -> Arcus 는 전환시에 별 문제가 없었지만, Arcus -> Redis 는 전환시에 튀는 경우가 발생
Slab Allocator Slab 0 Slab 1 Slab 2 … … Slab N
1mb 1mb 1mb 1mb 1mb 1mb 1mb 1mb
Slab Page List
Free Item List
LRU List Slab 0 Slab 1 Slab 2 … … Slab N Head
Slab 0 Slab 1 Slab 2 … … Slab N Tail
Item
Item
Item 밑에 있는 아이템일 수록 사용한지 오래됨.
Eviction Memcached는 slab별 LRU 만 지원
Redis 는 LRU, Random 등을 지원
Twitter에서 사용하는 Twemcache 의 경우는 Eviction 전략만 추가한 Memcached의 변종?
LRU 관리 Memcached는 이전에는 LRU 관리에 이슈가 있었음.
LRU List를 뒤에서 부터 검색해서 메모리를 확보함
다양한 Expire 값을 설정하면, Expire가 짧은 아이템이 앞으로가, 뒤에서 찾지못하고 메모리 할당의 가능성이 큼.
메모리 파편화 Memcached는 메모리 관리를 직접하므로 문제가 덜함.
Redis 는 Jemalloc등을 사용하지만, 메모리 할당을 직접 처리할 수 없으므로 메모리 파편화가 심해질 수 있다.
메모리 파편화 Memcache는 메모리를 자신이 관리하므로, 실제 메모리 부족 시, 기존 데이터를 지울 수 있다.
Redis는 Jemalloc에서는 메모리 Max를 알지 못하므로, 그냥 새로운 Chunk를 할당하게 된다.