redis和ssdb读取性能对比

      最近关注了一下ssdb,它的特点是基于文件存储系统所以它支撑量大的数据而不因为内存的限制受取约束.从官网的测试报告来看其性能也非常出色和redis相当,因此可以使用它来代替redis来进行k-v数据业务的处理.想法总是美好的,不过现实中就可能带点骨感.

    幸好ssdb是兼容redis的部份协议,所以直接用redis client库就可以进行一个压力测试.以于针对Redis和ssdb的几个读操进行一个简单的性能测试对比,这个测试不是直接在本机调用Redis和ssdb. 而是通过一个程序在别的服务器上调用.测试指令(get,hget,lregion)以下是测试结果截图

redis和ssdb读取性能对比?

测试代码

 class Test
    {
        long mCount = 0;

        long mIndex = 0;

        private bool mRuning = true;

        public long Count
        {
            get
            {
                return mCount;
            }
        }

        public void Execute()
        {
            Console.WriteLine("* -----------------------------------------------");
            Console.WriteLine("* redis get");
            
            ConsoleWait.Start();
            string result = OnTest(Config.RedisClient,GetHandler);
            ConsoleWait.End();
            Console.WriteLine(result);

            Console.WriteLine("* ssdb get");
            ConsoleWait.Start();
            result = OnTest(Config.SSDBClient, GetHandler);
            ConsoleWait.End();
            Console.WriteLine(result);
            Console.WriteLine("* -----------------------------------------------");

            //
            Console.WriteLine("* redis lregion[1-2]");
            ConsoleWait.Start();
            result = OnTest(Config.RedisClient, LRegionHandler1TO2);
            ConsoleWait.End();
            Console.WriteLine(result);

            Console.WriteLine("* ssdb lregion[1-2]");
            ConsoleWait.Start();
            result = OnTest(Config.SSDBClient, LRegionHandler1TO2);
            ConsoleWait.End();
            Console.WriteLine(result);
            Console.WriteLine("* -----------------------------------------------");

            //
            Console.WriteLine("* redis lregion[50-60]");
            ConsoleWait.Start();
            result = OnTest(Config.RedisClient, LRegionHandler1TO2);
            ConsoleWait.End();
            Console.WriteLine(result);

            Console.WriteLine("* ssdb lregion[50-60]");
            ConsoleWait.Start();
            result = OnTest(Config.SSDBClient, LRegionHandler1TO2);
            ConsoleWait.End();
            Console.WriteLine(result);
            Console.WriteLine("* -----------------------------------------------");

            //
            Console.WriteLine("* redis lregion[100-110]");
            ConsoleWait.Start();
            result = OnTest(Config.RedisClient, LRegionHandler1TO2);
            ConsoleWait.End();
            Console.WriteLine(result);


            Console.WriteLine("* ssdb lregion[100-110]");
            ConsoleWait.Start();
            result = OnTest(Config.SSDBClient, LRegionHandler1TO2);
            ConsoleWait.End();
            Console.WriteLine(result);
            Console.WriteLine("* -----------------------------------------------");

            //
            Console.WriteLine("* redis hget");
            ConsoleWait.Start();
            result = OnTest(Config.RedisClient, HGetHandler);
            ConsoleWait.End();
            Console.WriteLine(result);

            Console.WriteLine("* ssdb hget");
            ConsoleWait.Start();
            result = OnTest(Config.SSDBClient, HGetHandler);
            ConsoleWait.End();
            Console.WriteLine(result);
            Console.WriteLine("* -----------------------------------------------");
        }

        private void HGetHandler(RedisClient e)
        {
            while (mRuning)
            {
                long index = System.Threading.Interlocked.Increment(ref mIndex);
                ProtobufKey key = "user_" + Data.Import.Users[(int)(index % Data.Import.Users.Count)].Name;
                key.Get<Model.Order, Model.Employee, Model.Customer>(e);
                System.Threading.Interlocked.Increment(ref mCount);
            }
        }

        private void LRegionHandler1TO2(RedisClient e)
        {
            while (mRuning)
            {
                ProtobufList<Model.Order> list = "Orders";
                list.Range(1, 2, e);
                System.Threading.Interlocked.Increment(ref mCount);
            }
        }

        private void LRegionHandler50TO60(RedisClient e)
        {
            while (mRuning)
            {
                ProtobufList<Model.Order> list = "Orders";
                list.Range(50, 60, e);
                System.Threading.Interlocked.Increment(ref mCount);
            }
        }
        private void LRegionHandler100TO110(RedisClient e)
        {
            while (mRuning)
            {
                ProtobufList<Model.Order> list = "Orders";
                list.Range(100, 110, e);
                System.Threading.Interlocked.Increment(ref mCount);
            }
        }

        private  void GetHandler(RedisClient e)
        {
            while (mRuning)
            {
                long index = System.Threading.Interlocked.Increment(ref mIndex);
                ProtobufKey key = "user_" + Data.Import.Users[(int)(index % Data.Import.Users.Count)].Name;
                key.Get<Model.User>(e);
                System.Threading.Interlocked.Increment(ref mCount);
            }
        }

        private string OnTest(RedisClient client,Action<RedisClient> handler)
        {
            mCount = 0;
            mRuning = true;
            for (int i = 0; i < 20; i++)
            {
                System.Threading.ThreadPool.QueueUserWorkItem((o) =>
                {

                    GetHandler((RedisClient)o);
                }, client);
            }
            int s = 20;
            while (s > 0)
            {
                System.Threading.Thread.Sleep(1000);
                s--;
            }
            mRuning = false;
            System.Threading.Thread.Sleep(1000);
            return string.Format("* [seconds:{1}/total:{0}]", mCount, mCount / 20);
        }
    }

    从测试结果看来差距还是非常明显,并不象官网那样说得这么理想.虽然SSDB效率上不如REDIS,但其基于磁盘存储有着其最大的优势,毕竟很多业务数据远超过服务器内存的容量.

     SSDB的测试结果不理想也许是硬件环境受限,如果有个SSD硬盘的测试环境估计也得到一个更好的结果,但在测试过程中发现一个问题就是SSDB占用的CPU资源也是非常大的,在以上测试过程SSDB的并发效率比不上REDIS,同时CPU损耗上基本要比REDIS高出一倍的样子.

    以上测试结果紧紧是是一些情况下的性能测试对比,不能完全表述出两者在应用的差距的结果,如果需要用到这些产品的同学不防在实施前进行一些测试为实施选择提供一个更可靠的结果.

redis和ssdb读取性能对比,布布扣,bubuko.com

redis和ssdb读取性能对比

上一篇:QT QSqlQuery QSqlQueryModel


下一篇:SQL数据类型介绍