redis vs ssdb, hmset效率对比

平台环境:
软件 OS X 10.9.5 (13F34)
处理器 2.6 GHz Intel Core i5
内存 8 GB 1600 MHz DDR3
硬盘 500G SSD

软件环境:
redis 2.8.13
ssdb 1.7.0.0

测试总结:
使用php-redis驱动测试php连接redis和ssdb进入hmset持续写入10万个Key。
redis用时24s,ssdb用时120s,ssdb表现相差近6倍。

测试结果:
redis test start
Job start, 512.000000 kb, 2014-10-11 13:31:59
Job 10000 done, 512.000000 kb, 2014-10-11 13:32:01
Job 20000 done, 512.000000 kb, 2014-10-11 13:32:02
Job 30000 done, 512.000000 kb, 2014-10-11 13:32:05
Job 40000 done, 512.000000 kb, 2014-10-11 13:32:08
Job 50000 done, 512.000000 kb, 2014-10-11 13:32:13
Job 60000 done, 512.000000 kb, 2014-10-11 13:32:15
Job 70000 done, 512.000000 kb, 2014-10-11 13:32:17
Job 80000 done, 512.000000 kb, 2014-10-11 13:32:19
Job 90000 done, 512.000000 kb, 2014-10-11 13:32:21
Job 100000 done, 512.000000 kb, 2014-10-11 13:32:23
Job start, 512.000000 kb, 2014-10-11 13:32:23

ssdb test start
Job start, 512.000000 kb, 2014-10-11 13:32:23
Job 10000 done, 512.000000 kb, 2014-10-11 13:32:33
Job 20000 done, 512.000000 kb, 2014-10-11 13:32:44
Job 30000 done, 512.000000 kb, 2014-10-11 13:32:57
Job 40000 done, 512.000000 kb, 2014-10-11 13:33:10
Job 50000 done, 512.000000 kb, 2014-10-11 13:33:22
Job 60000 done, 512.000000 kb, 2014-10-11 13:33:35
Job 70000 done, 512.000000 kb, 2014-10-11 13:33:49
Job 80000 done, 512.000000 kb, 2014-10-11 13:34:00
Job 90000 done, 512.000000 kb, 2014-10-11 13:34:12
Job 100000 done, 512.000000 kb, 2014-10-11 13:34:23
Job start, 512.000000 kb, 2014-10-11 13:34:23

测试代码:

#!/usr/bin/env php
<?php
$test = new redis_test();
$test->totalSize = 100000;
$test->run();

class redis_test
{
    public $totalSize=1000000;

    function printf()
    {
      $args = func_get_args();
      if(count($args) == 1){
        $msg = $args[0].PHP_EOL;
      }else{
        $args[0] = $args[0].PHP_EOL;
        $msg = call_user_func_array("sprintf", $args);
      }

      echo $msg;
    }

    function run()
    {
        //测试redis->hmset()
        $this->printf("redis test start");
        $redis = new redis();
        $redis->connect('127.0.0.1', 6379);
        $this->test($redis);

        //测试ssdb->hmset()
        $this->printf("ssdb test start");
        $redis = new redis();
        $redis->connect('127.0.0.1', 8888);
        $this->test($redis);
    }

    function test($redis)
    {
        //导出一条测试记录
        $row = array (
          'id' => '1',
          'product' => '1',
          'imei' => '000000000000000',
          'model' => 'Galaxy Note 3 - 4.4.2 - API 19 - 1080x1920',
          'vcode' => '6',
          'vcoded' => '11',
          'channel' => '10001',
          'download' => '0',
          'ctime' => '1395992425',
          'year' => '2014',
          'month' => '201403',
          'week' => '201413',
          'day' => '20140328',
          'day1' => '1',
          'day2' => '1',
          'day3' => '1',
          'day4' => '1',
          'day5' => '1',
          'day6' => '1',
          'day7' => '1',
          'day14' => '1',
          'day30' => '0',
          'day60' => '0',
          'vcode_1' => '0',
          'vcode_2' => '0',
          'vcode_3' => '0',
          'vcode_6' => '20140710',
          'vcode_7' => '20140331',
          'vcode_8' => '0',
          'vcode_9' => '20140414',
          'vcode_10' => '0',
          'vcode_11' => '20140710',
          'vcode_12' => '0',
          'vcode_13' => '0',
          'vcode_14' => '0',
          'vcode_15' => '0',
          'vcode_16' => '0',
          'vcode_17' => '0',
          'vcode_18' => '0',
          'vcode_19' => '0',
          'last_act_year' => '2014',
          'last_act_month' => '201407',
          'last_act_week' => '201428',
          'last_act_day' => '20140710',
          'offday' => '77',
          'lose' => '1',
        );

        $this->printf("Job start, %s, %s", $this->memory_get_usage(), date("Y-m-d H:i:s"));
        for($i=1; $i<=$this->totalSize; $i++)
        {
            $row["id"]    = $i;
            $row["imei"]  = md5(rand(). microtime(true));
            $row["model"] = rand();

            $redis->hmset($row["imei"], $row);

            if($i % 10000 === 0)
                $this->printf("Job %s done, %s, %s", $i, $this->memory_get_usage(), date("Y-m-d H:i:s"));
        }

        $this->printf("Job start, %s, %s", $this->memory_get_usage(), date("Y-m-d H:i:s"));
    }

    function memory_get_usage()
    {
        $size = memory_get_usage(true);
        $unit=array('b ','kb','mb','gb','tb','pb');
        return sprintf("%02f", @round($size/pow(1024,($i=floor(log($size,1024)))), 2)).' '.$unit[$i];
    }
}

issue反馈:https://github.com/ideawu/ssdb/issues/448



发表评论

电子邮件地址不会被公开。