Skip to content

Commit f7f5bf0

Browse files
committed
Make history server's web UI port a Spark configuration
1 parent 2dfb494 commit f7f5bf0

File tree

6 files changed

+27
-35
lines changed

6 files changed

+27
-35
lines changed

core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ import org.apache.spark.util.Utils
4343
* EventLoggingListener.
4444
*
4545
* @param baseLogDir The base directory in which event logs are found
46-
* @param requestedPort The requested port to which this server is to be bound
4746
*/
4847
class HistoryServer(
4948
val baseLogDir: String,
50-
requestedPort: Int,
5149
conf: SparkConf)
5250
extends SparkUIContainer("History Server") with Logging {
5351

@@ -56,7 +54,7 @@ class HistoryServer(
5654
private val fileSystem = Utils.getHadoopFileSystem(baseLogDir)
5755
private val localHost = Utils.localHostName()
5856
private val publicHost = Option(System.getenv("SPARK_PUBLIC_DNS")).getOrElse(localHost)
59-
private val port = requestedPort
57+
private val port = WEB_UI_PORT
6058
private val securityManager = new SecurityManager(conf)
6159
private val indexPage = new IndexPage(this)
6260

@@ -243,7 +241,7 @@ class HistoryServer(
243241
* start-history-server.sh and stop-history-server.sh. The path to a base log directory
244242
* is must be specified, while the requested UI port is optional. For example:
245243
*
246-
* ./sbin/spark-history-server.sh /tmp/spark-events 18080
244+
* ./sbin/spark-history-server.sh /tmp/spark-events
247245
* ./sbin/spark-history-server.sh hdfs://1.2.3.4:9000/spark-events
248246
*
249247
* This launches the HistoryServer as a Spark daemon.
@@ -257,11 +255,14 @@ object HistoryServer {
257255
// How many applications to retain
258256
val RETAINED_APPLICATIONS = conf.getInt("spark.history.retainedApplications", 250)
259257

258+
// The port to which the web UI is bound
259+
val WEB_UI_PORT = conf.getInt("spark.history.ui.port", 18080)
260+
260261
val STATIC_RESOURCE_DIR = SparkUI.STATIC_RESOURCE_DIR
261262

262263
def main(argStrings: Array[String]) {
263264
val args = new HistoryServerArguments(argStrings)
264-
val server = new HistoryServer(args.logDir, args.port, conf)
265+
val server = new HistoryServer(args.logDir, conf)
265266
server.bind()
266267
server.start()
267268

core/src/main/scala/org/apache/spark/deploy/history/HistoryServerArguments.scala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,26 @@ import java.net.URI
2121

2222
import org.apache.hadoop.fs.Path
2323

24-
import org.apache.spark.util.{IntParam, Utils}
24+
import org.apache.spark.util.Utils
2525

2626
/**
2727
* Command-line parser for the master.
2828
*/
2929
private[spark] class HistoryServerArguments(args: Array[String]) {
30-
var port = 18080
3130
var logDir = ""
3231

3332
parse(args.toList)
3433

3534
private def parse(args: List[String]): Unit = {
3635
args match {
37-
case ("--port" | "-p") :: IntParam(value) :: tail =>
38-
port = value
39-
parse(tail)
40-
4136
case ("--dir" | "-d") :: value :: tail =>
4237
logDir = value
4338
parse(tail)
4439

4540
case ("--help" | "-h") :: tail =>
4641
printUsageAndExit(0)
4742

48-
case Nil => {}
43+
case Nil =>
4944

5045
case _ =>
5146
printUsageAndExit(1)
@@ -71,7 +66,6 @@ private[spark] class HistoryServerArguments(args: Array[String]) {
7166
"Usage: HistoryServer [options]\n" +
7267
"\n" +
7368
"Options:\n" +
74-
" -p PORT, --port PORT Port for web server (default: 18080)\n" +
7569
" -d DIR, --dir DIR Location of event log files")
7670
System.exit(exitCode)
7771
}

core/src/main/scala/org/apache/spark/deploy/worker/ui/WorkerWebUI.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class WorkerWebUI(val worker: Worker, val workDir: File, requestedPort: Option[I
3939

4040
private val host = Utils.localHostName()
4141
private val port = requestedPort.getOrElse(
42-
worker.conf.get("worker.ui.port", WorkerWebUI.DEFAULT_PORT).toInt)
42+
worker.conf.getInt("worker.ui.port", WorkerWebUI.DEFAULT_PORT))
4343
private val indexPage = new IndexPage(this)
4444

4545
private val handlers: Seq[ServletContextHandler] = {
@@ -188,6 +188,6 @@ class WorkerWebUI(val worker: Worker, val workDir: File, requestedPort: Option[I
188188
}
189189

190190
private[spark] object WorkerWebUI {
191+
val DEFAULT_PORT=8081
191192
val STATIC_RESOURCE_BASE = SparkUI.STATIC_RESOURCE_DIR
192-
val DEFAULT_PORT="8081"
193193
}

core/src/main/scala/org/apache/spark/ui/SparkUI.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private[spark] class SparkUI(
4949

5050
private val localHost = Utils.localHostName()
5151
private val publicHost = Option(System.getenv("SPARK_PUBLIC_DNS")).getOrElse(localHost)
52-
private val port = conf.get("spark.ui.port", SparkUI.DEFAULT_PORT).toInt
52+
private val port = conf.getInt("spark.ui.port", SparkUI.DEFAULT_PORT)
5353

5454
private val storage = new BlockManagerUI(this)
5555
private val jobs = new JobProgressUI(this)
@@ -118,6 +118,6 @@ private[spark] class SparkUI(
118118
}
119119

120120
private[spark] object SparkUI {
121-
val DEFAULT_PORT = "4040"
121+
val DEFAULT_PORT = 4040
122122
val STATIC_RESOURCE_DIR = "org/apache/spark/ui/static"
123123
}

docs/monitoring.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ You can start a the history server by executing:
3939

4040
The base logging directory must be supplied, and should contain sub-directories that each
4141
represents an application's event logs. This creates a web interface at
42-
`http://<server-url>:18080` by default, but the port can be changed by supplying an extra
43-
parameter to the start script. The history server depends on the following variables:
42+
`http://<server-url>:18080` by default. The history server depends on the following variables:
4443

4544
<table class="table">
4645
<tr><th style="width:21%">Environment Variable</th><th>Meaning</th></tr>
@@ -62,16 +61,23 @@ Further, the history server can be configured as follows:
6261
<td>spark.history.updateInterval</td>
6362
<td>10</td>
6463
<td>
65-
The period at which information displayed by this history server is updated. Each update
66-
checks for any changes made to the event logs in persisted storage.
64+
The period, in seconds, at which information displayed by this history server is updated.
65+
Each update checks for any changes made to the event logs in persisted storage.
6766
</td>
6867
</tr>
6968
<tr>
7069
<td>spark.history.retainedApplications</td>
7170
<td>250</td>
7271
<td>
73-
The number of application UIs to retain. If this cap is exceeded, then the least recently
74-
updated applications will be removed.
72+
The number of application UIs to retain. If this cap is exceeded, then the oldest
73+
applications will be removed.
74+
</td>
75+
</tr>
76+
<tr>
77+
<td>spark.history.ui.port</td>
78+
<td>18080</td>
79+
<td>
80+
The port to which the web interface of the history server binds.
7581
</td>
7682
</tr>
7783
</table>

sbin/start-history-server.sh

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,11 @@ sbin=`dirname "$0"`
2727
sbin=`cd "$sbin"; pwd`
2828

2929
if [ $# -lt 1 ]; then
30-
echo "Usage: ./start-history-server.sh <base-log-dir> [<web-ui-port>]"
31-
echo "Example: ./start-history-server.sh /tmp/spark-events 18080"
30+
echo "Usage: ./start-history-server.sh <base-log-dir>"
31+
echo "Example: ./start-history-server.sh /tmp/spark-events"
3232
exit
3333
fi
3434

35-
# Set up base event log directory
3635
LOG_DIR=$1
37-
shift
3836

39-
# Set up web UI port
40-
if [ ! -z $1 ]; then
41-
PORT=$1
42-
else
43-
PORT=18080
44-
fi
45-
46-
"$sbin"/spark-daemon.sh start org.apache.spark.deploy.history.HistoryServer 1 --dir "$LOG_DIR" --port "$PORT"
37+
"$sbin"/spark-daemon.sh start org.apache.spark.deploy.history.HistoryServer 1 --dir "$LOG_DIR"

0 commit comments

Comments
 (0)