Skip to content

Commit

Permalink
[SPARK-17707][WEBUI] Web UI prevents spark-submit application to be f…
Browse files Browse the repository at this point in the history
…inished

## What changes were proposed in this pull request?

This expands calls to Jetty's simple `ServerConnector` constructor to explicitly specify a `ScheduledExecutorScheduler` that makes daemon threads. It should otherwise result in exactly the same configuration, because the other args are copied from the constructor that is currently called.

(I'm not sure we should change the Hive Thriftserver impl, but I did anyway.)

This also adds `sc.stop()` to the quick start guide example.

## How was this patch tested?

Existing tests; _pending_ at least manual verification of the fix.

Author: Sean Owen <sowen@cloudera.com>

Closes #15381 from srowen/SPARK-17707.
  • Loading branch information
srowen authored and zsxwing committed Oct 7, 2016
1 parent dd16b52 commit cff5607
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse}
import scala.io.Source

import com.fasterxml.jackson.core.JsonProcessingException
import org.eclipse.jetty.server.{Server, ServerConnector}
import org.eclipse.jetty.server.{HttpConnectionFactory, Server, ServerConnector}
import org.eclipse.jetty.servlet.{ServletContextHandler, ServletHolder}
import org.eclipse.jetty.util.thread.QueuedThreadPool
import org.eclipse.jetty.util.thread.{QueuedThreadPool, ScheduledExecutorScheduler}
import org.json4s._
import org.json4s.jackson.JsonMethods._

Expand Down Expand Up @@ -83,7 +83,15 @@ private[spark] abstract class RestSubmissionServer(
threadPool.setDaemon(true)
val server = new Server(threadPool)

val connector = new ServerConnector(server)
val connector = new ServerConnector(
server,
null,
// Call this full constructor to set this, which forces daemon threads:
new ScheduledExecutorScheduler("RestSubmissionServer-JettyScheduler", true),
null,
-1,
-1,
new HttpConnectionFactory())
connector.setHost(host)
connector.setPort(startPort)
server.addConnector(connector)
Expand Down
14 changes: 11 additions & 3 deletions core/src/main/scala/org/apache/spark/ui/JettyUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import scala.xml.Node

import org.eclipse.jetty.client.api.Response
import org.eclipse.jetty.proxy.ProxyServlet
import org.eclipse.jetty.server.{Request, Server, ServerConnector}
import org.eclipse.jetty.server.{HttpConnectionFactory, Request, Server, ServerConnector}
import org.eclipse.jetty.server.handler._
import org.eclipse.jetty.servlet._
import org.eclipse.jetty.servlets.gzip.GzipHandler
import org.eclipse.jetty.util.component.LifeCycle
import org.eclipse.jetty.util.thread.QueuedThreadPool
import org.eclipse.jetty.util.thread.{QueuedThreadPool, ScheduledExecutorScheduler}
import org.json4s.JValue
import org.json4s.jackson.JsonMethods.{pretty, render}

Expand Down Expand Up @@ -294,7 +294,15 @@ private[spark] object JettyUtils extends Logging {
val server = new Server(pool)
val connectors = new ArrayBuffer[ServerConnector]
// Create a connector on port currentPort to listen for HTTP requests
val httpConnector = new ServerConnector(server)
val httpConnector = new ServerConnector(
server,
null,
// Call this full constructor to set this, which forces daemon threads:
new ScheduledExecutorScheduler(s"$serverName-JettyScheduler", true),
null,
-1,
-1,
new HttpConnectionFactory())
httpConnector.setPort(currentPort)
connectors += httpConnector

Expand Down
7 changes: 6 additions & 1 deletion docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ object SimpleApp {
val logData = sc.textFile(logFile, 2).cache()
val numAs = logData.filter(line => line.contains("a")).count()
val numBs = logData.filter(line => line.contains("b")).count()
println("Lines with a: %s, Lines with b: %s".format(numAs, numBs))
println(s"Lines with a: $numAs, Lines with b: $numBs")
sc.stop()
}
}
{% endhighlight %}
Expand Down Expand Up @@ -328,6 +329,8 @@ public class SimpleApp {
}).count();

System.out.println("Lines with a: " + numAs + ", lines with b: " + numBs);

sc.stop()
}
}
{% endhighlight %}
Expand Down Expand Up @@ -407,6 +410,8 @@ numAs = logData.filter(lambda s: 'a' in s).count()
numBs = logData.filter(lambda s: 'b' in s).count()

print("Lines with a: %i, lines with b: %i" % (numAs, numBs))

sc.stop()
{% endhighlight %}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.server.TServlet;
import org.eclipse.jetty.server.AbstractConnectionFactory;
import org.eclipse.jetty.server.ConnectionFactory;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.ExecutorThreadPool;
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;


public class ThriftHttpCLIService extends ThriftCLIService {
Expand Down Expand Up @@ -70,7 +74,8 @@ public void run() {
httpServer = new org.eclipse.jetty.server.Server(threadPool);

// Connector configs
ServerConnector connector = new ServerConnector(httpServer);

ConnectionFactory[] connectionFactories;
boolean useSsl = hiveConf.getBoolVar(ConfVars.HIVE_SERVER2_USE_SSL);
String schemeName = useSsl ? "https" : "http";
// Change connector if SSL is used
Expand All @@ -90,8 +95,21 @@ public void run() {
Arrays.toString(sslContextFactory.getExcludeProtocols()));
sslContextFactory.setKeyStorePath(keyStorePath);
sslContextFactory.setKeyStorePassword(keyStorePassword);
connector = new ServerConnector(httpServer, sslContextFactory);
connectionFactories = AbstractConnectionFactory.getFactories(
sslContextFactory, new HttpConnectionFactory());
} else {
connectionFactories = new ConnectionFactory[] { new HttpConnectionFactory() };
}
ServerConnector connector = new ServerConnector(
httpServer,
null,
// Call this full constructor to set this, which forces daemon threads:
new ScheduledExecutorScheduler("HiveServer2-HttpHandler-JettyScheduler", true),
null,
-1,
-1,
connectionFactories);

connector.setPort(portNum);
// Linux:yes, Windows:no
connector.setReuseAddress(!Shell.WINDOWS);
Expand Down

0 comments on commit cff5607

Please sign in to comment.