2
2つの同時スパークジョブで同じRDDを使用する方法はありますか?同時スパークジョブでRDDを共有する方法
たとえば、f
が計算されている間(ジョブ2)、b
をディスク(ジョブ1)に書き込もうとしています。しかし、スパークは一度に1つのジョブしか実行していないようです。
val conf = new SparkConf()
val sc = new SparkContext(conf)
val a = sc.parallelize(0 until 1000)
val b = a.mapPartitions(it => { Thread.sleep(5000); it })
// Compute b
b.persist().foreachPartition(_ => {})
val c = b.mapPartitions(it => { Thread.sleep(5000); it })
val d = c.mapPartitions(it => { Thread.sleep(5000); it })
val e = d.mapPartitions(it => { Thread.sleep(5000); it })
val f = e.mapPartitions(it => { Thread.sleep(5000); it })
// Concurrent actions on b and f (f uses b)
val actionFuts = List(
// Job 1
Future {
Thread.sleep(1000)
b.saveAsTextFile("output.ignore/test/b.txt")
},
// Job 2
Future {
f.saveAsTextFile("output.ignore/test/f.txt")
}
)
Await.result(Future.sequence(actionFuts).map(_ =>()), Duration.Inf)