Cache Hit Ratio

Source: Internet
Author: User

When a program needs a data in the K+1 layer, d is first searched in its cache K layer. If the data is just in the K-tier, it is called a cache hit.

When the end user accesses the accelerator node, it is called a hit if the node has cached the data to be accessed, and if not, it needs to be taken back to the original server, just without a hit.

The process of fetching data is synchronized with user access, so even if the new data is re-fetch, the user will not feel the delay.

Hit ratio = number of hits /(number of hits + no hits)

Cache Hit ratio is one of the important factors to judge the acceleration effect.

The cache hit ratio depends on a number of factors:

The application scenario looks at the frequency of access, a cache that is rarely accessed equals no effect. Generally speaking, an internet site is a very good scenario for caching applications. The smaller the granularity of the cached granularity , the higher the hit rate, and the object cache is currently the least granular , so the chance of being hit is higher.
For example: You visit the current page, browse the post, then for the ORM, you need to send n sql, the individual posts of the user object. Obviously, if this user is keep abreast in other posts, you can take the user object directly from the cache when you access that post.
The design architecture of the architecture is designed to have a critical impact on cache hit ratios.
For example, how you should try to avoid caching failures, how to provide frequent access to data caching problems, these are the test of the architect level of the place.
For example, for the forum, you need to record the number of visits per topic, so every time someone visits this topic, then the topic table will update once, what does that mean? The object cache for topic is not valid, and each access is updated with the cache. Then you can think of some ways, such as adding an intermediate variable to record the number of clicks, each accumulated a certain click to update the database once, thus reducing the frequency of cache failure.
Cache capacity and cache lifetime cache are too small, resulting in frequent LRU, will also reduce the hit rate, the cache validity period is too short also cause cache hit rate drop.

So cache hit rate problem can not be generalize, must say hit rate is very low or high hit rate. But if you have a good grasp of the cache, and consciously adjust the architecture of the application, to decompose the granularity of the cache, it will always bring a high rate of hit.

Cache Hits and locality

Why a good local program can have better performance

Time locality: Because of temporal locality, the same data object is used multiple times. Once a data object is entered from the k+1 layer into the K-tier cache, it is expected to be referenced multiple times. This can save a lot of time spent on visits.

Using spatial locality: Suppose that cache K can store n blocks of data. When an array is accessed, because the arrays are stored continuously, when the first element is accessed, a total of n elements (the cache k has n blocks) after the first element are copied to the cache k, which can be obtained directly from the cache when accessing the second element to the nth element, thereby improving performance.

Similarly, when the nth element is accessed, n is not in the cache, and the cache manager copies the elements from N to 2n into the cache, which can be accessed directly in the cache.

With spatial locality, we want to compensate for the time it takes to copy these blocks after we have access to other objects in the cache.

Cache Hit Ratio

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.