Internet applications, cache Breakdown Solution Analysis

Applications use caching to relieve memory read request to the low pressure, it has become almost a standard Internet applications. In this article, we will through common Internet applications cache breakdown scene solution to elaborate.

1. Scene Description      

Cache breakdown problem solved herein, mainly for the following scenario data cache:

  • Using the cache data load lazy loading mode (i.e., very small proportion of heat load data into the cache in advance)

  • Cache exists within an outer form of a stand-alone process for the centralized process or cache buffer

  • The final data stored in the data buffer heat, and the heat data is compared to the proportion of the amount of data is very low

  • Used in reading and writing than the high scenario

Scene seen from the above description, mainly to solve such a program in the cache write high wear problems than the highest price in a cache scenarios, which solution is simplified to the following:

Based on the figure, this embodiment has the following characteristics:

  • Unloaded data is stored in the low-speed buffer (such as a conventional relational database, file system, etc.)
  • Only when the data are used to, it will be loaded into the cache
  • If the data is not hit in the cache, the query from the low-speed memory is loaded into the cache

Scene feature based on the characteristics and the former embodiment described in section can be seen, this embodiment can maximize the cache usage. Program which also can not be ignored cache breakdown problem in that when the risk of a large amount of data query request misses in the cache, the request is transmitted through a low-speed memory, may lead to very slow memory timeout process, even downtime. The occurrence of such scenes might be malicious attacks from the outside, it may also be a normal service request.

2. Solution

Cache breakdown There are two types of solutions: improve the cache hit rate (in advance), low-speed memory protection (afterwards), in the following sections, we will explain in detail based on this second-class solution

2.1 enhance the cache hit rate

The key is to improve the cache hit rate preventive measures, the maximum intercepted data request prior to the low-speed memory, the program is subdivided into the following points, defined as below:

2.1.1 Pre-check

Before the query cache, query the data to be verified, the illegal interception of data queries. Details borrower inquiries, for example, loan number as the primary key data cache, in its simplest validation rules can be: before the loan number five must be "KXDJK" loan number and length must be 37. When requested by the borrower number can not check, data query request is intercepted. An important point is: the complexity of the cache hit rate is proportional to the validation rules, and the other point is that, based on performance requirements, validation rules can be complex, but must maintain high performance, otherwise the advantage of the cache will disappear, using a similar displacement may be extremely complex operation, but performance check method to check.

2.1.2 The null prevention

Data misses in the cache, the low-speed memory can not query the data, if a large number of repeated queries of the data, the low-speed memory will bring great pressure queries. Such scenario may be obtained by the null query to a specific value (to ensure that the particular value must not be the same normal value) is stored in the cache, the cache is complemented by failure mechanism, to ensure that such data in certain units time, queries will only spread through the low-speed memory N times (within a single process cache, and the cluster size N nodes)

2.1.3 Data preload

In some scenarios, legitimate data queries in an instant influx, although the implementation of the pre-check and guard against a null value, still unable to resolve such scenes. And such scenes can be hot and cold through the analysis of past data, before such a scenario occurs, the heat ahead of the data loaded into the cache, which for a higher distribution of hot and cold data analysis requirements, but also the most effective.

2.2 low-speed memory protection

In lifting the cache hit ratio chapters, we have to solve is to reduce the spread through the low-speed memory malicious / illegal request size, and in this chapter, we have to address is when more than low-speed memory data processing capacity legitimate queries influx , how best to carry out protection program is also divided into the following points, explain the following:

2.2.1 Overload Protection

The overload protection means more than the low-speed memory of the processing capability to intercept requests in advance, programs the following elements:

  • Time Limit slow memory unit processing capacity assessment indication may be generally performed by QPS, which is an experimental value, may be obtained by the performance test

  • Current slow memory is handled in the request count per unit time, i.e. current / the number of requests processed per minute per

  • The implementation of protection strategies, the current request is greater than the unit time per unit time limit to process the request, then the request is intercepted

Based on the above points can be seen, the second critical point, i.e., how to record the number of requests processed per unit time the low speed memory, especially in a cluster environment, become more complex, through a centralized high speed counter (e.g., self-energizing Redis mechanism) is performed, which is the upper limit of the low-speed memory of the processing capacity of a means of accurate but expensive solution, the solution can be cheaper maximum processing capacity of the low-speed memory / N (N is the number of nodes in the cluster) as a stand-alone, in memory performs a count operation.

2.2.2 fuse mechanism

After fusing embodiment the overload protection mechanisms in embodiment premise, based defenses, processing capacity than the low-speed memory request is intercepted several times, a data request in the access layer can be determined whether a request to intercept an upper layer based on the response intercepted, without will exceed the processing capacity request has been transmitted to the low-speed memory.

3. Summary of the solution

Recommended reading:

The history of the whole block chain white paper free delivery friends

Guess you like

Origin www.cnblogs.com/daimaxiaxiang/p/12549443.html