天天看點

開發SparkStreaming消費Kafka的應用要注意OutOfMemoryError遇到的問題解決方案

遇到的問題

其他部門的同僚開發了一個SparkStreaming消費Kafka資料的應用,運作了一個多月後,不能消費資料了,但是應用在Yarn上一直處于RUNNING狀态。

進入ApplicationMaster檢視Spark UI,發現了一個奇怪的現象

在Streaming頁面中,原本4s執行一批次的資料處理,在某個時刻就不再執行了。

打開了stderr日志

Exception in thread “pool-23-thread-1” java.lang.OutOfMemoryError: unable to create new native thread

at java.lang.Thread.start0(Native Method)

at java.lang.Thread.start(Thread.java:717)

at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:957)

at java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:1025)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

at java.lang.Thread.run(Thread.java:748)

Exception in thread “JobGenerator” java.lang.OutOfMemoryError: unable to create new native thread

at java.lang.Thread.start0(Native Method)

at java.lang.Thread.start(Thread.java:717)

at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:957)

at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1367)

at org.apache.spark.streaming.CheckpointWriter.write(Checkpoint.scala:290)

at org.apache.spark.streaming.scheduler.JobGenerator.doCheckpoint(JobGenerator.scala:297)

at org.apache.spark.streaming.scheduler.JobGenerator.org$apache$spark$streaming$scheduler$JobGenerator$$processEvent(JobGenerator.scala:186)

at org.apache.spark.streaming.scheduler.JobGenerator$$anon$1.onReceive(JobGenerator.scala:89)

at org.apache.spark.streaming.scheduler.JobGenerator$$anon$1.onReceive(JobGenerator.scala:88)

at org.apache.spark.util.EventLoop$$anon$1.run(EventLoop.scala:48)

奇怪的是,Executor發生了OutOfMemory異常,卻沒有導緻整個作業Fail掉,進而監控作業運作狀态的應用程式沒有發現這個作業已經挂掉了,導緻沒有及時預警

作業資源配置

Executor個數:1,每個Executor記憶體:1G

解決方案

1、将Executor記憶體提升至2G,重新送出運作。

2、建議代碼開發者檢查代碼,找一找為什麼Executor程序挂掉了而Driver程序仍然沒有挂掉的原因。

個人猜測,可能代碼導緻了Executor抛出的Error沒有傳遞給Driver,或者是Driver得到了Executor的Error但沒有異常終止.。因為他們開發的其他SparkStreaming作業,在運作時Executor抛出的Exception都引起了Driver的Fail。

繼續閱讀