• <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ù)加載中……

            commoncache與tokyocabinet插入數(shù)據(jù)的效率比較

            最近tokyocabinet這個(gè)數(shù)據(jù)庫(kù)很流行,網(wǎng)上出現(xiàn)很多研究這個(gè)玩意兒的文章。在它的主頁(yè)上,給出的benchmark表明,在它的硬件環(huán)境下,插入一百萬數(shù)據(jù)僅需不到一秒的時(shí)間。

            我被震撼了,為了親眼所見,也為了和我之前寫的commoncache庫(kù)進(jìn)行比較,我決定在我自己的機(jī)器上,使用同樣類型,大小的數(shù)據(jù),同樣的量級(jí),進(jìn)行插入數(shù)據(jù)這個(gè)操作的比較。

            下面給出我寫的測(cè)試文件:
            針對(duì)tokyocabinet的:
            test_unfix_cache.c
            /********************************************************************

                created:    2008/05/30

                filename:     test_unfix_cache.c

                author:        Lichuang

                            

                purpose:    

            ********************************************************************
            */



            #include 
            <stdlib.h>

            #include 
            <stdio.h>

            #include 
            <string.h>

            #include 
            <errno.h>

            #include 
            <unistd.h>

            #include 
            <fcntl.h>

            #include 
            <sys/types.h>

            #include 
            <sys/wait.h>

            #include 
            <netinet/in.h>

            #include 
            <signal.h>

            #include 
            <arpa/inet.h>



            #include 
            <tcutil.h>

            #include 
            <tchdb.h>



            TCHDB 
            *hdb = NULL;



            void mainloop();

            void createrandstring(char* stringint len);



            int isparent = 0;



            int main()

            {

                hdb 
            = tchdbnew();

                
            if (!hdb)

                {

                    printf(
            "create error!\n");

                    exit(
            -1);

                }



                
            if (!tchdbopen(hdb, "1.hdb", HDBOWRITER | HDBOCREAT))

                {

                    printf(
            "open error!\n");

                    exit(
            -1);

                }



                mainloop();



                
            return 0;

            }



            #define STRING_LEN 5



            void mainloop()

            {

                
            char string[STRING_LEN];

                
            int num, i, len;



                srand((unsigned)time(NULL) 
            + getpid());

                len 
            = STRING_LEN - 1;



                
            for (i = 1; i < 1000000++i)

                {

                    memset(
            string0, STRING_LEN);

                    createrandstring(
            string, len);



                    
            if (!tchdbput2(hdb, stringstring))            

                    {

                    }

                    
            else

                    {

                    }

                }



                printf(
            "pid = %d, test done\n", getpid());

            }



            const char str[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";



            void createrandstring(char* stringint len)

            {

                
            int x, i;

                
            for (i = 0; i < len - 1++i)

                {

                    x 
            = rand() % (sizeof(str) - 1);  

                    
            //x = (i + len) % (sizeof(str) - 1);  

                    

                    
            string[i] = str[x];

                }



                
            string[++i] = str[len % sizeof(str) + 1];

                
            string[i] = '\0';

            }


            對(duì)應(yīng)的Makefile:
            all:test_unfix_cache.c
                gcc 
            -I/usr/local/include test_unfix_cache.c -o test_unfix_cache  -L/usr/local/lib -ltokyocabinet -lz -lbz2 -lrt -lpthread -lm -lc

            而針對(duì)commoncache的測(cè)試文件是:
            /********************************************************************
                created:    2008/05/30
                filename:     test_unfix_cache.c
                author:        Lichuang
                            
                purpose:    
            ********************************************************************
            */

            #include 
            <stdlib.h>
            #include 
            <stdio.h>
            #include 
            <string.h>
            #include 
            <errno.h>
            #include 
            <unistd.h>
            #include 
            <fcntl.h>
            #include 
            <sys/types.h>
            #include 
            <sys/wait.h>
            #include 
            <netinet/in.h>
            #include 
            <signal.h>
            #include 
            <arpa/inet.h>

            #include 
            "ccache.h"
            #include 
            "memory.h"

            ccache_t
            * cache;

            void mainloop();
            void createrandstring(char* stringint len);

            int isparent = 0;

            int main()
            {
                cache 
            = ccache_create(75000100"./testunfixmap"108101);
                
            if (NULL == cache)
                {
                    printf(
            "create_cache error!\n");
                    
            return -1;
                }

                mainloop();

                
            return 0;
            }

            #define STRING_LEN 5

            int cmp_fun(const void* data1, const void* data2, int len)
            {
                
            return memcmp(data1, data2, sizeof(char* len);
            }

            void mainloop()
            {
                
            char string[STRING_LEN];
                
            int i, len;
                ccache_data_t data;

                srand((unsigned)time(NULL) 
            + getpid());
                len 
            = STRING_LEN - 1;

                
            for (i = 1; i < 1000000++i)
                {
                    memset(
            string0, STRING_LEN);
                    createrandstring(
            string, len);

                    data.datasize 
            = len;
                    data.keysize 
            = len;
                    data.data 
            = (void*)&string;
                    data.key  
            = (void*)&string;

                    
            //printf("i = %d\n", i);

                    
            if (0 > ccache_insert(&data, cache, cmp_fun, NULL, NULL))
                    {
                    }
                    
            else
                    {
                        
            continue;
                    }
                }

                printf(
            "pid = %d, test done\n", getpid());
            }

            const char str[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

            void createrandstring(char* stringint len)
            {
                
            int x, i;
                
            for (i = 0; i < len - 1++i)
                {
                    x 
            = rand() % (sizeof(str) - 1);  
                    
            //x = (i + len) % (sizeof(str) - 1);  
                    
                    
            string[i] = str[x];
                }

                
            string[++i] = str[len % sizeof(str) + 1];
                
            string[i] = '\0';
            }

            在commoncache的項(xiàng)目代碼的test目錄中,同樣存在一個(gè)名為test_unfix_test.c的文件,是我以前寫commoncache時(shí)測(cè)試用的,不過原來的那個(gè)文件功能較多,不僅有插入操作,還有查找,替換等操作,這次為了測(cè)試,我對(duì)這個(gè)文件進(jìn)行了精簡(jiǎn),只保留插入數(shù)據(jù)操作的部分。使用的是commoncache中的hash-rbtree結(jié)構(gòu)。

            性能測(cè)試結(jié)果:
            tokyocabinet:
            lichuang@lichuang:/media/e/source/tokyocabinet/test$ time ./test_unfix_cache 
            pid 
            = 15464, test done

            real    0m0.373s
            user    0m0.364s
            sys    0m0.008s
            commoncache:
            lichuang@lichuang:/media/e/source/ccache/bin$ time ./test_unfix_cache 
            pid 
            = 15514, test done

            real    0m0.235s
            user    0m0.228s
            sys    0m0.004s
            看上來,commoncache比之tokyocabinet還稍好一些?
            不過,commoncache與tokyocabinet還是有區(qū)別的,前者工作的區(qū)域是共享內(nèi)存,后者是磁盤文件,有這樣的表現(xiàn),確實(shí)驚人。

            這次比較,起碼給了我一些些的自信,我的commoncache不比世界一流的文件數(shù)據(jù)庫(kù)性能差的太多。
            下一步,我想繼續(xù)下面的幾個(gè)工作:
            1) 國(guó)慶的時(shí)候,整理出一份commoncache的設(shè)計(jì)文檔,算是階段性的一個(gè)小結(jié)。另外,commoncache在插入數(shù)據(jù)的時(shí)候,有時(shí)會(huì)報(bào)錯(cuò),我還得查查是為什么。
            2) 抽空要開始研究文件數(shù)據(jù)庫(kù)的實(shí)現(xiàn)了,tokyocabinet就是一個(gè)不錯(cuò)的參考。

            另外,多說幾句,一個(gè)產(chǎn)品要成功,僅僅有性能是不夠,可維護(hù)性,可備份性,優(yōu)秀的協(xié)議設(shè)計(jì)等等,都是重要的指標(biāo)。我想,commoncache只做到了性能這一點(diǎn),我需要在其他幾方面繼續(xù)努力。

            哦,忘了給出我的環(huán)境參數(shù):
            ubuntu9.04,內(nèi)核2.6.18,內(nèi)存3G,intel 雙核CPU。


            posted on 2009-09-20 20:02 那誰 閱讀(4221) 評(píng)論(2)  編輯 收藏 引用 所屬分類: ccache

            評(píng)論

            # re: commoncache與tokyocabinet插入數(shù)據(jù)的效率比較  回復(fù)  更多評(píng)論   

            看你的blog好久了,再不頂真說不過去了:)
            2009-09-30 21:57 | nanduo

            # re: commoncache與tokyocabinet插入數(shù)據(jù)的效率比較  回復(fù)  更多評(píng)論   

            內(nèi)存比磁盤快這么一點(diǎn)也算可以?
            2013-10-30 01:17 | ddd
            亚洲日本va午夜中文字幕久久| 九九久久精品国产| 免费一级做a爰片久久毛片潮| 久久精品视频免费| 久久国产高清字幕中文| 精品永久久福利一区二区| 久久婷婷五月综合色奶水99啪| 久久SE精品一区二区| 久久中文字幕人妻熟av女| 色综合合久久天天给综看| 久久这里只有精品视频99| 久久福利片| 亚洲精品无码专区久久同性男| 久久综合给合综合久久| 久久中文字幕无码专区| 亚洲成av人片不卡无码久久| 色狠狠久久综合网| 亚洲av成人无码久久精品| 亚洲级αV无码毛片久久精品| 久久人人爽人人爽人人AV东京热| 久久丫精品国产亚洲av| 久久精品草草草| 久久精品国产福利国产琪琪| 欧美精品福利视频一区二区三区久久久精品| 欧美精品一本久久男人的天堂| 一本大道加勒比久久综合| 热RE99久久精品国产66热| 99久久国产宗和精品1上映| 久久久久高潮毛片免费全部播放| 久久久久久毛片免费播放| 亚洲国产精品久久久久婷婷老年| 久久亚洲天堂| 国产激情久久久久久熟女老人| 99久久777色| 香蕉99久久国产综合精品宅男自 | 日本久久久精品中文字幕| 久久se精品一区精品二区国产| 久久婷婷午色综合夜啪| 高清免费久久午夜精品| 老司机午夜网站国内精品久久久久久久久 | 久久综合狠狠综合久久综合88|