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-1779] Throw an exception if memory fractions are not between 0 and 1 #714

Closed
wants to merge 13 commits into from

Conversation

scwf
Copy link
Contributor

@scwf scwf commented May 9, 2014

No description provided.

add a warning when memoryFraction is not between 0 and 1
@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@andrewor14
Copy link
Contributor

We should probably throw an exception, actually. It's a pathological state if the max memory is negative, or greater than what the JVM offers.

@andrewor14
Copy link
Contributor

Could you also do that in ExternalAppendOnlyMap? There are two similar configs there.

@scwf
Copy link
Contributor Author

scwf commented May 9, 2014

ok, updated.

@@ -1045,6 +1045,9 @@ private[spark] object BlockManager extends Logging {

def getMaxMemory(conf: SparkConf): Long = {
val memoryFraction = conf.getDouble("spark.storage.memoryFraction", 0.6)
if (memoryFraction > 1 && memoryFraction <= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the value of 0 is technically "between 0 and 1." This should be memoryFraction < 0. Someone might want to not use the RDD cache at all and use all memory for spilling, for instance. (though I don't think this is common)

Copy link
Contributor

Choose a reason for hiding this comment

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

(Same in ExternalAppendOnlyMap)

@andrewor14
Copy link
Contributor

Thanks, this looks good. (now we just need to test it)

@@ -1045,6 +1045,9 @@ private[spark] object BlockManager extends Logging {

def getMaxMemory(conf: SparkConf): Long = {
val memoryFraction = conf.getDouble("spark.storage.memoryFraction", 0.6)
if (memoryFraction > 1 && memoryFraction < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should throw an IllegalArgumentException.

Preconditions.checkArgument(0 < memoryFraction && 1 > memoryFraction, 
  "spark.storage.memoryFraction should be between 0 and 1.")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for that

@witgo
Copy link
Contributor

witgo commented May 10, 2014

SPARK-1779】 => [SPARK-1779]

@scwf scwf changed the title 【SPARK-1779】add warning when memoryFraction is not between 0 and 1 [SPARK-1779] add warning when memoryFraction is not between 0 and 1 May 10, 2014
@@ -76,6 +76,12 @@ class ExternalAppendOnlyMap[K, V, C](
private val maxMemoryThreshold = {
val memoryFraction = sparkConf.getDouble("spark.shuffle.memoryFraction", 0.3)
val safetyFraction = sparkConf.getDouble("spark.shuffle.safetyFraction", 0.8)
if (memoryFraction > 1 && memoryFraction < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should or(||) instead of and(&&).
[memoryFraction > 1 && memoryFraction < 0] => [memoryFraction > 1 || memoryFraction < 0]
The same to safetyFraction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, i made a mistake

Copy link
Contributor

Choose a reason for hiding this comment

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

oops, good call

@pwendell
Copy link
Contributor

Hey @witgo @andrewor14. I thought I commented earlier but it appears the comment didn't get posted.

I think it would be a good idea to validate this at the time of SparkConf construction rather than have validations scattered throughout the code.

https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/SparkConf.scala#L213

Also - it would be good to echo back the value that was set to the user. Sometimes users don't know where a configuration option is coming from:

if (memoryFraction > 1 || memoryFraction < 0) {
  val msg = s"spark.storage.memoryFraction should be between 0 and 1 (was '$memoryFraction')."
  throw new IllegalArgumentException(msg)
}

@scwf
Copy link
Contributor Author

scwf commented May 11, 2014

Hi @pwendell, thanks. I didn't notice validateSettings in SparkConf and it's good to validate this in it.

@erikerlandson
Copy link
Contributor

I coded up a proposal where SparkConf owns the checking inside of getInt(), getDouble() and friends, described here:

https://issues.apache.org/jira/browse/SPARK-1779?focusedCommentId=13996567&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-13996567

@@ -236,6 +236,27 @@ class SparkConf(loadDefaults: Boolean) extends Cloneable with Logging {
}
}

// Validate memoryFraction
val storageMemFraction = getDouble("spark.storage.memoryFraction", 0.6)
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be written a bit more concisely like:

val memoryKeys = Seq(
  "spark.storage.memoryFraction",
  "spark.shuffle.memoryFraction", 
  "spark.shuffle.safetyFraction")
for (key -> memoryKeys) {
  val value = getDouble(key, 0.5)
  if (value > 1 || value < 0) {
    throw new IllegalArgumentException("$key should be between 0 and (was '$value').")
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, updated!

@pwendell
Copy link
Contributor

Suggested a way to make this more concise, but looks good overall.

for (key -> memoryKeys) {
val value = getDouble(key, 0.5)
if (value > 1 || value < 0) {
throw new IllegalArgumentException("$key should be between 0 and (was '$value').")
Copy link
Contributor

Choose a reason for hiding this comment

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

missing indent

@andrewor14
Copy link
Contributor

Ah yes, this is much better. There is a missing indent, however. After you fix that I think this is good to go.

@pwendell
Copy link
Contributor

Jenkins, test this please.

@scwf
Copy link
Contributor Author

scwf commented Aug 4, 2014

hey @andrewor14 , i can not see FAILED unit tests info, so i do not know how to resolve it. can you help me

@andrewor14
Copy link
Contributor

test this please

@andrewor14
Copy link
Contributor

Pending tests this LGTM

@SparkQA
Copy link

SparkQA commented Aug 4, 2014

QA tests have started for PR 714. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17865/consoleFull

@SparkQA
Copy link

SparkQA commented Aug 4, 2014

QA results for PR 714:
- This patch FAILED unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17865/consoleFull

@@ -236,6 +236,20 @@ class SparkConf(loadDefaults: Boolean) extends Cloneable with Logging {
}
}

// Validate memoryFraction
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this is no longer only memoryFraction. Maybe use "Validate memory fractions" instead

@andrewor14
Copy link
Contributor

Also, could you update the description to "Throw an exception if memory fractions are not between 0 and 1"

@scwf
Copy link
Contributor Author

scwf commented Aug 5, 2014

@andrewor14 if so, we do not know which one is outside (0,1)

@andrewor14
Copy link
Contributor

What do you mean? I was referring to the title of the PR, because it's now out of date based on your recent changes.

@andrewor14
Copy link
Contributor

test this please

@SparkQA
Copy link

SparkQA commented Aug 5, 2014

QA tests have started for PR 714. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17909/consoleFull

@pwendell
Copy link
Contributor

pwendell commented Aug 5, 2014

LGTM pending tests.

@SparkQA
Copy link

SparkQA commented Aug 5, 2014

QA results for PR 714:
- This patch FAILED unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17909/consoleFull

@scwf scwf changed the title [SPARK-1779] add warning when memoryFraction is not between 0 and 1 [SPARK-1779] Throw an exception if memory fractions are not between 0 and 1 Aug 5, 2014
@scwf
Copy link
Contributor Author

scwf commented Aug 5, 2014

hi @andrewor14,unit tests error in sparkstreaming,we may retest this

[info] - flume polling test multiple hosts *** FAILED ***
[info] org.jboss.netty.channel.ChannelException: Failed to bind to: localhost/127.0.0.1:56218
[info] at org.jboss.netty.bootstrap.ServerBootstrap.bind(ServerBootstrap.java:272)

@andrewor14
Copy link
Contributor

test this please

@pwendell
Copy link
Contributor

pwendell commented Aug 5, 2014

Jenkins, test this please.

@SparkQA
Copy link

SparkQA commented Aug 5, 2014

QA tests have started for PR 714. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17932/consoleFull

@SparkQA
Copy link

SparkQA commented Aug 5, 2014

QA results for PR 714:
- This patch PASSES unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17932/consoleFull

@pwendell
Copy link
Contributor

pwendell commented Aug 5, 2014

Thanks - I'm going to merge this.

@asfgit asfgit closed this in 9862c61 Aug 5, 2014
asfgit pushed a commit that referenced this pull request Aug 5, 2014
… and 1

Author: wangfei <scnbwf@yeah.net>
Author: wangfei <wangfei1@huawei.com>

Closes #714 from scwf/memoryFraction and squashes the following commits:

6e385b9 [wangfei] Update SparkConf.scala
da6ee59 [wangfei] add configs
829a195 [wangfei] add indent
717c0ca [wangfei] updated to make more concise
fc45476 [wangfei] validate memoryfraction in sparkconf
2e79b3d [wangfei] && => ||
43621bd [wangfei] && => ||
cf38bcf [wangfei] throw IllegalArgumentException
14d18ac [wangfei] throw IllegalArgumentException
dff1f0f [wangfei] Update BlockManager.scala
764965f [wangfei] Update ExternalAppendOnlyMap.scala
a59d76b [wangfei] Throw exception when memoryFracton is out of range
7b899c2 [wangfei] 【SPARK-1779
@scwf scwf deleted the memoryFraction branch August 22, 2014 15:23
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
… and 1

Author: wangfei <scnbwf@yeah.net>
Author: wangfei <wangfei1@huawei.com>

Closes apache#714 from scwf/memoryFraction and squashes the following commits:

6e385b9 [wangfei] Update SparkConf.scala
da6ee59 [wangfei] add configs
829a195 [wangfei] add indent
717c0ca [wangfei] updated to make more concise
fc45476 [wangfei] validate memoryfraction in sparkconf
2e79b3d [wangfei] && => ||
43621bd [wangfei] && => ||
cf38bcf [wangfei] throw IllegalArgumentException
14d18ac [wangfei] throw IllegalArgumentException
dff1f0f [wangfei] Update BlockManager.scala
764965f [wangfei] Update ExternalAppendOnlyMap.scala
a59d76b [wangfei] Throw exception when memoryFracton is out of range
7b899c2 [wangfei] 【SPARK-1779】
Alexis-D pushed a commit to Alexis-D/spark that referenced this pull request Nov 16, 2020
* drop user info when ingesting conda list explicit uris

* add test

* special taste of scala

* more test

* fix test

* more docs

* 1 more docs
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.

8 participants