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-13776][WebUI]Limit the max number of acceptors and selectors for Jetty #11615

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion core/src/main/scala/org/apache/spark/ui/JettyUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import scala.collection.mutable.ArrayBuffer
import scala.language.implicitConversions
import scala.xml.Node

import org.eclipse.jetty.server.{Connector, Request, Server}
import org.eclipse.jetty.server.{AbstractConnector, Connector, Request, Server}
import org.eclipse.jetty.server.handler._
import org.eclipse.jetty.server.nio.SelectChannelConnector
import org.eclipse.jetty.server.ssl.SslSelectChannelConnector
Expand Down Expand Up @@ -270,9 +270,25 @@ private[spark] object JettyUtils extends Logging {

gzipHandlers.foreach(collection.addHandler)
connectors.foreach(_.setHost(hostName))
// As each acceptor and each selector will use one thread, the number of threads should at
// least be the number of acceptors and selectors plus 1. (See SPARK-13776)
var minThreads = 1
connectors.foreach { c =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use collect or "cast" using pattern matching on type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to crash the app if we add a non-SelectChannelConnector in future. It's better than being silent.

// Currently we only use "SelectChannelConnector"
val connector = c.asInstanceOf[SelectChannelConnector]
// Limit the max acceptor number to 8 so that we don't waste a lot of threads
connector.setAcceptors(math.min(connector.getAcceptors, 8))
// The number of selectors always equals to the number of acceptors
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minThreads += connector.getAcceptors * 2
}
server.setConnectors(connectors.toArray)

val pool = new QueuedThreadPool
if (serverName.nonEmpty) {
pool.setName(serverName)
}
pool.setMaxThreads(math.max(pool.getMaxThreads, minThreads))
pool.setMinThreads(math.min(pool.getMinThreads, pool.getMaxThreads))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When could getMinThreads be greater than getMaxThreads? Why don't you use minThreads here, too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default pool.getMinThreads may be greater than minThreads here and that's fine. So I use pool.getMaxThreads here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, could getMinThreads be greater than getMaxThreads ever? Why are you doing the line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If minThreads=4, getMaxThreads=100, getMinThreads=8, I want to call setMaxThreads(100), setMinThreads(8).
If minThreads=200, getMaxThreads=100, getMinThreads=8, I want to call setMaxThreads(200), setMinThreads(8).
If minThreads=10, getMaxThreads=100, getMinThreads=8, I want to call setMaxThreads(200), setMinThreads(8).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind. I see. I don't need to setMinThreads.

pool.setDaemon(true)
server.setThreadPool(pool)
val errorHandler = new ErrorHandler()
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/org/apache/spark/ui/WebUI.scala
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private[spark] abstract class WebUI(
def bind() {
assert(!serverInfo.isDefined, "Attempted to bind %s more than once!".format(className))
try {
var host = Option(conf.getenv("SPARK_LOCAL_IP")).getOrElse("0.0.0.0")
val host = Option(conf.getenv("SPARK_LOCAL_IP")).getOrElse("0.0.0.0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK but was this change intentional? rest seems OK

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, never mind. I will remove it.

serverInfo = Some(startJettyServer(host, port, sslOptions, handlers, conf, name))
logInfo("Bound %s to %s, and started at http://%s:%d".format(className, host,
publicHostName, boundPort))
Expand Down