閱讀730 返回首頁    go 阿裏雲 go 技術社區[雲棲]


HBase Phoenix助力海量數據實時分析

前言

phoenix這個項目我一直接觸不多,在去年接觸的一家公司使用phoenix分析數百億的記錄並且在秒級別返回的延遲時,筆者才慢慢探究一些phoenix的內幕。上個星期跟一位phoenix的PMC&Committer聊了聊phoenix的定位及未來的發展,發現phoenix還是比較競爭力的,從最近phoenix不斷的發布版本來看,phoenix也在迅速的發展。在phoenix社區也組織了phoenixCon來宣傳phoenix:PhoenixCon 2017。本文的目的是想梳理下phoenix的架構及內幕,phoenix怎麼支持海量數據的實時分析。

架構

phoenix是專門為HBase增強的,具體說就是HBase有幾個方麵的問題:

  • HBase比較底層,沒有SQL接口,對於希望使用SQL的同學轉換成本高
  • HBase不支持二級索引(HBase自身也有一些方案,不過還是以phoenix支持最佳)
  • HBase不支持事務

最近幾年,從SQL到NO-SQL,再到NewSQL的興起。其實NewSQL本身並沒有什麼大技術的創新點(持久內存等硬件本身除外),隻是架構的創新或者說是一種混合架構。Phoenix是不是NewSQL,其實並不重要,重要的是他解決了什麼問題。
大致的phoenix嵌入進HBase的圖如下所示:
image

phoenix最主要給HBase添加了二級索引、SQL的支持。至於事物及一些其它的支持,算是錦上添花,讓phoenix越看越是NewSQL。phoenix的官方文檔比較全,筆者就不搬了。

特別地:

  • 支持join(hash join\Sort-Merge Join)
  • 相關SQL的優化(現在正在對接Calcite:https://calcite.apache.org/ )
  • 支持jdbc直接訪問

性能

phoenix適合海量數據的實時分析需求:

  • phoenix基本通過建立索引在海量數據上查詢少量數據,並且基本實時返回。
  • phoenix也支持做一些複雜SQL操作,包括join,sub-query等。
  • phoenix不適合於ETL,比如10T數據變為10T數據。

如下有一張跟Hadoop體係hive的對比:
image
出自:https://phoenix.apache.org/performance.html

在四個場景中,Hive On HBase最差,phoenix(key filter)最快,究其原因就是phoenix(key filter)走了index,查詢時間基本在1s以內。另外,Hive on HDFS跟phoenix on HDFS對比,在5000w條數據量左右是分界線,時間在20s左右,其實hive啟動時間都在5s左右,再跑一個MR/TEZ作業都在10s左右(後續有一定的優化)。

測試數據:https://phoenix-bin.github.io/client/performance/phoenix-20160718043634.htm
其中包括了主要的一些場景,比如:Aggregation、 Count Distinct、 IN/LIKE Clause、LIMIT,測試數據集合基本是百萬級別,時間在數秒左右。

雲HBase

目前雲HBase也已經支持phoenix4.6版本,用戶可以直接下載 https://hbase-cloud2.oss-cn-hangzhou.aliyuncs.com/phoenix-4.6.0-HBase-1.1.tar.gz
我們簡單演示下join的功能,參考:https://phoenix.apache.org/joins.html

CREATE TABLE IF NOT EXISTS Customers(
CustomerID  VARCHAR NOT NULL,
CustomerName  VARCHAR,
Country VARCHAR
CONSTRAINT pk PRIMARY KEY(CustomerID)
);


CREATE TABLE IF NOT EXISTS Items(
ItemID  VARCHAR NOT NULL,
ItemName  VARCHAR,
Price Decimal
CONSTRAINT pk PRIMARY KEY(ItemID)
);

SELECT O.OrderID, C.CustomerName
FROM ORDERS AS O
INNER JOIN CUSTOMERS AS C
ON O.CustomerID = C.CustomerID;

0: jdbc:phoenix:hb-bp18zlo0b209p7g23-001.hbas> CREATE INDEX iOrders ON Orders (ItemID) INCLUDE (CustomerID, Quantity);
5 rows affected (1.519 seconds)
0: jdbc:phoenix:hb-bp18zlo0b209p7g23-001.hbas> CREATE INDEX i2Orders ON Orders (CustomerID) INCLUDE (ItemID, Quantity);
5 rows affected (1.502 seconds)
0: jdbc:phoenix:hb-bp18zlo0b209p7g23-001.hbas> CREATE INDEX iItems ON Items (ItemName) INCLUDE (Price);
6 rows affected (1.427 seconds)


0: jdbc:phoenix:hb-bp18zlo0b209p7g23-001.hbas> SELECT O.OrderID, C.CustomerName, C.Country, O.Date
. . . . . . . . . . . . . . . . . . . . . . .> FROM Orders AS O
. . . . . . . . . . . . . . . . . . . . . . .> INNER JOIN Customers AS C
. . . . . . . . . . . . . . . . . . . . . . .> ON O.CustomerID = C.CustomerID;
+------------------------------------------+------------------------------------------+------------------------------------------+-------------------------+
|                O.ORDERID                 |              C.CUSTOMERNAME              |                C.COUNTRY                 |         O.DATE          |
+------------------------------------------+------------------------------------------+------------------------------------------+-------------------------+
| 1630781                                  | Alps Nordic AB                           | Sweden                                   | 0009-01-22 13:00:00.000 |
| 1630782                                  | Salora Oy                                | Finland                                  | 0009-02-22 13:00:00.000 |
| 1630783                                  | Logica                                   | Belgium                                  | 0009-03-22 13:00:00.000 |
| 1630784                                  | Alps Nordic AB                           | Sweden                                   | 0009-04-22 13:00:00.000 |
| 1630785                                  | Deister Electronics                      | Germany                                  | 0009-05-22 13:00:00.000 |
+------------------------------------------+------------------------------------------+------------------------------------------+-------------------------+
5 rows selected (0.136 seconds)


0: jdbc:phoenix:hb-bp18zlo0b209p7g23-001.hbas> SELECT ItemName, sum(Price * Quantity) AS OrderValue
. . . . . . . . . . . . . . . . . . . . . . .> FROM Items
. . . . . . . . . . . . . . . . . . . . . . .> JOIN Orders
. . . . . . . . . . . . . . . . . . . . . . .> ON Items.ItemID = Orders.ItemID
. . . . . . . . . . . . . . . . . . . . . . .> WHERE Orders.CustomerID > 'C002'
. . . . . . . . . . . . . . . . . . . . . . .> GROUP BY ItemName;
+------------------------------------------+------------------------------------------+
|                 ITEMNAME                 |                ORDERVALUE                |
+------------------------------------------+------------------------------------------+
| BX016                                    | 10374                                    |
| MU3508                                   | 1.44E+4                                  |
| XT2217                                   | 46436                                    |
+------------------------------------------+------------------------------------------+
3 rows selected (0.184 seconds)

最後

歡迎加入阿裏雲雲HBase技術交流群:https://yq.aliyun.com/articles/82911

最後更新:2017-05-18 20:31:28

  上一篇:go  找bug記(1)
  下一篇:go  小白楊入住雲棲社區