From b01c9ed94523d3cf74f422e726749627bc4b12b6 Mon Sep 17 00:00:00 2001 From: zsxwing Date: Sun, 28 Jun 2015 22:19:24 +0800 Subject: [PATCH] Enable GZip by default for Web UI --- core/pom.xml | 5 +++++ .../org/apache/spark/ui/JettyUtils.scala | 19 +++++++++++++++++++ pom.xml | 7 +++++++ 3 files changed, 31 insertions(+) diff --git a/core/pom.xml b/core/pom.xml index 565437c4861a..543717d89e96 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -146,6 +146,11 @@ jetty-servlet compile + + org.eclipse.jetty + jetty-servlets + compile + diff --git a/core/src/main/scala/org/apache/spark/ui/JettyUtils.scala b/core/src/main/scala/org/apache/spark/ui/JettyUtils.scala index 06e616220c70..598f6efd5a4c 100644 --- a/core/src/main/scala/org/apache/spark/ui/JettyUtils.scala +++ b/core/src/main/scala/org/apache/spark/ui/JettyUtils.scala @@ -27,6 +27,7 @@ import scala.xml.Node import org.eclipse.jetty.server.Server import org.eclipse.jetty.server.handler._ import org.eclipse.jetty.servlet._ +import org.eclipse.jetty.servlets.GzipFilter import org.eclipse.jetty.util.thread.QueuedThreadPool import org.json4s.JValue import org.json4s.jackson.JsonMethods.{pretty, render} @@ -166,8 +167,26 @@ private[spark] object JettyUtils extends Logging { contextHandler } + private def addDefaultFilters(handlers: Seq[ServletContextHandler], conf: SparkConf): Unit = { + val compression = conf.getBoolean("spark.ui.compression", true) + if (compression) { + // Enable gzip for Web UI + logInfo("Adding filter: GzipFilter") + val holder = new FilterHolder() + holder.setClassName(classOf[GzipFilter].getName()) + holder.setInitParameter("methods", "GET,POST") + holder.setInitParameter("mimeTypes", "text/html,text/xml,text/plain,text/css," + + "text/javascript,text/json,application/x-javascript,application/javascript," + + "application/json,application/xml,application/xml+xhtml,image/svg+xml") + val enumDispatcher = java.util.EnumSet.of(DispatcherType.ASYNC, DispatcherType.ERROR, + DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.REQUEST) + handlers.foreach { case (handler) => handler.addFilter(holder, "/*", enumDispatcher) } + } + } + /** Add filters, if any, to the given list of ServletContextHandlers */ def addFilters(handlers: Seq[ServletContextHandler], conf: SparkConf) { + addDefaultFilters(handlers, conf) val filters: Array[String] = conf.get("spark.ui.filters", "").split(',').map(_.trim()) filters.foreach { case filter : String => diff --git a/pom.xml b/pom.xml index 00f50166b39b..ad619d138fdc 100644 --- a/pom.xml +++ b/pom.xml @@ -382,6 +382,12 @@ ${jetty.version} provided + + org.eclipse.jetty + jetty-servlets + ${jetty.version} + provided + org.eclipse.jetty jetty-util @@ -1442,6 +1448,7 @@ org.eclipse.jetty:jetty-http org.eclipse.jetty:jetty-continuation org.eclipse.jetty:jetty-servlet + org.eclipse.jetty:jetty-servlets org.eclipse.jetty:jetty-plus org.eclipse.jetty:jetty-security org.eclipse.jetty:jetty-util