Home >Database >Redis >What is redis avalanche

What is redis avalanche

青灯夜游
青灯夜游Original
2019-06-04 10:32:145683browse

What is redis avalanche? The following article will give you a brief introduction, I hope it will be helpful to you.

What is redis avalanche

What is an avalanche?

Because the cache layer carries a large number of requests, it effectively protects the storage layer. However, if the cache as a whole cannot provide services for some reasons, all requests will arrive. Storage layer, the number of calls to the storage layer will increase dramatically, causing the storage layer to also hang up. The English explanation of cache avalanche is running bison, which means that after the cache layer crashes, concurrent traffic will access back-end storage in large quantities like galloping bison.

The simple understanding of cache avalanche is: due to the failure of the original cache (or the data is not loaded into the cache), during the period when the new cache has not arrived (the cache is normally obtained from Redis, as shown below) all the cache should have been accessed All requests go to query the database, which puts huge pressure on the database CPU and memory. In severe cases, it can cause database downtime and system crash.

What is redis avalanche

The cache failure is as shown below:

What is redis avalanche

One scenario where this problem exists is: when the cache server is restarted Or a large number of caches may fail in a certain period of time, so when they fail, a large amount of data will directly access the DB, which puts a lot of pressure on the DB.

The avalanche effect when the cache fails has a terrible impact on the underlying system! So what are the solutions to this problem?

Solution

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

2) Use mutex locks

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

3) For different keys, you can set different expiration times to make the cache invalidation time points inconsistent and try to achieve an even distribution.

4) Never expire

Setting the permanent non-expiration setting in redis ensures that there will be no hot spots, that is, it will not expire physically.

5), Resource Protection

Using Netflix's hystrix, you can isolate the thread pool of various resources to protect the main thread pool.

The above is the detailed content of What is redis avalanche. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:redis cluster principleNext article:redis cluster principle

Related articles

See more