Skip to content

Commit b565079

Browse files
committed
Add spark.ports.maxRetries
1 parent 2551eb2 commit b565079

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

core/src/main/scala/org/apache/spark/SparkEnv.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import java.net.Socket
2222

2323
import scala.collection.JavaConversions._
2424
import scala.collection.mutable
25-
import scala.concurrent.Await
2625
import scala.util.Properties
2726

2827
import akka.actor._

core/src/main/scala/org/apache/spark/util/Utils.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,17 @@ private[spark] object Utils extends Logging {
13311331
.map { case (k, v) => s"-D$k=$v" }
13321332
}
13331333

1334+
/**
1335+
* Default number of retries in binding to a port.
1336+
*/
1337+
val portMaxRetries: Int = {
1338+
// SparkEnv may be null during tests
1339+
Option(SparkEnv.get)
1340+
.flatMap(_.conf.getOption("spark.ports.maxRetries"))
1341+
.map(_.toInt)
1342+
.getOrElse(16)
1343+
}
1344+
13341345
/**
13351346
* Attempt to start a service on the given port, or fail after a number of attempts.
13361347
* Each subsequent attempt uses 1 + the port used in the previous attempt.
@@ -1346,7 +1357,7 @@ private[spark] object Utils extends Logging {
13461357
startPort: Int,
13471358
startService: Int => (T, Int),
13481359
serviceName: String = "",
1349-
maxRetries: Int = 3): (T, Int) = {
1360+
maxRetries: Int = portMaxRetries): (T, Int) = {
13501361
val serviceString = if (serviceName.isEmpty) "" else s" '$serviceName'"
13511362
for (offset <- 0 to maxRetries) {
13521363
// Do not increment port if startPort is 0, which is treated as a special port

docs/configuration.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,13 @@ Apart from these, the following properties are also available, and may be useful
567567
Port for the driver to listen on.
568568
</td>
569569
</tr>
570+
<tr>
571+
<td><code>spark.port.maxRetries</code></td>
572+
<td>16</td>
573+
<td>
574+
Maximum number of retries when binding to a port before giving up.
575+
</td>
576+
</tr>
570577
<tr>
571578
<td><code>spark.akka.frameSize</code></td>
572579
<td>10</td>

0 commit comments

Comments
 (0)