Redis cache penetration, cache avalanche, cache breakdown - low-hill/Knowledge GitHub Wiki
Cache penetration ์กด์ฌ ํ์ง ์๋ ๋ฐ์ดํฐ๋ฅผ ์กฐํํ๋๊ฒ์ ๋ปํ๋ค. storage layer์ ์กด์ฌํ์ง ์๋ ๋ฐ์ดํฐ๋ cache์ ์ ์ฅ ๋์ง ์๊ธฐ ๋๋ฌธ์ non-existent ๋ฐ์ดํฐ๊ฐ ๋ฐ์ํ๋๋ฐ ๋ฐ์ดํฐ๊ฐ ์์ฒญ๋ ๋๋ง๋ค DB์์ ์กฐํํ๊ธฐ์ ์บ์ฑ์ ์๋ฏธ๋ฅผ ์๊ฒ ๋๋ค. traffic์ด ๋ง์ผ๋ฉด DB์ ๋ถํ๊ฐ ๊ฑธ๋ฆฌ๊ณ ์กด์ฌํ์ง ์๋ ํค๋ก ์ ์์ ์ธ ๊ณต๊ฒฉ์ ํ ์ ์๋ค.
-
cache empty data
์ฟผ๋ฆฌ์์ ๋ฐํ๋ ๋ฐ์ดํฐ๊ฐ ๋น์ด ์๋ ๊ฒฝ์ฐ ๋น ๊ฒฐ๊ณผ๋ฅผ ์บ์ฑํ๊ณ ๋ง๋ฃ ์๊ฐ์ 5๋ถ ์ดํ๋ก ์งง๊ฒ ์ค์ ํ๋ค.
-
Bloom filter
Bloom filter๋ฅผ ํ์ฉํ์ฌ ์กด์ฌํ์ง ์๋ ๋ฐ์ดํฐ๋ฅผ ํํฐ๋งํ์ฌ ์์ฒญ์ด ๋ฐฑ์๋๋ก ์ ์ก๋๋ ๊ฒ์ ๋ฐฉ์งํ ์ ์๋ค.
redisson๋ก Bloom filter ๊ตฌํ ํ ์ ์๋ค. redission bloom filter ์์ค์ฝ๋ ์ฐธ๊ณ
RBloomFilter<String> bloomFilter = redisson.getBloomFilter("bloomFilter");
bloomFilter.tryInit(100_000_000, 0.03);
bloomFilter.add("a");
bloomFilter.add("b");
bloomFilter.add("c");
bloomFilter.getExpectedInsertions();
bloomFilter.getFalseProbability();
bloomFilter.getHashIterations();
bloomFilter.contains("a");
Redis ๋ค์ด ํน์ ๋๋์ cache key๊ฐ ๋์์ ๋ง๋ฃ๋์ด ๋ชจ๋ ์์ฒญ์ ๋ํด DB์์ ์กฐํํ๊ธฐ ๋๋ฌธ์ DB์ ๋ถํ๊ฐ ๋ฐ์ํ๊ณ ๋ค์ด์ด ๋ ์ ์๋ค. ํด๋น ๊ฒฝ์ฐ ๋ฐ์ดํฐ ์บ์ฑ ์ ๋ง๋ฃ ์ผ์ ํ ๋ฒ์์ random๊ฐ(1-5๋ถ)์ผ๋ก ์ค์ ํ๋ค. ์) TTL -> 30+1~5
hot key problem์ผ๋ก๋ ์๋ ค์ง cache breakdown์ key์ ๋์๋ค๋ฐ์ ์ธ request ๋ฐ์์ผ๋ก redis๊ฐ ๋ค์ด๋๊ณ ์๋ง์ ์์ฒญ์ ๋๋น์ ์ํฅ์ ๋ฏธ์น๋ค.
-
Mutex
ํ๋์ ์ค๋ ๋์์ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ฟผ๋ฆฌํ ์ ์์ผ๋ฉฐ ๋ค๋ฅธ ์ค๋ ๋๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์ฟผ๋ฆฌํ๋ ์ค๋ ๋๊ฐ ์คํ์ ์๋ฃํ๊ณ ๋ฐ์ดํฐ๋ฅผ ์บ์์ ๋ค์ ์ถ๊ฐํ ๋๊น์ง ๋๊ธฐ
-
hotspot data never expires
ํค์ ํด๋น๋๋ value์ ๋ง๋ฃ์๊ฐ์ ์ ์ฅํ์ฌ ๋ง๋ฃ์๊ฐ์ ๋๋ฌํ์์ ๋ ๋ฐฑ๊ทธ๋ผ์ด๋์์ ๋น๋๊ธฐ๋ก ์บ์ฑ๋๋ค.
https://devpress.csdn.net/redis/62f658c17e6682346618b138.html https://www.alibabacloud.com/knowledge/developer1/detailed-explanation-caching-problems