redis additional knowledge --- Cache breakdown, avalanche cache, the cache penetration

  1. Cache penetration

    • Deposit penetration refers to a certain query data does not exist, because the cache is needed from the database query is not hit, can not find the data cache is not written, it will lead to a time that does not exist in the data request should go to the database query, resulting in cache penetration. When large flow, might DB hung up, if someone does not take advantage of the presence of frequent attacks our key applications, this is the loophole.

    • response:

      有很多种方法可以有效地解决缓存穿透问题,最常见的则是采用布隆过滤器,将所有可能存在的数据哈希到一个足够大的bitmap中,一个一定不存在的数据会被这个bitmap拦截掉,从而避免了对底层数据库的查询压力。
      另外也有一个更为简单粗暴的方法,如果一个查询返回的数据为空(不管是数据不存在,还是系统故障),仍然把这个空结果进行缓存,但它的过期时间会很短,最长不超过五分钟
  2. Cache avalanche

    • Refers to the use of the same expiration date when setting up the cache, the cache at the same time lead to failure at some point, lead to all queries fall on the database, resulting in a cache avalanche.

    • response:

      不同的key,设置不同的过期时间,让缓存失效的时间点尽量均匀。
      设置一个随机因子
      尽量分散设置 缓存 
      热点数据设置 较长的缓存时间   冷门数据设置较短的缓存时间
  3. Cache breakdown

    • For some key set expiration time, if these key may be ultra concurrently access certain point in time, it is a very "hot" data. This time, it is necessary to consider the question: cache is "breakdown" of the problem, and this difference is that here avalanche cache for a key cache, the former is a lot of key.
      At a point in time when the cache expires, just at this point in time there are a large number of concurrent requests this Key over, these requests are usually found in the cache expires load data from the backend DB and set back into the cache, this time a large concurrent request It may momentarily overwhelmed by the backend DB.
    • Self-check for updates

Guess you like

Origin www.cnblogs.com/kevin6/p/11799559.html
Recommended