Spark常见问题解决办法
以下是在學習和使用spark過程中遇到的一些問題,記錄下來。
1、首先來說說spark任務運行完后查錯最常用的一個命令,那就是把任務運行日志down下來。 程序存在錯誤,將日志down下來查看具體原因!down日志命令:yarn logs -applicationId app_id
2、Spark性能優(yōu)化的9大問題及其解決方案
Spark程序優(yōu)化所需要關注的幾個關鍵點——最主要的是數(shù)據(jù)序列化和內(nèi)存優(yōu)化
問題1:reduce task數(shù)目不合適
解決方法:需根據(jù)實際情況調(diào)節(jié)默認配置,調(diào)整方式是修改參數(shù)spark.default.parallelism。通常,reduce數(shù)目設置為core數(shù)目的2到3倍。數(shù)量太大,造成很多小任務,增加啟動任務的開銷;數(shù)目太少,任務運行緩慢。
問題2:shuffle磁盤IO時間長
解決方法:設置spark.local.dir為多個磁盤,并設置磁盤為IO速度快的磁盤,通過增加IO來優(yōu)化shuffle性能;
問題3:map|reduce數(shù)量大,造成shuffle小文件數(shù)目多
解決方法:默認情況下shuffle文件數(shù)目為map tasks * reduce tasks. 通過設置spark.shuffle.consolidateFiles為true,來合并shuffle中間文件,此時文件數(shù)為reduce tasks數(shù)目;
問題4:序列化時間長、結果大
解決方法:Spark默認使.用JDK.自帶的ObjectOutputStream,這種方式產(chǎn)生的結果大、CPU處理時間長,可以通過設置spark.serializer為org.apache.spark.serializer.KryoSerializer。另外如果結果已經(jīng)很大,可以使用廣播變量;
問題5:單條記錄消耗大
解決方法:使用mapPartition替換map,mapPartition是對每個Partition進行計算,而map是對partition中的每條記錄進行計算;
問題6:collect輸出大量結果時速度慢
解決方式:collect源碼中是把所有的結果以一個Array的方式放在內(nèi)存中,可以直接輸出到分布式?文件系統(tǒng),然后查看文件系統(tǒng)中的內(nèi)容;
問題7:任務執(zhí)行速度傾斜
解決方式:如果是數(shù)據(jù)傾斜,一般是partition key取的不好,可以考慮其它的并行處理方式 ,并在中間加上aggregation操作;如果是Worker傾斜,例如在某些worker上的executor執(zhí)行緩慢,可以通過設置spark.speculation=true 把那些持續(xù)慢的節(jié)點去掉;
問題8:通過多步驟的RDD操作后有很多空任務或者小任務產(chǎn)生
解決方式:使用coalesce或repartition去減少RDD中partition數(shù)量;
問題9:Spark Streaming吞吐量不高
解決方式:可以設置spark.streaming.concurrentJobs
3、intellij idea直接編譯spark源碼及問題解決:
http://blog.csdn.net/tanglizhe1105/article/details/50530104
http://stackoverflow.com/questions/18920334/output-path-is-shared-between-the-same-module-error
Spark編譯:clean package -Dmaven.test.skip=true
參數(shù):-Xmx2g -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=512m
4、import Spark source code into intellj, build Error:
not found: type SparkFlumeProtocol and EventBatch
http://stackoverflow.com/questions/33311794/import-spark-source-code-into-intellj-build-error-not-found-type-sparkflumepr
<ignore_js_op>
spark_complie_config.png
5、org.apache.spark.SparkException: Exception thrown in awaitResult
set "spark.sql.broadcastTimeout" to increase the timeout
6、Apache Zeppelin編譯安裝:
Apache Zeppelin installation grunt build error:
解決方案:進入web模塊npm install;
http://stackoverflow.com/questions/33352309/apache-zeppelin-installation-grunt-build-error?rq=1
7、Spark源碼編譯遇到的問題解決:http://www.tuicool.com/articles/NBVvai
內(nèi)存不夠,這個錯誤是因為編譯的時候內(nèi)存不夠?qū)е碌?#xff0c;可以在編譯的時候加大內(nèi)存。
[ERROR] PermGen space -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors,re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions,
please read the following articles:
[ERROR] [Help 1]http://cwiki.apache.org/confluence/display/MAVEN/OutOfMemoryError
export MAVEN_OPTS="-Xmx2g -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=512m"
8、Exception in thread "main" java.lang.UnsatisfiedLinkError: no jnind4j in java.library.path
解決方案:I’m using a 64-Bit Java on Windows and still get the no jnind4j in java.library.path error It may be that you have incompatible DLLs on your PATH. In order to tell DL4J to ignore those you have to add the following as a VM parameter (Run -> Edit Configurations -> VM Options in IntelliJ): -Djava.library.path=""
9、spark2.0本地運行源碼報錯解決辦法:
修改對應pom中的依賴jar包,將scope級別由provided改為compile
運行類之前,去掉make選項;在運行vm設置中增加-Dspark.master=local
Win7下運行spark example代碼報錯:
java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: file:/SourceCode/spark-2.0.0/spark-warehouse修改SQLConf類中WAREHOUSE_PATH變量,將file:前綴改為file:/或file:///
createWithDefault("file:/${system:user.dir}/spark-warehouse")
local模式運行:-Dspark.master=local
10、解決Task not serializable Exception錯誤
方法1:將RDD中的所有數(shù)據(jù)通過JDBC連接寫入數(shù)據(jù)庫,若使用map函數(shù),可能要為每個元素都創(chuàng)建connection,這樣開銷很大,如果使用mapPartitions,那么只需要針對每個分區(qū)建立connection;mapPartitions處理后返回的是Iterator。
方法2:對未序列化的對象加@transisent引用,在進行網(wǎng)絡通信時不對對象中的屬性進行序列化
11、這個函數(shù)在func("11")調(diào)用時候正常,但是在執(zhí)行func(11)或func(1.1)時候就會報error: type mismatch的錯誤. 這個問題很好解決
針對特定的參數(shù)類型, 重載多個func函數(shù),這個不難, 傳統(tǒng)JAVA中的思路, 但是需要定義多個函數(shù)
使用超類型, 比如使用AnyVal,Any;這樣的話比較麻煩,需要在函數(shù)中針對特定的邏輯做類型轉(zhuǎn)化,從而進一步處理上面兩個方法使用的是傳統(tǒng)JAVA思路,雖然都可以解決該問題,但是缺點是不夠簡潔;在充滿了語法糖的Scala中,針對類型轉(zhuǎn)換提供了特有的implicit隱式轉(zhuǎn)化的功能;
12、org.apache.spark.shuffle.MetadataFetchFailedException: Missing an output location for shuffle
解決方案:這種問題一般發(fā)生在有大量shuffle操作的時候,task不斷的failed,然后又重執(zhí)行,一直循環(huán)下去,直到application失敗。一般遇到這種問題提高executor內(nèi)存即可,同時增加每個executor的cpu,這樣不會減少task并行度。
13、Spark ML PipeLine GBT/RF預測時報錯,java.util.NoSuchElementException: key not found: 8.0
錯誤原因:由于GBT/RF模型輸入setFeaturesCol,setLabelCol參數(shù)列名不一致導致。
解決方案:只保存訓練算法模型,不保存PipeLineModel
14、linux刪除亂碼文件,step1. ls -la; step2. find . -inum inode num -exec rm {} -rf \;
15、Caused by: java.lang.RuntimeException: Failed to commit task Caused by: org.apache.spark.executor.CommitDeniedException: attempt_201603251514_0218_m_000245_0: Not committed because the driver did not authorize commit
如果你比較了解spark中的stage是如何劃分的,這個問題就比較簡單了。一個Stage中包含的task過大,一般由于你的transform過程太長,因此driver給executor分發(fā)的task就會變的很大。所以解決這個問題我們可以通過拆分stage解決。也就是在執(zhí)行過程中調(diào)用cache.count緩存一些中間數(shù)據(jù)從而切斷過長的stage。
原文地址:http://www.kekeyun.com/thread-3382-1-1.html
轉(zhuǎn)載于:https://www.cnblogs.com/kxgdby/p/7956693.html
總結
以上是生活随笔為你收集整理的Spark常见问题解决办法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。