2016-11-07 6 views
1

私は以下のようなパターンを持っています。Javaのメモリ不足エラーでどのタイプのSparkメモリを増やす必要がありますか?

def someFunction(...) : ... = 
{ 
    // Somewhere here some large string (still < 1 GB) is made ... 
    // ... and sometimes I get Java.lang.OutOfMemoryError while building that string 
} 

.... 
val RDDb = RDDa.map(x => someFunction(...)) 

ので、someFunctionの内側に、一箇所に大きな文字列はまだ(< 1ギガバイト)という大きなされていない、作られますが、その文字列を構築しながら、私は時々java.lang.OutOfMemoryError: Java heap spaceエラーが発生します。これは、私のエグゼキュータのメモリがかなり大きい場合(8 GB)でも発生します。

this articleによれば、ユーザーメモリーとスパークメモリーがあります。今私の場合では、私は増加する必要があります、ユーザーのメモリまたはスパークメモリですか?

P.S:私は1G生の文字列を簡単に8Gのメモリよりも多くを使用することができるスパークバージョン2.0

+0

あなたはこれを見たことがありますか? http://stackoverflow.com/questions/21138751/spark-java-lang-outofmemoryerror-java-heap-space – borowis

+0

私はSparkバージョン2.0を使用しています。彼らはそのバージョンで新しいメモリ管理システムを持っています。 – pythonic

答えて

2

を使用しています。 XMLのXMLEventReaderのようなストリーミング処理を使用する方が良いでしょう。

Rober SedgewickとKevin Wayneによる書籍アルゴリズムの推定を参照してください。各文字列には56バイトのオーバーヘッドがあります。 Memory estimation

私は簡単なテストプログラムを書いて、-Xmx8G

object TestStringBuilder { 
    val m = 1024 * 1024 
    def memUsage(): Unit = { 
    val runtime = Runtime.getRuntime 

    println(
     s"""max: ${runtime.maxMemory()/m} M 
     |allocated: ${runtime.totalMemory()/m} M 
     |free: ${runtime.freeMemory()/m} M""".stripMargin) 
    } 

    def main(args: Array[String]): Unit = { 
    val builder = new StringBuilder() 
    val size = 10 * m 
    try { 
     while (true) { 
     builder.append(Math.random()) 
     if (builder.length % size == 0) { 
      println(s"len is ${builder.length/m} M") 
      memUsage() 
     } 
     } 
    } 
    catch { 
     case ex: OutOfMemoryError => 
     println(s"OutOfMemoryError len is ${builder.length/m} M") 
     memUsage() 
     case ex => 
     println(ex) 
    } 
    } 
} 

で実行出力は次のようなものかもしれません。

len is 140 M 
max: 7282 M allocated: 673 M free: 77 M 
len is 370 M 
max: 7282 M allocated: 2402 M free: 72 M 
len is 470 M 
max: 7282 M allocated: 1479 M free: 321 M 
len is 720 M 
max: 7282 M allocated: 3784 M free: 314 M 
len is 750 M 
max: 7282 M allocated: 3784 M free: 314 M 
len is 1020 M 
max: 7282 M allocated: 3784 M free: 307 M 
OutOfMemoryError len is 1151 M 
max: 7282 M allocated: 3784 M free: 303 M 
+0

なぜ、生の文字列がその多くのメモリを使用するのでしょうか?それは非常識です! – pythonic

0

ロッキーです。それとは別に、RDDのマップ実行中に使用されるスパークメモリです。