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
Changes from 1 commit
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
12 changes: 11 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,19 @@ private[spark] object JettyUtils extends Logging {

gzipHandlers.foreach(collection.addHandler)
connectors.foreach(_.setHost(hostName))
// As each Acceptor will use one thread, the number of threads should at least be the number
// of acceptors plus 1. (See SPARK-13776)
var minThreads = 1
connectors.collect { case c: AbstractConnector => c }.foreach { c =>
Copy link
Member

Choose a reason for hiding this comment

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

Nit: the Scala math class is math vs Math but I wouldn't change it just for that. I think this looks like the right kind of approach.

// Limit the max acceptor number to 8 so that we don't waste a lot of threads
c.setAcceptors(Math.min(c.getAcceptors, 8))
minThreads += c.getAcceptors
}
server.setConnectors(connectors.toArray)

val pool = new QueuedThreadPool
pool.setMaxThreads(Math.max(pool.getMaxThreads, minThreads))
pool.setMinThreads(Math.min(pool.getMinThreads, pool.getMaxThreads))
pool.setDaemon(true)
server.setThreadPool(pool)
val errorHandler = new ErrorHandler()
Expand Down