redis和ssdb讀取效能對比

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   io   檔案   資料   

      最近關注了一下ssdb,它的特點是基於檔案儲存體系統所以它支撐量大的資料而不因為記憶體的限制受取約束.從官網的測試報告來看其效能也非常出色和redis相當,因此可以使用它來代替redis來進行k-v資料業務的處理.想法總是美好的,不過現實中就可能帶點骨感.

    幸好ssdb是相容redis的部份協議,所以直接用redis client庫就可以進行一個壓力測試.以於針對Redis和ssdb的幾個讀操進行一個簡單的效能測試對比,這個測試不是直接在本機調用Redis和ssdb. 而是通過一個程式在別的伺服器上調用.測試指令(get,hget,lregion)以下是測試結果

?

測試代碼

 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高出一倍的樣子.

    以上測試結果緊緊是是一些情況下的效能測試對比,不能完全表述出兩者在應用的差距的結果,如果需要用到這些產品的同學不防在實施前進行一些測試為實施選擇提供一個更可靠的結果.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.