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
21 changes: 21 additions & 0 deletions core/src/main/scala/org/apache/spark/SparkConf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,27 @@ 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

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!

val shuffleMemFraction = getDouble("spark.shuffle.memoryFraction", 0.3)
val shuffleSafFraction = getDouble("spark.shuffle.safetyFraction", 0.8)

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

// Check for legacy configs
sys.env.get("SPARK_JAVA_OPTS").foreach { value =>
val error =
Expand Down