[SPARK-20638][Core]Optimize the CartesianRDD to reduce repeatedly data fetching#17898
[SPARK-20638][Core]Optimize the CartesianRDD to reduce repeatedly data fetching#17898jtengyp wants to merge 1 commit intoapache:masterfrom
Conversation
In compute, group each iterator to multiple groups, reducing repeatedly data fetching.
|
Please read http://spark.apache.org/contributing.html |
| y <- rdd2.iterator(currSplit.s2, context)) yield (x, y) | ||
| val groupSize = 500; | ||
| for (x <- rdd1.iterator(currSplit.s1, context).grouped(groupSize); | ||
| y <- rdd2.iterator(currSplit.s2, context).grouped(groupSize); |
There was a problem hiding this comment.
One disadvantage I can think now is, longer waiting time for first element.
There was a problem hiding this comment.
Pardon, doesn't this change the type of the result? you're iterating over groupings not elements, and emitting pairs of groups. As in below, but maybe I'm missing something.
scala> val foo = List(1,2,3)
foo: List[Int] = List(1, 2, 3)
scala> val bar = List(4,5,6)
bar: List[Int] = List(4, 5, 6)
scala> for (x <- foo; y <- bar) yield (x, y)
res0: List[(Int, Int)] = List((1,4), (1,5), (1,6), (2,4), (2,5), (2,6), (3,4), (3,5), (3,6))
scala> (for (x <- foo.grouped(2); y <- bar.grouped(2)) yield (x, y)).foreach(println)
(List(1, 2),List(4, 5))
(List(1, 2),List(6))
(List(3),List(4, 5))
(List(3),List(6))
There was a problem hiding this comment.
The actual yield is on (i, j) and not (x, y) - the next line adds the iteration over the groupings :-)
There was a problem hiding this comment.
I agree with @viirya - there is also an implicit assumption of size here : the batch will get deserialized into memory.
By default, we have kept the iterator model going in spark without needing to buffer (iirc).
There was a problem hiding this comment.
I working on this too. But the optimize method maybe similar to the pr which @viirya opened before, cache the second iterator into local. The code is ready, maybe open a pr in recently. In this patch, I worry about whether we can accurately control the size of the buffer. If we should cache it by BlockManager or MemoryConsumer?
There was a problem hiding this comment.
Oh haha right. Hm, but isn't this better solved 'upstream' by buffering an iterator somewhere? or just buffering the iterator right here?
|
Maybe create a JIRA and update title as Spark PR convention. Since this should be a performance improvement, the difference is expected to show. |
|
Here is my test: val groupSize = 1000 |
|
Test build #3697 has finished for PR 17898 at commit
|
In compute, group each iterator to multiple groups, reducing repeatedly data fetching.
What changes were proposed in this pull request?
In compute, group each iterator to multiple groups. Thus in the second iteration, the data with be fetched (num of data)/groupSize times, rather than (num of data) times.
How was this patch tested?
The existing UT.