Cache application in website architecture (4) cache Monitoring and Management

Source: Internet
Author: User

It is quite convenient to use the cache service added to the web system. Currently, many solutions are available, such as Microsoft's Enterprise Library and memcached. However, it is not very easy to monitor and manage the cache in a project. For example, to monitor which items on the cache server use the cache, the specific number of keys, size, hit rate of a single key, expiration time, and other information. With this information, it is very easy to troubleshoot why the memory is quickly used up. If the manual expiration cache service is provided, it will be better. Sometimes, due to data errors, the cache needs to be invalidated urgently. This method has the least impact.

This article summarizes the Cache Management for memcached.

In fact, memcached also provides some cache statistics, such as the total number of current caches, the amount of memory used, the total number of retrieved records, the total number of writes, and the total number of hits, however, the granularity of such statistics is too large:

1: it cannot be specific to a single key. If we want to calculate the hit rate of a key, it will be difficult.

2: You cannot analyze which items in the system use the key, which occupies more keys and has more memory.

3: manual expiration cannot be implemented. This requirement is also very helpful in some special situations.

 

Since memcached itself does not provide, I use a flexible method to record our specific information.

First, we introduce a concept: partition, which can be understood as hard disk partitions on the computer. Users can place different files on different partitions, which is easier to manage, there are sub-partitions under the same partition, just like files on the computer, the sub-partition below is the specific key, for our cache background management, you can understand this, A project can be allocated as a partition, which can be divided into different sub-partitions by project function module. The sub-partitions are scattered with N multiple keys.



Implementation Scheme: We can record some information about each key, such as the size, partition name, expiration time, access hit rate, create a special key on each memcached instance to store the access information of the key.

Note:

1: The special keys must be updated to record access information. If the key is too frequent, the normal cache performance will be affected. Therefore, you can consider forming a memory queue, when the number of keys reaches (if the Key Usage frequency is not high, you can set the time. When this time is used, the key content will be updated even if the number is insufficient.
2: Because memcached has a single key size limit, this statistical information key cannot be too large. When recording key access information, try to store it in text format to minimize the size.

3: each instance corresponds to a key used to store key access information, so that more keys can be counted.


Monitoring view: Through the above efforts, we can form three views:
1. In the memcached instance view, the statistical information provided by the memcached service itself is displayed in the unit of a specific cache instance. It also contains the number of partitions contained in the instance, that is, the number of items in the cache on the instance.
Second, the partition view collects the data of all nodes based on the partition name, and finally summarizes the statistical data. For example, you can count the total number of keys used by the hotel project, this is helpful for analyzing the distribution of keys.
Third, the key view displays the access information of a specific key and the manual expiration function.

 

Conclusion: although the above scheme can meet the requirements, in the actual production environment, try not to enable this monitoring function, and enable it again when necessary, so as to maximize the cache efficiency.

 

 

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.