Home > Back-end >  About redis cache avalanche, penetration, the problem of breakdown
About redis cache avalanche, penetration, the problem of breakdown

Time:10-12

The original link https://news.html5.qq.com/share/4479888108403640388? Url=https%3A%2F%2Fpost.mp.qq.com % 2 fkan % 2 farticle % 2 f1001006561816-846442226. The HTML % 3 f_wv % 3 d2147483777%26 sig % 3 dc5f06302bddb0208a4ae2b227cd9bf5a % 26 article_id % 3 d846442226%26 time % 3 d1578368600%26 _pflag % 3 d1%26 x5prefetch % 3 d1 & amp; Cardmode=1 & amp; dataSrc=https://bbs.csdn.net/topics/331&docId=4479888108403640388&queryId=&sh_sid=&subjectId=1090319&zimeitiId=qbKd_1001006561816

What is an avalanche? Is cached in the same time large area fails, all requests on the database, the database cannot afford so much request, for an instant the database down, at that time, you are like a cat on hot bricks, the controls can only restart the database, after the restart, found that just up a little later, broke down again, if not solve, even have to tidy up home,

1, build a redis cluster, and guarantee the high availability cluster (master-slave + sentry), select the appropriate memory elimination mechanism,

2, in the key set expiration time, plus a random number, so that you can avoid the key at the same time large area fails, example:

SetRedis (Key, value, time + math.h random () * 10000)

3, be persistent, RDB + AOF, restart automatically restore data

Here mention digression, how to handle the cache avalanche in application layer, you can use local ehcache + Hystrix current-limiting downgrade, familiar with the classmate of micro service should be not unfamiliar to Hystrix,


Own the player signed a contract, deal! Real NBA team management! Advertising
King NBA
Immediately download
2, through

Query cache through referring to the requests of the Key is not in the cache, but a direct request to the database, such as the Key to save the database id, request users with less than zero, or a very large value such as Integer. MAX_VALUE () to request, at this time upon the request of all falls in the database, bypass the cache, then can solve:

1, the interface parameter validation, do not conform to the parameters of direct return.

2, the Key does not exist when the cache null values, and set up a relatively short expiration time,

3, the bloom filter

4, gateway IP layer do not normal request block processing

3, the breakdown


Breakdown is referring to the cache, a hot key expired, a large number of requests into the database at the same time, lead to database collapsed, hot key means to request very high frequent concurrency key, for example: a strong armoured vehicles, were machine gunned may not matter too much, can withstand, but was hit by a penetrator, instant and the hot key is like a penetrator,

1, set up hot data never expire

2, the bloom filter

4, the cached data write consistency

This is in the process of using the cache can't avoid the problem, about this problem to discuss each have each view, such as

1, update the cache first, then update the database

2, update the database and then update cache

3, delete the cache to update the database

Etc etc.

Recommended the third method, according to know facebook is also this way,