邵芳 王勇



摘 要:HBase原有負載均衡算法策略是保證每個Region Server的Region數目相同。但每個Region的訪問并不均等,可能造成負載不均衡情況,產生熱點數據,影響請求響應效率。部分Region會成為熱點,導致一些Region Server負載過重。為提高HBase數據庫整體性能,將數據熱度因素考慮在內,使用預測方法設計HBase負載均衡算法,把預測數據的熱度作為Region Server負載。實驗表明,優化后的負載均衡算法可在一定程度上提高HBase數據庫性能。
關鍵詞:HBase;大數據;負載均衡;熱點數據;預測
DOI:10. 11907/rjdk. 181331
中圖分類號:TP312文獻標識碼:A文章編號:1672-7800(2019)001-0104-04
Abstract: In order to improve the performance of HBase database, the original load balancing algorithm of HBase is analyzed. The original algorithm strategy ensures that the number of Region per Region Server is the same, but because the access of each Region is not equal, it may cause the load imbalance, generate hot data, and affect the response efficiency of the request. Part of the Region will become a hot spot, which some Region Server overload. It is very important to consider the impact of the heat of the data on the load balancing of a distributed database. Therefore, the prediction method is used to design the HBase load balancing algorithm and predict the heat of the data as the load of the Region Server. The experiment shows that the optimized load balancing algorithm can improve the performance of HBase database.
0 引言
隨著互聯網的迅猛發展,利用傳統關系型數據庫解決大規模數據集存在的問題引起廣泛關注,NoSQL(Not Only SQL,NoSQL ,非關系型數據庫)研究成為熱點[1]。互聯網產生的數據量增長迅速,對于海量數據的不斷增長,要求系統具有良好的橫向擴展性,集群技術能夠解決此類問題[2]。集群之間能資源共享,控制任務分發調度性能,并且隨著數據的增加進行擴展。
Apache HBase是開源分布式NoSQL數據庫,HBase技術源于《Bigtable:一個結構化數據的分布式存儲系統》這篇Google論文[3]。HBase作為一個分布式列存儲數據庫,因其高可用性、可擴展性等特征而被廣泛應用。HBase和Hadoop無縫集成,利用HDFS實現數據的底層分布式存儲[4]。HBase數據庫是列式存儲的數據庫,表的列數可在建表后動態增加,對于無實際值的列不進行存儲,節省空間。健康大數據平臺使用HBase數據庫,負載不均問題直接影響到整個集群的性能。隨著大量數據的注入,HBase Region數目的增加或不均等地對Region Server訪問[5],HBase通過負載均衡算法保證盡量均等地分配每個Region Server。國內外很多知名企業都使用NoSQL 數據庫存儲數據,如百度、新浪、Google、騰訊、阿里巴巴、Facebook等[6]。NoSQL數據庫相關技術還在不斷發展,互聯網時代海量數據的應用需求為NoSQL的發展提供了源源不斷的動力。因此,對非關系型數據庫HBase負載均衡的研究具有重要意義。
1 HBase負載均衡算法分析
如果Region Server存在負載不均衡,那么部分節點的堵塞情況就很容易發生,進而影響整體性能[7]。通過多種措施可以對HBase進行性能調優[8],在0.92版本以后,HBase的負載均衡算法可通過實現了LoadBalancer接口的hbase.master.loadbalancer.class來自定義,實現定制的均衡策略,負載均衡策略是可插拔的。
1.1 SimpleLoadBalancer負載均衡策略分析
在HBase0.94版本中,默認使用SimpleLoadBalancer負載均衡算法,算法步驟是:計算每個Region Server中Region的總數目,用Region總數除以Region Server的數目得到每個Region Server的Region平均數目averageNum,最小值min的值為floor(averageNum),最大值max的值為ceiling(averageNum)[9]。如果所有Region Server都在此范圍內,說明不需要進行負載均衡操作。否則,從負載Region數目最大的Region Server開始遍歷到負載數目小于等于max為止,把這些需要轉移的Region存儲起來,設置原地址和目的地址(暫時為空)。從負載Region數目最小的Region Server開始遍歷到負載數目大于等于min為止,設置為目的地址。如果仍有負載小于min的Region Server,則從Region數目最多的Region Server中取出一個Region轉移到此Region Server中,直到沒有負載小于min的Region Server為止。如果仍然存在目的地址為空,則從負載最低的Region Server開始遍歷,如果此Region Server負載小于max則將其地址設置為目的地址,直到沒有為空的目的地址。若所有目的地址都不為空,則返回。否則,沒有目的地址的Region仍放在原Region Server中。