高性能高可用Redis客戶端的設計與實現
2022年電子技術應用第1期
劉世超1,2,楊 斌1,2,劉衛國1,2
1.山東大學 軟件學院,山東 濟南250101;2.國家超級計算無錫中心,江蘇 無錫214072
摘要: Redis是一個基于內存存儲的非結構化數據庫,以高I/O(Input/Output)性能和高響應速度著稱,在數據緩沖、消息隊列、Key-Value存儲等場景都發揮著重要的作用。在其支持的眾多客戶端中,C/C++客戶端Hiredis的應用尤為廣泛。對Hiredis庫做了深入分析,發現了其管道功能存在高開銷、指令存儲不當以及內存混淆問題。基于此,在32邏輯核的X86架構處理器以及64 GB內存的Linux服務器上,設計并實現了一個面向C/C++的高性能高可用Redis客戶端,通過內存預分配以及內存隔離的方法提高了大量指令批處理時的性能并解決了復雜場景下的內存混淆問題。經測試,新客戶端提高了3~7倍的指令執行效率,同時也保證了復雜場景下的內存安全以及數據準確性。
中圖分類號: TP391
文獻標識碼: A
DOI:10.16157/j.issn.0258-7998.212432
中文引用格式: 劉世超,楊斌,劉衛國. 高性能高可用Redis客戶端的設計與實現[J].電子技術應用,2022,48(1):46-52,58.
英文引用格式: Liu Shichao,Yang Bin,Liu Weiguo. Design and implementation of high-performance and high-availability redis client[J]. Application of Electronic Technique,2022,48(1):46-52,58.
文獻標識碼: A
DOI:10.16157/j.issn.0258-7998.212432
中文引用格式: 劉世超,楊斌,劉衛國. 高性能高可用Redis客戶端的設計與實現[J].電子技術應用,2022,48(1):46-52,58.
英文引用格式: Liu Shichao,Yang Bin,Liu Weiguo. Design and implementation of high-performance and high-availability redis client[J]. Application of Electronic Technique,2022,48(1):46-52,58.
Design and implementation of high-performance and high-availability redis client
Liu Shichao1,2,Yang Bin1,2,Liu Weiguo1,2
1.School of Software,Shandong University,Jinan 250101,China;2.National Supercomputing Center in Wuxi,Wuxi 214072,China
Abstract: Redis is an unstructured database based on memory storage. It is known for high I/O(Input/Output) performance and high response speed. It plays an important role in data buffering, message queues, key-value storage and other scenarios. Among the many clients it supports, the C/C++ client Hiredis is particularly widely used. This article did an in-depth analysis of the Hiredis library and found that its pipeline function has high overhead, improper instruction storage, and memory confusion problems. Based on this, this article designs and implements a C/C++-oriented high-performance and high-availability Redis client on a 32-core X86 architecture processor and a 64 GB memory Linux server. It improves the performance of processing a large number of instructions and solves the problem of memory confusion in complex scenarios through memory pre-allocation and memory isolation. After testing, the new client has improved instruction execution efficiency by 3~7 times, while also ensuring memory safety and accuracy in complex scenarios.
Key words : Redis;pipeline;Hiredis;memory confusion;performance optimization
0 引言
隨著互聯網飛速發展以及大規模應用的不斷涌現,目前已經步入了大數據時代。非結構化數據逐漸替代了傳統結構化數據并迅速占據了主導地位,為了管理形式多樣的非結構化數據,涌現了諸如MongoDB[1]、InfluxDB[2]、Elasticsearch[3]等十分有代表性的數據庫。這些數據庫雖然針對非結構化數據的存取做了很多優化,但是受限于硬盤(Hard Disk Drive,HDD)等底層存儲介質,往往無法滿足高性能場景的需求。
為了提高性能,以Redis為代表的內存數據庫應運而生。Redis是一個非結構化數據庫,支持使用非結構化語言(Not-only Structured Query Language,NoSQL)查詢。同時,Redis通過I/O(Input/Output)多路復用和DRAM(Dynamic Random Access Memory)提供了高吞吐、高并發和低時延的服務,在數據緩沖、消息隊列、Key-Value存儲等場景都發揮了重要的作用。
但是隨著大規模計算集群的算力逐漸增大,應用的數據規模也隨之變大,計算和I/O之間的“存儲墻”也變得愈發明顯。現有的Redis也遇到一些網絡和存儲方面的問題。因此如何改進Redis也受到了廣泛的重視,隨之出現了很多Redis優化的相關工作,它們從各種角度對Redis服務端或客戶端做了改進。
本文詳細內容請下載:http://www.rjjo.cn/resource/share/2000003907。
作者信息:
劉世超1,2,楊 斌1,2,劉衛國1,2
(1.山東大學 軟件學院,山東 濟南250101;2.國家超級計算無錫中心,江蘇 無錫214072)
此內容為AET網站原創,未經授權禁止轉載。