調優 | Apache Hudi應用調優指南

leesf發表於2020-06-06

通過Spark作業將資料寫入Hudi時,Spark應用的調優技巧也適用於此。如果要提高效能或可靠性,請牢記以下幾點。

輸入並行性:Hudi對輸入進行分割槽預設併發度為1500,以確保每個Spark分割槽都在2GB的限制內(在Spark2.4.0版本之後去除了該限制),如果有更大的輸入,則相應地進行調整。我們建議設定shuffle的併發度,配置項為hoodie.[insert|upsert|bulkinsert].shuffle.parallelism,以使其至少達到input_data_size/500MB。

Off-heap(堆外)記憶體:Hudi寫入parquet檔案,需要使用一定的堆外記憶體,如果遇到此類故障,請考慮設定類似spark.yarn.executor.memoryOverheadspark.yarn.driver.memoryOverhead的值。

Spark 記憶體:通常Hudi需要能夠將單個檔案讀入記憶體以執行合併或壓縮操作,因此執行程式的記憶體應足以容納此檔案。另外,Hudi會快取輸入資料以便能夠智慧地放置資料,因此預留一些spark.memory.storageFraction通常有助於提高效能。

調整檔案大小:設定limitFileSize以平衡接收/寫入延遲與檔案數量,並平衡與檔案資料相關的後設資料開銷。

時間序列/日誌資料:對於單條記錄較大的資料庫/ nosql變更日誌,可調整預設配置。另一類非常流行的資料是時間序列/事件/日誌資料,它往往更加龐大,每個分割槽的記錄更多。在這種情況下,請考慮通過.bloomFilterFPP()/bloomFilterNumEntries()來調整Bloom過濾器的精度,以加速目標索引查詢時間,另外可考慮一個以事件時間為字首的鍵,這將使用範圍修剪並顯著加快索引查詢的速度。

GC調優:請確保遵循Spark調優指南中的垃圾收集調優技巧,以避免OutOfMemory錯誤。[必須]使用G1 / CMS收集器,其中新增到spark.executor.extraJavaOptions的示例如下:

-XX:NewSize=1g -XX:SurvivorRatio=2 -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:CMSInitiatingOccupancyFraction=70 -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime -XX:+PrintTenuringDistribution -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/hoodie-heapdump.hprof

OutOfMemory錯誤:如果出現OOM錯誤,則可嘗試通過如下配置處理:spark.memory.fraction = 0.2,spark.memory.storageFraction = 0.2允許其溢位而不是OOM(速度變慢與間歇性崩潰相比)。

以下是完整的生產配置

spark.driver.extraClassPath /etc/hive/conf
spark.driver.extraJavaOptions -XX:+PrintTenuringDistribution -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCTimeStamps -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/hoodie-heapdump.hprof
spark.driver.maxResultSize 2g
spark.driver.memory 4g
spark.executor.cores 1
spark.executor.extraJavaOptions -XX:+PrintFlagsFinal -XX:+PrintReferenceGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintAdaptiveSizePolicy -XX:+UnlockDiagnosticVMOptions -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/hoodie-heapdump.hprof
spark.executor.id driver
spark.executor.instances 300
spark.executor.memory 6g
spark.rdd.compress true
 
spark.kryoserializer.buffer.max 512m
spark.serializer org.apache.spark.serializer.KryoSerializer
spark.shuffle.service.enabled true
spark.sql.hive.convertMetastoreParquet false
spark.submit.deployMode cluster
spark.task.cpus 1
spark.task.maxFailures 4
 
spark.yarn.driver.memoryOverhead 1024
spark.yarn.executor.memoryOverhead 3072
spark.yarn.max.executor.failures 100

相關文章