• 幕客老师召集小伙伴
  • 运维高手36项修炼
  • python自动化运维项目实战
  • nginx从入门到实战
  • 阿里云与Centos7实战

压测twmemcache的LRU内存清理机制

一、关于twmemcache的清理机制

LRU item eviction (-M 1) works at the item level. When a new item needs to be stored and cannot be accommodated by recycling an expired item or allocating more memory, the least recently used item in the same slab class the new item belongs to gets evicted.
Random slab eviction (-M 2) works at the slab level. When a new item needs to be inserted and it cannot be accommodated by recycling an expired item or allocating more memory, a random slab is picked from the list of all allocated slabs, all items within it evicted, and reassigned to the slab class that fits the new item.
LRA (least recently accessed, also known as Slab LRU) slab eviction (-M 4) works at the slab level. It updates slab ordering the same way LRU item eviction updates item ordering, but the objects being ordered are slabs instead of items, and there is only one global, slab-class agonostic list. It evicts the slab at the head of the list when a new item cannot be accommondated otherwise.
LRC (least recently created) slab eviction (-M 8) works at the slab level. It tracks slab ordering by the time they were created or reassigned. One noticeable behavior of LRC slab eviction is that it disables reusing memory at the item level- it no longer tries to find an expired or deleted item. As a result, it evicts the slab at the head of the list when a new item cannot be accommodated by allocating more memory.

二、压测工具

mcperf --linger=0 --timeout=5 --conn-rate=1000 --call-rate=1000 --num-calls=1000 --num-conns=1000 --sizes=u1,10240

三、压测脚本

#!/usr/bin/env python

#Used to test memcache

 

import threading

from time import sleep, ctime

import random

import string

 

loops = []

 

for i in range(0,5):

    loops.append(''.join(random.choice(string.ascii_letters) for x in range(20)))

 

def loop(nloop, nval):

    k_nval = "okooo_%s"%nval

    print "key %s,value %s"%(k_nval,nval)

    import memcache

    mc = memcache.Client(['192.168.8.211:11210'],debug=0)

    mc.set(k_nval,nval)

    chenee = mc.get("foo.chenee")

    if chenee == "okooo":

        print "OK...",

    else:

        print "failed!"

 

def main():

    print 'starting at:', ctime()

    threads = []

    nloops = range(len(loops))

 

    for i in nloops:

        t = threading.Thread(target=loop,args=(i, loops[i]))

        threads.append(t)

 

    for i in nloops:

        threads[i].start()

 

    for i in nloops:

        threads[i].join()

 

    print 'all DONE at:', ctime()

 

if __name__ == '__main__':

    main()

 

三、服务端检查

/usr/local/twemcache2/bin/twemcache -d -p 11211 -u nobody -m 10 -c 1024 -P /var/run/twem/twemcache.pid -M 4 -f 1.05 -o /logs/twem/cache.log -X /logs/twem/command.log -y 1

通过查看

-m 10最大限制内存使用量为10M,如果超过了,触发twmemcache的自动清理

 

echo "stats"|nc www.iaskjob.com 11211|grep "slab"

STAT slab_evict 42即为触发key的淘汰机制

 

 

四、补充twmemcache相关操作

set key flags exptime bytes [noreply] 
value 
  • key:键值 key-value 结构中的 key,用于查找缓存值。
  • flags:可以包括键值对的整型参数,客户机使用它存储关于键值对的额外信息 。
  • exptime:在缓存中保存键值对的时间长度(以秒为单位,0 表示永远)
  • bytes:在缓存中存储的字节数(注意长度和需要输入的value数值相匹配,否则会出现插入缓慢的情况 )
  • noreply(可选): 该参数告知服务器不需要返回数据
  • value:存储的值(始终位于第二行)

 

例:

set testj 0 900 2

12

 

 

 

 

压测twmemcache的LRU内存清理机制

Pingbacks已打开。

引用地址

暂无评论

发表评论