ideawu / ssdb

SSDB - A fast NoSQL database, an alternative to Redis
http://ssdb.io/
BSD 3-Clause "New" or "Revised" License
8.19k stars 1.4k forks source link

ssdb vs redis hmset的性能对比悬殊比较大 #448

Closed vus520 closed 10 years ago

vus520 commented 10 years ago

mac os redis 2.8.13 ssdb 1.7.0.0

ssdb Job 10000 done, 2.000000 mb, 2014-10-06 21:39:02 Job 20000 done, 2.000000 mb, 2014-10-06 21:39:08 Job 30000 done, 2.000000 mb, 2014-10-06 21:39:14 Job 40000 done, 2.000000 mb, 2014-10-06 21:39:22 Job 50000 done, 2.000000 mb, 2014-10-06 21:39:30 Job 60000 done, 2.000000 mb, 2014-10-06 21:39:38 Job 70000 done, 2.000000 mb, 2014-10-06 21:39:46 Job 80000 done, 2.000000 mb, 2014-10-06 21:39:54 Job 90000 done, 2.000000 mb, 2014-10-06 21:40:03 Job 100000 done, 2.000000 mb, 2014-10-06 21:40:11 ... Job 900000 done, 2.000000 mb, 2014-10-06 21:54:56 Job 910000 done, 2.000000 mb, 2014-10-06 21:55:09 Job 920000 done, 2.000000 mb, 2014-10-06 21:55:20 Job 930000 done, 2.000000 mb, 2014-10-06 21:55:31 Job 940000 done, 2.000000 mb, 2014-10-06 21:55:44 Job 950000 done, 2.000000 mb, 2014-10-06 21:55:56 Job 960000 done, 2.000000 mb, 2014-10-06 21:56:10 Job 970000 done, 2.000000 mb, 2014-10-06 21:56:22 Job 980000 done, 2.000000 mb, 2014-10-06 21:56:35 Job 990000 done, 2.000000 mb, 2014-10-06 21:56:47 Job 1000000 done, 2.000000 mb, 2014-10-06 21:56:59

redis Job 10000 done, 2.000000 mb, 2014-10-06 21:49:51 Job 20000 done, 2.000000 mb, 2014-10-06 21:49:54 Job 30000 done, 2.000000 mb, 2014-10-06 21:49:56 Job 40000 done, 2.000000 mb, 2014-10-06 21:49:59 Job 50000 done, 2.000000 mb, 2014-10-06 21:50:01 Job 60000 done, 2.000000 mb, 2014-10-06 21:50:03 Job 70000 done, 2.000000 mb, 2014-10-06 21:50:06 Job 80000 done, 2.000000 mb, 2014-10-06 21:50:08 Job 90000 done, 2.000000 mb, 2014-10-06 21:50:10 Job 100000 done, 2.000000 mb, 2014-10-06 21:50:13 ... Job 900000 done, 2.000000 mb, 2014-10-06 21:53:19 Job 910000 done, 2.000000 mb, 2014-10-06 21:53:21 Job 920000 done, 2.000000 mb, 2014-10-06 21:53:23 Job 930000 done, 2.000000 mb, 2014-10-06 21:53:26 Job 940000 done, 2.000000 mb, 2014-10-06 21:53:28 Job 950000 done, 2.000000 mb, 2014-10-06 21:53:30 Job 960000 done, 2.000000 mb, 2014-10-06 21:53:32 Job 970000 done, 2.000000 mb, 2014-10-06 21:53:34 Job 980000 done, 2.000000 mb, 2014-10-06 21:53:36 Job 990000 done, 2.000000 mb, 2014-10-06 21:53:38 Job 1000000 done, 2.000000 mb, 2014-10-06 21:53:41

ideawu commented 10 years ago

从Job 10000 done, 2.000000 mb, 2014-10-06 21:39:02这样的文字中, 我无法看出你标题中所说明的问题. 请正确地反馈问题.

vus520 commented 10 years ago

任务是循环插入100万个key,每1万次set的时间开销,ssdb的时间开销是redis的4倍左右,数据量越大插入越慢

ideawu commented 10 years ago

建议你给出可执行的程序, 以及操作步骤. 谢谢.

vus520 commented 10 years ago

我把结果帖到了这里: http://www.4wei.cn/archives/1002361

代码执行方式: php redisTest.php

redisTest.php代码如下:

#!/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];
    }
}