Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit c6ba647

Browse files
IngoSchustercloud-fan
authored andcommitted
[SPARK-21176][WEB UI] Limit number of selector threads for admin ui proxy servlets to 8
## What changes were proposed in this pull request? Please see also https://issues.apache.org/jira/browse/SPARK-21176 This change limits the number of selector threads that jetty creates to maximum 8 per proxy servlet (Jetty default is number of processors / 2). The newHttpClient for Jettys ProxyServlet class is overwritten to avoid the Jetty defaults (which are designed for high-performance http servers). Once jetty/jetty.project#1643 is available, the code could be cleaned up to avoid the method override. I really need this on v2.1.1 - what is the best way for a backport automatic merge works fine)? Shall I create another PR? ## How was this patch tested? (Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests) The patch was tested manually on a Spark cluster with a head node that has 88 processors using JMX to verify that the number of selector threads is now limited to 8 per proxy. gurvindersingh zsxwing can you please review the change? Author: IngoSchuster <[email protected]> Author: Ingo Schuster <[email protected]> Closes apache#18437 from IngoSchuster/master. (cherry picked from commit 88a536b) Signed-off-by: Wenchen Fan <[email protected]>
1 parent 8de67e3 commit c6ba647

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import scala.language.implicitConversions
2626
import scala.xml.Node
2727

2828
import org.eclipse.jetty.client.api.Response
29+
import org.eclipse.jetty.client.HttpClient
30+
import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP
2931
import org.eclipse.jetty.proxy.ProxyServlet
3032
import org.eclipse.jetty.server._
3133
import org.eclipse.jetty.server.handler._
@@ -208,6 +210,16 @@ private[spark] object JettyUtils extends Logging {
208210
rewrittenURI.toString()
209211
}
210212

213+
override def newHttpClient(): HttpClient = {
214+
// SPARK-21176: Use the Jetty logic to calculate the number of selector threads (#CPUs/2),
215+
// but limit it to 8 max.
216+
// Otherwise, it might happen that we exhaust the threadpool since in reverse proxy mode
217+
// a proxy is instantiated for each executor. If the head node has many processors, this
218+
// can quickly add up to an unreasonably high number of threads.
219+
val numSelectors = math.max(1, math.min(8, Runtime.getRuntime().availableProcessors() / 2))
220+
new HttpClient(new HttpClientTransportOverHTTP(numSelectors), null)
221+
}
222+
211223
override def filterServerResponseHeader(
212224
clientRequest: HttpServletRequest,
213225
serverResponse: Response,

0 commit comments

Comments
 (0)