Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-4818][Core] Add 'iterator' to reduce memory consumed by join #3671

Closed
wants to merge 2 commits into from
Closed

[SPARK-4818][Core] Add 'iterator' to reduce memory consumed by join #3671

wants to merge 2 commits into from

Conversation

zsxwing
Copy link
Member

@zsxwing zsxwing commented Dec 11, 2014

In Scala, map and flatMap of Iterable will copy the contents of Iterable to a new Seq. Such as,

  val iterable = Seq(1, 2, 3).map(v => {
    println(v)
    v
  })
  println("Iterable map done")

  val iterator = Seq(1, 2, 3).iterator.map(v => {
    println(v)
    v
  })
  println("Iterator map done")

outputed

1
2
3
Iterable map done
Iterator map done

So we should use 'iterator' to reduce memory consumed by join.

Found by Johannes Simon in http://mail-archives.apache.org/mod_mbox/spark-user/201412.mbox/%3C5BE70814-9D03-4F61-AE2C-0D63F2DE4446%40mail.de%3E

@SparkQA
Copy link

SparkQA commented Dec 11, 2014

Test build #24348 has started for PR 3671 at commit 95d59d6.

  • This patch merges cleanly.

@zsxwing zsxwing changed the title [SPARK-4824][Core] Add 'iterator' to reduce memory consumed by join [SPARK-4818][Core] Add 'iterator' to reduce memory consumed by join Dec 11, 2014
@SparkQA
Copy link

SparkQA commented Dec 11, 2014

Test build #24348 has finished for PR 3671 at commit 95d59d6.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/24348/
Test FAILed.

@zsxwing
Copy link
Member Author

zsxwing commented Dec 11, 2014

Jenkins, retest this please.

@SparkQA
Copy link

SparkQA commented Dec 11, 2014

Test build #24351 has started for PR 3671 at commit 95d59d6.

  • This patch merges cleanly.

@SparkQA
Copy link

SparkQA commented Dec 11, 2014

Test build #24351 has finished for PR 3671 at commit 95d59d6.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/24351/
Test PASSed.

@@ -493,9 +493,9 @@ class PairRDDFunctions[K, V](self: RDD[(K, V)])
def leftOuterJoin[W](other: RDD[(K, W)], partitioner: Partitioner): RDD[(K, (V, Option[W]))] = {
this.cogroup(other, partitioner).flatMapValues { pair =>
if (pair._2.isEmpty) {
pair._1.map(v => (v, None))
pair._1.iterator.map(v => (v, None): (V, Option[W]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, are these types required? or can it be limited to just changing None to None: Option[W]?
Not that it hurts to spell out the types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None to None: Option[W]

Have tried. But not work.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zsxwing First of all thanks for the patch! What kind of error are you getting without these explicit types? Compile time or runtime? I don't get any compile error/warning without these types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. My IDE had some problem. After I rebuilt the project, the errors gone.

@SparkQA
Copy link

SparkQA commented Dec 12, 2014

Test build #24407 has started for PR 3671 at commit 48ee7b9.

  • This patch merges cleanly.

@scwf
Copy link
Contributor

scwf commented Dec 12, 2014

Very interesting, any test for the effect on memory or performance?

@SparkQA
Copy link

SparkQA commented Dec 12, 2014

Test build #24407 has finished for PR 3671 at commit 48ee7b9.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/24407/
Test PASSed.

@zsxwing
Copy link
Member Author

zsxwing commented Dec 12, 2014

Very interesting, any test for the effect on memory or performance?

No. But I expect the memory will descrease from O(m * n) to O(m + n).

@zsxwing
Copy link
Member Author

zsxwing commented Dec 16, 2014

@pwendell Is it OK to put this patch into branch 1.2, or it's too late?

@JoshRosen
Copy link
Contributor

This looks good to me. This is a small fix but one which could significantly improve memory usage during joins, so I'm going to pull this into master (1.3.0), branch-1.2 (1.2.1), and branch-1.1 (1.1.2).

asfgit pushed a commit that referenced this pull request Dec 22, 2014
In Scala, `map` and `flatMap` of `Iterable` will copy the contents of `Iterable` to a new `Seq`. Such as,
```Scala
  val iterable = Seq(1, 2, 3).map(v => {
    println(v)
    v
  })
  println("Iterable map done")

  val iterator = Seq(1, 2, 3).iterator.map(v => {
    println(v)
    v
  })
  println("Iterator map done")
```
outputed
```
1
2
3
Iterable map done
Iterator map done
```
So we should use 'iterator' to reduce memory consumed by join.

Found by Johannes Simon in http://mail-archives.apache.org/mod_mbox/spark-user/201412.mbox/%3C5BE70814-9D03-4F61-AE2C-0D63F2DE4446%40mail.de%3E

Author: zsxwing <[email protected]>

Closes #3671 from zsxwing/SPARK-4824 and squashes the following commits:

48ee7b9 [zsxwing] Remove the explicit types
95d59d6 [zsxwing] Add 'iterator' to reduce memory consumed by join

(cherry picked from commit c233ab3)
Signed-off-by: Josh Rosen <[email protected]>
@asfgit asfgit closed this in c233ab3 Dec 22, 2014
asfgit pushed a commit that referenced this pull request Dec 22, 2014
In Scala, `map` and `flatMap` of `Iterable` will copy the contents of `Iterable` to a new `Seq`. Such as,
```Scala
  val iterable = Seq(1, 2, 3).map(v => {
    println(v)
    v
  })
  println("Iterable map done")

  val iterator = Seq(1, 2, 3).iterator.map(v => {
    println(v)
    v
  })
  println("Iterator map done")
```
outputed
```
1
2
3
Iterable map done
Iterator map done
```
So we should use 'iterator' to reduce memory consumed by join.

Found by Johannes Simon in http://mail-archives.apache.org/mod_mbox/spark-user/201412.mbox/%3C5BE70814-9D03-4F61-AE2C-0D63F2DE4446%40mail.de%3E

Author: zsxwing <[email protected]>

Closes #3671 from zsxwing/SPARK-4824 and squashes the following commits:

48ee7b9 [zsxwing] Remove the explicit types
95d59d6 [zsxwing] Add 'iterator' to reduce memory consumed by join

(cherry picked from commit c233ab3)
Signed-off-by: Josh Rosen <[email protected]>

Conflicts:
	core/src/main/scala/org/apache/spark/rdd/PairRDDFunctions.scala
@zsxwing zsxwing deleted the SPARK-4824 branch December 23, 2014 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants