From b565079b4515f1c0abb1176805348e9c80b8bb64 Mon Sep 17 00:00:00 2001 From: Andrew Or Date: Tue, 5 Aug 2014 11:02:40 -0700 Subject: [PATCH] Add spark.ports.maxRetries --- core/src/main/scala/org/apache/spark/SparkEnv.scala | 1 - .../main/scala/org/apache/spark/util/Utils.scala | 13 ++++++++++++- docs/configuration.md | 7 +++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/org/apache/spark/SparkEnv.scala b/core/src/main/scala/org/apache/spark/SparkEnv.scala index 051814f074c80..100033f7f8962 100644 --- a/core/src/main/scala/org/apache/spark/SparkEnv.scala +++ b/core/src/main/scala/org/apache/spark/SparkEnv.scala @@ -22,7 +22,6 @@ import java.net.Socket import scala.collection.JavaConversions._ import scala.collection.mutable -import scala.concurrent.Await import scala.util.Properties import akka.actor._ diff --git a/core/src/main/scala/org/apache/spark/util/Utils.scala b/core/src/main/scala/org/apache/spark/util/Utils.scala index b4e8e157f0b3c..f4efca7ce825f 100644 --- a/core/src/main/scala/org/apache/spark/util/Utils.scala +++ b/core/src/main/scala/org/apache/spark/util/Utils.scala @@ -1331,6 +1331,17 @@ private[spark] object Utils extends Logging { .map { case (k, v) => s"-D$k=$v" } } + /** + * Default number of retries in binding to a port. + */ + val portMaxRetries: Int = { + // SparkEnv may be null during tests + Option(SparkEnv.get) + .flatMap(_.conf.getOption("spark.ports.maxRetries")) + .map(_.toInt) + .getOrElse(16) + } + /** * Attempt to start a service on the given port, or fail after a number of attempts. * Each subsequent attempt uses 1 + the port used in the previous attempt. @@ -1346,7 +1357,7 @@ private[spark] object Utils extends Logging { startPort: Int, startService: Int => (T, Int), serviceName: String = "", - maxRetries: Int = 3): (T, Int) = { + maxRetries: Int = portMaxRetries): (T, Int) = { val serviceString = if (serviceName.isEmpty) "" else s" '$serviceName'" for (offset <- 0 to maxRetries) { // Do not increment port if startPort is 0, which is treated as a special port diff --git a/docs/configuration.md b/docs/configuration.md index 870343f1c0bd2..1cf4903835838 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -567,6 +567,13 @@ Apart from these, the following properties are also available, and may be useful Port for the driver to listen on. + + spark.port.maxRetries + 16 + + Maximum number of retries when binding to a port before giving up. + + spark.akka.frameSize 10