spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scwf <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-4449][Core] Specify port range in spark
Date Tue, 18 Nov 2014 12:13:53 GMT
Github user scwf commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3314#discussion_r20501274
  
    --- Diff: core/src/main/scala/org/apache/spark/util/Utils.scala ---
    @@ -1652,25 +1652,28 @@ private[spark] object Utils extends Logging {
        * 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 (unless the
port is 0).
        *
    -   * @param startPort The initial port to start the service on.
    +   * @param port The initial port to start the service on.
        * @param maxRetries Maximum number of retries to attempt.
        *                   A value of 3 means attempting ports n, n+1, n+2, and n+3, for
example.
        * @param startService Function to start service on a given port.
        *                     This is expected to throw java.net.BindException on port collision.
        */
       def startServiceOnPort[T](
    -      startPort: Int,
    +      port: Int,
           startService: Int => (T, Int),
    +      conf: SparkConf = new SparkConf(),
           serviceName: String = "",
           maxRetries: Int = portMaxRetries): (T, Int) = {
         val serviceString = if (serviceName.isEmpty) "" else s" '$serviceName'"
    +    val startPort = conf.getInt("spark.port.min", 0)
    +    val endPort = conf.getInt("spark.port.max", 65536)
         for (offset <- 0 to maxRetries) {
    -      // Do not increment port if startPort is 0, which is treated as a special port
    -      val tryPort = if (startPort == 0) {
    -        startPort
    +      // Do not increment port if port is 0, which is treated as a special port
    +      val tryPort = if (port == 0) {
    +        (startPort + Math.random() * (endPort - startPort)).toInt
    --- End diff --
    
    "This doesn't work if port isn't in the range, right? that seems like a problem" , Hi,
@srowen, you mean in `else` branch here?  if ```port``` is not in the range, then ```((port
+ offset - startPort) % (endPort - startPort)) + startPort``` will give us a port in this
range


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message