7

There are indications that joins in Spark are implemented with / based on the cogroup function/primitive/transform. So let me focus first on cogroup - it returns a result which is RDD consisting of essentially ALL elements of the cogrouped RDDs. Said in another way - for every key in each of the cogrouped RDDs there is at least one element from at least one of the cogrouped RDDs.

That would mean that when smaller, moreover streaming e.g. JavaPairDstreamRDDs keep getting joined with much larger, batch RDD that would result in RAM allocated for multiple instances of the result (cogrouped) RDD a.k.a essentially the large batch RDD and some more ... Obviously the RAM will get returned when the DStream RDDs get discard and they do on a regular basis, but still that seems as unnecessary spike in the RAM consumption

I have two questions:

  1. Is there anyway to control the cogroup process more "precisely" e.g. tell it to include I the cogrouped RDD only elements where there are at least one element from EACH of the cogrouped RDDs per given key. Based on the current cogroup API this is not possible

  2. If the cogroup is really such a sledgehammer and secondly the joins are based on cogroup then even though they can present a prettier picture in terms of the end result visible to the end user does that mean that under the hood there is still the same atrocious RAM consumption going on

1 Answer 1

5

It is not that bad. It largelly depends on the granularity of your partitioning. Cogroup will first shuffle by key, in disk, to distinct executor nodes. For each key, yes, the entire set of all elements with that key, for both RDDs, will be loaded in RAM and given to you. But not all keys need to be in RAM at any given time, so unless your data is really skewed you will not suffer for it much.

4
  • Will using repartitioning with same partitioner before cogrouping help?
    – Benak Raj
    Oct 8, 2016 at 5:01
  • I have more than 5 JavaPairRDD, contain a master pairRDD. i want to combine these all based master pairRDD. How can i do this ?
    – junsid
    May 5, 2017 at 11:56
  • How to use cogroup for large datasets like when I use collect() it throws out of memory exception rdd1 = rdd2.cogroup(rdd3).collect. Can you help on this issue [stackoverflow.com/questions/47180307/…. can partitioning help I'm new to spark any help to resolve this.
    – Pyd
    Nov 9, 2017 at 5:29
  • @Vignesh sure, I left and answer over there. Nov 10, 2017 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.