是的,Memcache自己的数据结构每个项目占用超过50个字节.它取决于您的数据和密钥,因此在64位计算机上假设60+字节.
在查看memcache的代码时可以看到它:https://github.com/memcached/memcached/blob/master/memcached.h
这是构成项目的原因:
/**
* Structure for storing items within memcached.
*/
typedef struct _stritem {
struct _stritem *next;
struct _stritem *prev;
struct _stritem *h_next; /* hash chain next */
rel_time_t time; /* least recent access */
rel_time_t exptime; /* expire time */
int nbytes; /* size of data */
unsigned short refcount;
uint8_t nsuffix; /* length of flags-and-length string */
uint8_t it_flags; /* ITEM_* above */
uint8_t slabs_clsid;/* which slab class we're in */
uint8_t nkey; /* key length, w/terminating null and padding */
/* this odd type prevents type-punning issues when we do
* the little shuffle to save space when not using CAS. */
union {
uint64_t cas;
char end;
} data[];
/* if it_flags & ITEM_CAS we have 8 bytes CAS */
/* then null-terminated key */
/* then " flags length\r\n" (no terminating null) */
/* then data with terminating \r\n (no terminating null; it's binary!) */
} item;
Run Code Online (Sandbox Code Playgroud)
有3个指针,在64位机器上总计3*8 = 24字节.那里有两个时间戳,应该是32位,因此它们共计8个字节.以下int应为8字节,short应为2,u_int8应为单字节,因此它们总和为14.
这使得总共46个字节.
如果启用了CAS,则会有一个64位的CAS值,它会增加8个字节:总共54个字节
现在它变得凌乱:以下是字符数据,其中标志和数据长度以十进制形式打印(代码可以在https://github.com/memcached/memcached/blob/master/items.c,第80行找到).鉴于该标志为"0",key为一个char,数据为空,这使得:
这是另一个10字节,为最小可能的memcache项目大小总共64字节(启用CAS,您可以使用-C选项禁用它).
如果你得到65字节,也许你的客户设置一个标志"10"或类似.