A few days ago did a memcached of thinking and tested some data on how to increase the memcached memory utilization.
When you start memcached, you can addThe-f parameter and the-n parameter. -f Specifies the chunk size change ratio of each slab, the default 1.25,-n specifies slab the size of the chunk from how much to start.
Use Memcache_add ($memcache _obj, MD5 (rand ()), Str_repeat (MD5 (rand ()), ten), false,80000), and continuously pour data into memcache.
Memcached–d start–m 50 Start memcache, the growth factor defaults to 1.25
Results:
2011-03-28 11:15:37:sar:localh~211:10 0 0 0 0/0% 0 5 265 50M 0% 0 0 0 4/0/0
2011-03-28 11:15:40:sar:localh~211:11 0 0 530 0/0% 0 192K 4K 50M 1% 797 530 0 4/0/0
2011-03-28 11:15:43:sar:localh~211:11 0 0 13K 0/0% 0 5M 105K 50M 17% 21K 13K 0 4/0/1
2011-03-28 11:15:46:sar:localh~211:11 0 0 13K 0/0% 0 5M 104K 50M 48% 61K 13K 0 4/1/1
2011-03-28 11:15:49:sar:localh~211:11 0 0 13K 0/0% 0 5M 102K 50M 77% 98K 13K 580 4/1/2
2011-03-28 11:15:52:sar:localh~211:11 0 0 13K 0/0% 0 5M 103K 50M 92% 116K 13K 13K 4/1/3
2011-03-28 11:15:55:sar:localh~211:11 0 0 13K 0/0% 0 5M 105K 50M 92% 116K 13K 13K 4/2/4
2011-03-28 11:15:58:sar:localh~211:11 0 0 13K 0/0% 0 5M 107K 50M 92% 116K 13K 13K 4/2/5
2011-03-28 11:16:01:sar:localh~211:11 0 0 13K 0/0% 0 5M 101K 50M 92% 116K 13K 13K 4/3/6
Stable utilization at 92%, storage 116k
Stats Slabs
STAT 8:chunk_size 440
STAT 8:chunks_per_page 2383
STAT 8:total_pages 50
STAT 8:total_chunks 119150
STAT 8:used_chunks 119150
A chunk with a size of 440 bytes is used. The Slab with ID 8 is used
Memcached–d start–m 50–f 2 growth factor of 2
Results:
2011-03-28 11:17:53:sar:localh~211:10 0 0 0 0/0% 0 5 267 50M 0% 0 0 0 4/0/0
2011-03-28 11:17:56:sar:localh~211:11 0 0 13K 0/0% 0 5M 107K 50M 16% 20K 13K 0 4/0/0
2011-03-28 11:17:59:sar:localh~211:11 0 0 13K 0/0% 0 5M 106K 50M 47% 60K 13K 0 4/1/1
2011-03-28 11:18:02:sar:localh~211:11 0 0 13K 0/0% 0 5M 106K 50M 63% 80K 13K 13K 4/1/2
2011-03-28 11:18:05:sar:localh~211:11 0 0 13K 0/0% 0 5M 105K 50M 63% 80K 13K 13K 4/1/3
2011-03-28 11:18:08:sar:localh~211:11 0 0 13K 0/0% 0 5M 108K 50M 63% 80K 13K 13K 4/2/4
2011-03-28 11:18:11:sar:localh~211:11 0 0 13K 0/0% 0 5M 106K 50M 63% 80K 13K 13K 4/2/5
The usage rate is stable at 63%, storing 80k strips.
STAT 4:chunk_size 640
STAT 4:chunks_per_page 1638
STAT 4:total_pages 50
STAT 4:total_chunks 81900
STAT 4:used_chunks 81900
Chunk with a size of 640, using Slab with ID 4
Memcached–d start–m 50–f 1.001–n 375 growth rate of 1.001 (memcache required growth rate must be greater than 1)
Results:
2011-03-28 14:40:09:sar:127.0.~211:11 0 0 12K 0/0% 0 4M 100K 50M 98% 124K 12K 10K 4/1/3
2011-03-28 14:40:10:sar:127.0.~211:11 0 0 13K 0/0% 0 5M 104K 50M 99% 125K 13K 13K 4/1/3
2011-03-28 14:40:11:sar:127.0.~211:11 0 0 13K 0/0% 0 5M 106K 50M 99% 125K 13K 13K 4/2/4
Stable utilization at 99%, storage 125k
STAT 1:chunk_size 408
STAT 1:chunks_per_page 2570
STAT 1:total_pages 6
STAT 1:total_chunks 15420
STAT 1:used_chunks 15022
Chunk with a size of 408, using slab with ID 1
Visible adjustment of the-F and-n values can effectively increase the memcache memory usage.
However, it is important to note that the above test data uses the same length data, and for long-length data, the-F and-n values need to be determined based on the overall data.
After my test slab the ID value of the maximum is 200, if the ID 199 slab chunk is still less than the data length, then the data needs to be stored in the Slab ID 200, the slab size is 1m, resulting in a huge waste of memory.
memcached-d start-m 50-f 1.001-n 100
2011-03-28 14:51:15:sar:127.0.~211:11 0 0 13K 0/0% 0 5M 101K 50M 0% 13K 13K 4/1/2
Memory usage is approximately equal to 0, storing 50 data
STAT 200:chunk_size 1048576
STAT 200:chunks_per_page 1
STAT 200:total_pages 50
STAT 200:total_chunks 50
STAT 200:used_chunks 50
Chunk with a size of 1m, using an ID of 200 slab
Now there is one more question:
STAT 1:chunk_size 408
STAT 1:chunks_per_page 2570
A 1m size slab store 2,570 chunk of size 408, visible and not full, the remaining space is wasted. In this case, each slab wasted memory only hundreds of bytes, can be ignored, but if the chunk size is dozens of hundred k, the space waste situation is very objective. The-I (uppercase I) parameter can be added at memcached startup to change the size of the slab
Article turned from: http://blog.csdn.net/ago52030/article/details/6902026
memcached memory allocation optimization and usage issues