• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            那誰的技術(shù)博客

            感興趣領(lǐng)域:高性能服務(wù)器編程,存儲(chǔ),算法,Linux內(nèi)核
            隨筆 - 210, 文章 - 0, 評(píng)論 - 1183, 引用 - 0
            數(shù)據(jù)加載中……

            The design and implementation of CommonCache Library(base on version 0.6)


            1. Overview

            a) the functions of a cache
            cache the most frequently visited data in the memory, so:
            1) if the the data get losed is not a big matter,it means that you should not store data
            in cache only, offen, cache is between the DB server and application,hence reduce visiting DB times
             and speed up application.
            2) since the memory is not quite big, so the eliminating algorithm such LRU must to be used.
            3) must support key-value-like API such as find/erase/set and so forth.

            b) ccache feature (version 0.6):
            1) using mmap to cache data in file, so it can be used in multi-thead and multi-process application.
            2) support unfix size key node
            3) support hash-rbtree and hash-list structure
            4) use LRU algorithm to eliminate nodes when it is running out of its memory size
            5) fast, 100W/read operation on fix-size key node in no more than 0.5 second

            c) what is the difference between ccache and memcached?
            ccache is a static library, memcached is a cache sever, so users who use ccache must
            design the protocols between clients and server, and write the server application themself.

            2. implementation
            a) the cache file structure


            b) the hashitem array detail   
            the hashitem array is used to find the node base on the node key.Every nodes in a
            same hashitem has a same hash num.All the nodes in the same hashitem are strutured
            in list or rbtree:


            when compiling the ccache, define the macro CCACHE_USE_RBTREE to specily using rbtree,
            else macro CCACHE_USE_LIST using list. The structrue ccache_node_t has following fields
            about this:

            typedef struct ccache_node_t
            {
                    
            /* 
                      
                     
            */

            #ifdef CCACHE_USE_LIST
                
            struct ccache_node_t *next, *prev;
            #elif defined CCACHE_USE_RBTREE    
                ccache_color_t color;
                
            struct ccache_node_t *parent, *left, *right;
            #endif

                    
            /* 
                      
                     
            */

            }
            ccache_node_t;

            the hashitem array size is defined in the configure file when open the cache.

            c) the freearea array detail   
            ccache use slab-like algorithm to allocate node memory.In the configure file, there is an
            item called "alignsize", this value specify the align size between different freearea,
            assume the alignsize is 8 bytes:

            all the nodes in the same freearea has the same size, when allocating a node(ccache_memory.c/ccache_allocate):
            1) allign the node size with the alignsize value, then find the fit
            freearea(ccache_memory.c/ccache_get_freeareaid) and return the freeareaid
            2) if the data zone has enough memory for the node, change the cache->start_free and cache->freesize
            and return the node pointer
            3) else, erase the  cache->freearea[freeareaid]->lrulast node, use this node memory
            for this allocation.
            4) every time a node allocated, place it in the freearea's tail(freearea->lrulast = node),
            when the node has been visited, it move on one step in the freearea list.So, the more a node has been
            visited, the closer it moves to the freearea head(freearea->lrufirst).Hence, the freearea lrulast
            node is the less frequently visited node in the freearea(although not so accurate:).

            the ccache_node_t structure has following fields about LRU:

            typedef struct ccache_node_t
            {
                
            /*
                   .
                
            */
                   
                
            struct ccache_node_t *lrunext, *lruprev;

                
            /*
                   .
                
            */
                   
            }
            ccache_node_t;

             

             

            posted on 2009-10-22 21:11 那誰 閱讀(4118) 評(píng)論(1)  編輯 收藏 引用 所屬分類: ccache

            評(píng)論

            # re: The design and implementation of CommonCache Library(base on version 0.6)  回復(fù)  更多評(píng)論   

            開源,大力支持啊!
            中國缺少這樣的東西
            2010-03-10 19:37 | jesse
            精品少妇人妻av无码久久| 99久久中文字幕| 国产精品99久久久精品无码| 一本久道久久综合狠狠躁AV| 色欲久久久天天天综合网| 国产综合久久久久久鬼色| 国产—久久香蕉国产线看观看| 日本精品久久久久影院日本| 91精品国产9l久久久久| 亚洲国产成人久久综合碰碰动漫3d | 久久无码av三级| 亚洲第一永久AV网站久久精品男人的天堂AV| 伊人久久大香线蕉综合网站| 国产成人久久精品区一区二区| 伊人久久大香线蕉综合网站| 久久久久夜夜夜精品国产| 伊人久久大香线焦AV综合影院 | 久久九九久精品国产| 国产精品久久精品| 日韩乱码人妻无码中文字幕久久 | 美女久久久久久| 日本精品久久久中文字幕| 久久精品九九亚洲精品| 天天综合久久一二三区| 国产精品欧美久久久久天天影视| 久久久久亚洲AV无码专区体验| 中文成人久久久久影院免费观看 | 久久99精品久久久久久齐齐 | 蜜臀久久99精品久久久久久| 欧美激情精品久久久久| 97超级碰碰碰久久久久| 久久99精品久久久久久hb无码| 国产毛片欧美毛片久久久| 久久综合色老色| 久久亚洲精品无码VA大香大香| 色欲综合久久躁天天躁| 亚洲国产精品成人久久蜜臀| 色欲综合久久躁天天躁| 国产精品99久久久久久宅男小说| 久久久久亚洲精品日久生情| 伊人久久久AV老熟妇色|