技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> 算法 --> 关于tokyocabinet的memory db 的filesize与使用内存的关系

关于tokyocabinet的memory db 的filesize与使用内存的关系

浏览:1536次  出处信息
我使用tokyotyrant的方式如下:

    /data1/tokyotyrant/bin/ttserver -host 10.10.10.111 -port 6789 -dmn -pid /data1/tokyotyrant_data/6789/6789.pid -le -uas -thnum 16 -log /data1/tokyotyrant_data/6789/6789.log -ulog /data1/tokyotyrant_data/6789/6789.ulog -sid 6789 -mhost 10.10.10.112 -mport 7890 -rts /data1/tokyotyrant_data/6789/6789.rts *

    两项统计数据如下:

    [root@localhost ~]# tcrmgr inform -port 6789 10.10.10.111

    record number: 10470754

    file size: 2014949218

    [root@localhost ~]# tcrmgr inform -port 6789 -st 10.10.10.111 | grep rss

    memrss  3826147328

    [root@localhost ~]#

    疑问:

    存储的数据占用的内存大小file size为2G; 但是物理内存占用为3.8G; 我承认程序本身会占用一部分内存,100MB了不得了吧,那么其余的1.7G都做什么用了呢?

    首先,通过看源码,得知,file size是通过存储的数据计算出来的,其中包括存储数据的数据结构占用的空间和key+value占用的空间。计算方式如下:

    tcutil.c

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    /* Get the total size of memory used in a map object. */

    uint64_t tcmapmsiz(const TCMAP *map){

     assert(map);

     return map->msiz + map->rnum * (sizeof(*map->first) + sizeof(tcgeneric_t)) +

     map->bnum * sizeof(void *);

    }

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    所以,即使没有一条记录,filesize也不会是0的; 默认的bnum为65672; 如果你的机器是32位的,则,0条记录时的filesize为: 65672 * 4 = 262688; 所以,如果你执行了vanish,发现filesize不为0 ,就不用奇怪了。   

建议继续学习:

  1. cacti 增加 Tokyocabinet 监控    (阅读:2601)
  2. 关于tokyocabinet的list操作    (阅读:1518)
  3. 安装tokyocabinet的问题    (阅读:1329)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1