Memcached:插入特定数量的项目后删除密钥

Memcached:插入特定数量的项目后删除密钥

我正在调试一个 php 脚本,该脚本将数据保存在 中,memcache以此来预热应用程序。
此脚本仅调用set将数据保存到 中memcache,并且在设置特定数量的条目后,插入的第一个项目开始消失(行为可重现)。

我一直在阅读 memcache 文档,并了解到驱逐因此开始检查日志并读取统计数据以查看是否是原因。

在插入开始删除第一个元素的项目之前停止 php 脚本,然后运行stats slabs

stats slabs
STAT 1:chunk_size 96
STAT 1:chunks_per_page 10922
STAT 1:total_pages 1
STAT 1:total_chunks 10922
STAT 1:used_chunks 1
STAT 1:free_chunks 10921
STAT 1:free_chunks_end 0
STAT 1:mem_requested 93
STAT 1:get_hits 0
STAT 1:cmd_set 1
STAT 1:delete_hits 0
STAT 1:incr_hits 0
STAT 1:decr_hits 0
STAT 1:cas_hits 0
STAT 1:cas_badval 0
STAT 1:touch_hits 0
STAT 3:chunk_size 152
STAT 3:chunks_per_page 6898
STAT 3:total_pages 4
STAT 3:total_chunks 27592
STAT 3:used_chunks 22787
STAT 3:free_chunks 4805
STAT 3:free_chunks_end 0
STAT 3:mem_requested 3232040
STAT 3:get_hits 0
STAT 3:cmd_set 22814
STAT 3:delete_hits 0
STAT 3:incr_hits 0
STAT 3:decr_hits 0
STAT 3:cas_hits 0
STAT 3:cas_badval 0
STAT 3:touch_hits 0
STAT 4:chunk_size 192
STAT 4:chunks_per_page 5461
STAT 4:total_pages 1
STAT 4:total_chunks 5461
STAT 4:used_chunks 1300
STAT 4:free_chunks 4161
STAT 4:free_chunks_end 0
STAT 4:mem_requested 202877
STAT 4:get_hits 0
STAT 4:cmd_set 1301
STAT 4:delete_hits 0
STAT 4:incr_hits 0
STAT 4:decr_hits 0
STAT 4:cas_hits 0
STAT 4:cas_badval 0
STAT 4:touch_hits 0
STAT active_slabs 3
STAT total_malloced 6291008

如你所见,所有的slab仍然有剩余的可用空间。

当让脚本插入下一个项目时,memcache 服务器会记录以下信息:

30: going from conn_closing to conn_closed
29: going from conn_read to conn_parse_cmd
<29 set [tc:e-401:id-2485:profile-5:property-11][1] 0 0 3
29: going from conn_parse_cmd to conn_nread
> NOT FOUND [tc:e-401:id-2485:profile-5:property-11][1]
>29 STORED

再次调用,stats slabs我发现已经使用了新的平板:

stats slabs
STAT 1:chunk_size 96
STAT 1:chunks_per_page 10922
STAT 1:total_pages 1
STAT 1:total_chunks 10922
STAT 1:used_chunks 1
STAT 1:free_chunks 10921
STAT 1:free_chunks_end 0
STAT 1:mem_requested 93
STAT 1:get_hits 0
STAT 1:cmd_set 1
STAT 1:delete_hits 0
STAT 1:incr_hits 0
STAT 1:decr_hits 0
STAT 1:cas_hits 0
STAT 1:cas_badval 0
STAT 1:touch_hits 0
STAT 2:chunk_size 120
STAT 2:chunks_per_page 8738
STAT 2:total_pages 1
STAT 2:total_chunks 8738
STAT 2:used_chunks 1
STAT 2:free_chunks 8737
STAT 2:free_chunks_end 0
STAT 2:mem_requested 120
STAT 2:get_hits 0
STAT 2:cmd_set 1
STAT 2:delete_hits 0
STAT 2:incr_hits 0
STAT 2:decr_hits 0
STAT 2:cas_hits 0
STAT 2:cas_badval 0
STAT 2:touch_hits 0
STAT 3:chunk_size 152
STAT 3:chunks_per_page 6898
STAT 3:total_pages 4
STAT 3:total_chunks 27592
STAT 3:used_chunks 22790
STAT 3:free_chunks 4802
STAT 3:free_chunks_end 0
STAT 3:mem_requested 3232437
STAT 3:get_hits 0
STAT 3:cmd_set 22817
STAT 3:delete_hits 0
STAT 3:incr_hits 0
STAT 3:decr_hits 0
STAT 3:cas_hits 0
STAT 3:cas_badval 0
STAT 3:touch_hits 0
STAT 4:chunk_size 192
STAT 4:chunks_per_page 5461
STAT 4:total_pages 1
STAT 4:total_chunks 5461
STAT 4:used_chunks 1300
STAT 4:free_chunks 4161
STAT 4:free_chunks_end 0
STAT 4:mem_requested 202877
STAT 4:get_hits 0
STAT 4:cmd_set 1301
STAT 4:delete_hits 0
STAT 4:incr_hits 0
STAT 4:decr_hits 0
STAT 4:cas_hits 0
STAT 4:cas_badval 0
STAT 4:touch_hits 0
STAT active_slabs 4
STAT total_malloced 7339568
END

第一个项目(以“ tc:e-501”开头的键不再存在(使用检查memdump --servers=localhost | grep tc:e-501,并从 php 调用get以获取第一个键也给我不存在的)

打电话后stats items我发现驱逐计数器是 0......

stats items
STAT items:1:number 1
STAT items:1:age 1391
STAT items:1:evicted 0
STAT items:1:evicted_nonzero 0
STAT items:1:evicted_time 0
STAT items:1:outofmemory 0
STAT items:1:tailrepairs 0
STAT items:1:reclaimed 0
STAT items:1:expired_unfetched 0
STAT items:1:evicted_unfetched 0
STAT items:1:crawler_reclaimed 0
STAT items:2:number 1
STAT items:2:age 982
STAT items:2:evicted 0
STAT items:2:evicted_nonzero 0
STAT items:2:evicted_time 0
STAT items:2:outofmemory 0
STAT items:2:tailrepairs 0
STAT items:2:reclaimed 0
STAT items:2:expired_unfetched 0
STAT items:2:evicted_unfetched 0
STAT items:2:crawler_reclaimed 0
STAT items:3:number 22790
STAT items:3:age 1391
STAT items:3:evicted 0
STAT items:3:evicted_nonzero 0
STAT items:3:evicted_time 0
STAT items:3:outofmemory 0
STAT items:3:tailrepairs 0
STAT items:3:reclaimed 0
STAT items:3:expired_unfetched 0
STAT items:3:evicted_unfetched 0
STAT items:3:crawler_reclaimed 0
STAT items:4:number 1300
STAT items:4:age 1381
STAT items:4:evicted 0
STAT items:4:evicted_nonzero 0
STAT items:4:evicted_time 0
STAT items:4:outofmemory 0
STAT items:4:tailrepairs 0
STAT items:4:reclaimed 0
STAT items:4:expired_unfetched 0
STAT items:4:evicted_unfetched 0
STAT items:4:crawler_reclaimed 0
END

set脚本中的以下调用将继续按顺序删除插入的第一个项目,因此我丢弃了密钥冲突。

是什么原因导致了这种现象?我目前完全不知道。

編輯:使用 memcached 1.4.20 編輯:使用选项-M似乎没有帮助,项目仍然被删除并且没有set调用返回任何false值。

相关内容