Memcache improves cache hit rate

Source: Internet
Author: User

Recently, a project and new Code have been stored. memcahce is widely used as the cache in the new Code. Therefore, I began to learn more about the memory allocation policy of memcache. I have heard of a memcache monitoring script written in PHP before. I searched for it online and downloaded it with memcache. php.
Modify the PHP file code configuration

Define ('admin _ username', 'admin'); define ('admin _ password', 'admin'); $ memcache_servers [] = '2017. 0.0.1: 11211 '; $ memcache_servers [] = '2017. 0.0.1: 11212 '; // multiple monitors

Problem occurred
We found that the hit rate dropped from 0.5% to 97% at a rate of 94% per day.
The number of misses is growing fast.
According to the monitored variables, almost all items are concentrated in slab2, with nearly 8737 items.
The problem must occur on the data cached by slab2.

Start searching for Problems ~
Download a memcached statistical tool memcache-tool from the Internet.
Run memcached-tool 127.0.0.1: 11211 in Linux

# Item_size max_age pages count full? Evicted slabid chunk size lifecycle page quantity is the number of cache items full number of canceled?

It seems that the storage of page data in slab 2 is full, but the number of pages has not increased, and the count has reached 8738.
The memcache daemon process is
Memcached-D-M 10-u root-P 11211
The allocated memory is only 10 MB, and the font-F of chunk size is the default 1.25.

[[email protected]]# memcached -u root -vvslab class   1: chunk size        96 perslab   10922slab class   2: chunk size       120 perslab    8738slab class   3: chunk size       152 perslab    6898slab class   4: chunk size       192 perslab    5461slab class   5: chunk size       240 perslab    4369slab class   6: chunk size       304 perslab    3449slab class   7: chunk size       384 perslab    2730slab class   8: chunk size       480 perslab    2184

0 MB of memory is allocated to too many slab instances, resulting in a maximum of one slab pages and no additional pages.
The Count of slab2 has reached the maximum value of 8738. Cached data is continuously evicted.

Solve the problem
A new memcache daemon
Memcached-D-M 10-F 2-u root-P 11212
In the project code, change the address of All cached data interfaces using memcache 11211 slab2 to 11212.

[[email protected] ~]# /home/duyumi/memcached-tool 127.0.0.1:11212  #  Item_Size  Max_age   Pages   Count   Full?  Evicted Evict_Time OOM  2     192B      5190s       2    8001      no        0        0    0

The number of pages is increased to 2, the Count reaches 8001, and there is no full. The maximum chunk of a page is 5461, and the size of each chunk is 192b.

[[email protected] ~]# memcached -u root -f 2 -vvslab class   1: chunk size        96 perslab   10922slab class   2: chunk size       192 perslab    5461slab class   3: chunk size       384 perslab    2730....

The cached item is not evicted.

OK. The problem is resolved.


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.