Redis avalanche of cache, cache and cache penetration breakdown

Redis is a non-relational database, compared to other database, it queries extremely fast and can be very high instantaneous concurrency bear. It is often used to cache storage site, in order to reduce the major databases (such as mysql) server pressure.
Redis avalanche of cache, cache and cache penetration breakdown
Use Redis as a cache to time, often there will be cached avalanche breakdown and penetrating questions. What these classic problem? How to solve?
Avalanche Cache
Cache Avalanche simultaneous failure of a large number of Key, Key will request these to the database, the database will also lead to excessive pressure or even hang.
General business platform data will be cached, if all of Key Home expiration time is 12 hours, 12:00 refresh, there is a zero spike activity influx of large numbers of users, the assumption was 6000 requests per second, you can carry the original cache per 5000 live requests, but the cache was all Key are ineffective. At this point one seconds off the 6000 request for all database, which inevitably could not carry, will alarm, and the reactions to DBA may restart the database, but the database has been a new flow rate immediately to the killing.
Solution: Let the time to failure Key's spread out, you can add a random value in a unified time to failure, or to use more sophisticated algorithms dispersed expiration time.
Cache penetration
procedures in dealing with the cache, the cache usually start with the query, if the cache does not get this key is null, it will query from the database, and set to the cache. That query data a certain value does not exist, you need to query from the database, finding data is not written to the cache, which will result in a time that does not exist in the data request should go to the database query result caching penetration.
Simply put, launched a search operation, the value of the cache and the database are not, this will perform a back and forth of this process, read redis, and found no connection to the database and found that no, resulting in penetration cache .
Solution: You can add a layer of filter, the system is considered to be a key illegal interception, returned directly to the client an error message at the system level.
Cache breakdown
Cache is the breakdown for the data cache and the database are not. When the sudden influx of a large number of requests after Key fails, will request to DB, the database leading to excessive pressure and collapse.
The solution to this problem is to:
1, set the focus Key, Key automatically detect hot spots, the expiration time of increased focus Key or set to never expire, or set to logically never expire.
2, plus mutex. When they find no hits Redis, to check the database when performing an update on the operation of the cache lock, the lock who is who gets to update, and then get a start if there is a cache returns received after the lock, not on the investigation and then update the database. (Double check)

Guess you like

Origin blog.51cto.com/1086869/2451308
Recommended