Kylin引入Spark引擎

1 引入Spark引擎

Kylin v2開始引入了Spark引擎,能夠在構建Cube步驟中替換MapReduce。 關於配置spark引擎的文檔,下面給出官方連接以便查閱:
http://kylin.apache.org/docs20/tutorial/cube_spark.htmlhtml

如下是配置步驟:
1.在kylin的安裝目錄下,新建目錄hadoop_confweb

mkdir  $KYLIN_HOME/hadoop_conf

2.將core-site.xml,hdfs-site.xml,hbase-site.xml,hive-site.xml,yarn-site.xml 5個配置文件放入剛纔創建的目錄。shell

(若是使用的是Apache的Hadoop,hbase,hive等,去配置文件目錄複製或者創建軟鏈接,我使用的是CDH管理集羣,那麼配置文件就在/etc/hadoop/conf,/etc/hive/conf,/etc/hbase/conf路徑下,直接複製過去)apache

cp /etc/hadoop/conf/hdfs-site.xml    $KYLIN_HOME/hadoop_conf
cp /etc/hadoop/conf/yarn-site.xml    $KYLIN_HOME/hadoop_conf
cp /etc/hadoop/conf/core-site.xml    $KYLIN_HOME/hadoop_conf
cp /etc/hbase/conf/hbase-site.xml    $KYLIN_HOME/hadoop_conf
cp /etc/hive/conf/hive-site.xml      $KYLIN_HOME/hadoop_conf

3.修改kylin.properties,添加如下配置(這裏寫hadoop-conf的全路徑,路徑根據本身hadoo_conf目錄所在位置決定)app

kylin.env.hadoop-conf-dir= $KYLIN_HOME/hadoop_conf

4 . 檢查 Spark 配置oop

Kylin 在KYLIN_HOME/spark 中嵌入一個 Spark binary (v2.1.2),全部使用 「kylin.engine.spark-conf.」 做爲前綴的 Spark 配置屬性都能在 $KYLIN_HOME/conf/kylin.properties 中進行管理。這些屬性當運行提交 Spark job 時會被提取並應用;例如,若是您配置 「kylin.engine.spark-conf.spark.executor.memory=4G」,Kylin 將會在執行 「spark-submit」 操做時使用 「–conf spark.executor.memory=4G」 做爲參數。
運行 Spark cubing 前,建議查看一下這些配置並根據您集羣的狀況進行自定義。
下面是建議配置,開啓了 Spark 動態資源分配:性能

kylin.engine.spark-conf.spark.master=yarn
kylin.engine.spark-conf.spark.submit.deployMode=cluster
kylin.engine.spark-conf.spark.dynamicAllocation.enabled=true
kylin.engine.spark-conf.spark.dynamicAllocation.minExecutors=1
kylin.engine.spark-conf.spark.dynamicAllocation.maxExecutors=1000
kylin.engine.spark-conf.spark.dynamicAllocation.executorIdleTimeout=300
kylin.engine.spark-conf.spark.yarn.queue=default
kylin.engine.spark-conf.spark.driver.memory=2G
kylin.engine.spark-conf.spark.executor.memory=4G
kylin.engine.spark-conf.spark.yarn.executor.memoryOverhead=1024
kylin.engine.spark-conf.spark.executor.cores=1
kylin.engine.spark-conf.spark.network.timeout=600
kylin.engine.spark-conf.spark.shuffle.service.enabled=true
kylin.engine.spark-conf.spark.executor.instances=1
kylin.engine.spark-conf.spark.eventLog.enabled=true
kylin.engine.spark-conf.spark.hadoop.dfs.replication=2
kylin.engine.spark-conf.spark.hadoop.mapreduce.output.fileoutputformat.compress=true
kylin.engine.spark-conf.spark.hadoop.mapreduce.output.fileoutputformat.compress.codec=org.apache.hadoop.io.compress.DefaultCodec
kylin.engine.spark-conf.spark.io.compression.codec=org.apache.spark.io.SnappyCompressionCodec
kylin.engine.spark-conf.spark.eventLog.dir=hdfs\:///kylin/spark-history
kylin.engine.spark-conf.spark.history.fs.logDirectory=hdfs\:///kylin/spark-history

5.重啓kylin網站

bin/kylin.sh stop
bin/kylin.sh startui

注意:
1.若是直接使用bin/kylin.sh restart重啓,有可能配置會不生效,我就遇到了,用上面的方式重啓就沒問題。spa

2.在kylin的web頁面上,有system選項卡,裏面有reload config,原本我覺得修改配置文件後能夠點擊此按鈕,不用重啓,可是實驗證實這樣配置也沒法生效。因此保險的方法就是按照上面的方式重啓。

2 建立和修改樣例 cube

Kylin 啓動後,訪問 Kylin 網站,在 「Advanced Setting」 頁,編輯名爲 「kylin_sales」 的 cube,將 「Cube Engine」 由 「MapReduce」 換成 「Spark」:



點擊 「Next」 進入 「Configuration Overwrites」 頁面,點擊 「+Property」 添加屬性 「kylin.engine.spark.rdd-partition-cut-mb」 其值爲 「500」 (理由以下):

樣例 cube 有兩個耗盡內存的度量: 「COUNT DISTINCT」 和 「TOPN(100)」;當源數據較小時,他們的大小估計的不太準確: 預估的大小會比真實的大不少,致使了更多的 RDD partitions 被切分,使得 build 的速度下降。500 對於其是一個較爲合理的數字。點擊 「Next」 和 「Save」 保存 cube。

3 用 Spark 構建 Cube

點擊 「Build」,選擇當前日期爲 end date。Kylin 會在 「Monitor」 頁生成一個構建 job,第 7 步是 Spark cubing。Job engine 開始按照順序執行每一步。


第 7 步是 Spark cubing,當 Kylin 執行這一步時,您能夠監視 Yarn 資源管理器裏的狀態. 點擊 「Application Master」 連接將會打開 Spark 的 UI 網頁,它會顯示每個 stage 的進度以及詳細的信息。

查看Spark 的 UI

全部步驟成功執行後,Cube 的狀態變爲 「Ready」 且您能夠像往常那樣進行查詢。

4 MapReduce和Spark引擎構建Cube時間對比

默認MapReduce引擎構建Cube,耗時15.97分鐘;


引入Spark引擎構建Cube,耗時6.78分鐘

5 進一步

若是您是 Kylin 的管理員可是對於 Spark 是新手,建議您瀏覽 Spark 文檔,別忘記相應地去更新配置。您能夠開啓 Spark 的 Dynamic Resource Allocation ,以便其對於不一樣的工做負載能自動伸縮。Spark 性能依賴於集羣的內存和 CPU 資源,當有複雜數據模型和巨大的數據集一次構建時 Kylin 的 Cube 構建將會是一項繁重的任務。若是您的集羣資源不可以執行,Spark executors 就會拋出如 「OutOfMemorry」 這樣的錯誤,所以請合理的使用。對於有 UHC dimension,過多組合 (例如,一個 cube 超過 12 dimensions),或耗盡內存的度量 (Count Distinct,Top-N) 的 Cube,建議您使用 MapReduce engine。若是您的 Cube 模型較爲簡單,全部度量都是 SUM/MIN/MAX/COUNT,源數據規模小至中等,Spark engine 將會是個好的選擇。

相關文章
相關標籤/搜索