Get the App
SLTechnology News&Howtos  ›  Database  › 

What does redis avalanche mean?

Shulou Source: shulou.com Published: 2022-06-01 01:55:32 10月01日 Update

This article mainly introduces what redis avalanche refers to, has a certain reference value, friends in need can refer to. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

What is an avalanche?

Because the cache layer carries a large number of requests, which effectively protects the storage layer, but if the cache cannot provide service as a whole for some reason, then all requests will reach the storage layer, and the amount of invocation of the storage layer will soar, causing the storage layer to die. The English interpretation of cache avalanche is a fleeing bison, which means that after the cache layer is pawned, concurrent traffic will access the back-end storage in large quantities like a galloping bison.

The popular and simple understanding of cache avalanche is: due to the invalidation of the original cache (or the data has not been loaded into the cache), all requests that should have accessed the cache have gone to query the database during the absence of the new cache (the cache is normally obtained from Redis, as shown below), which will cause great pressure on the database CPU and memory, which will seriously cause database downtime and system crash.

When the cache expires, it is shown below:

A scenario with this problem is when the cache server is restarted or a large number of caches fail in a certain period of time, so that in the event of failure, a large amount of data will directly access the DB, which puts great pressure on the DB.

The avalanche effect of cache failure has a terrible impact on the underlying system! Is there any way to solve this problem?

Solution method

1) set the high availability of redis cluster and DB cluster. If the redis goes down, it can be replaced by another machine immediately. This prevents some of the risks.

2) use mutexes

After the cache expires, the number of threads reading and writing to the database is controlled by locking or queuing. For example, only one thread is allowed to query data and write cache for a key, while other threads wait. In the case of a stand-alone machine, you can use synchronized or lock to solve the problem. In a distributed environment, you can use the setnx command of redis to solve the problem.

3) different key can be set for different expiration time, so that the cache expiration time is different and the average distribution can be achieved as far as possible.

4) never expire

The setting in redis does not expire forever, which ensures that there will be no hot issues, that is, it will not expire physically.

5). Resource protection

Using netflix's hystrix, you can do thread pool isolation for various resources, thereby protecting the main thread pool.

Thank you for reading this article carefully. I hope the editor can share what redis Avalanche refers to is helpful to everyone. At the same time, I also hope that you can support us, pay attention to the industry information channel, and find out if you have any problems. Detailed solutions are waiting for you to learn!

Tags: Caching data avalanches threads databases problems storage time articles protection differences pressures situations methods times systems resources bison clusters services Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MariaDB Shulou Tech Info NVidia Linux