Spark流式上下文在停止时挂起

时间:2015-10-19 14:50:08

标签: scala apache-spark spark-streaming

我正在尝试编写一个火花流程序,我希望优先关闭我的应用程序,以防我的应用程序收到关闭钩子。我编写了以下代码片段来完成此任务。

sys.ShutdownHookThread {
  println("Gracefully stopping MyStreamJob")
  ssc.stop(stopSparkContext = true, stopGracefully = true)
  println("Streaming stopped")
  sys.exit(0)
}

在调用此代码时,仅调用第一个println。这是第二个println Streaming Stopped从未见过。我在控制台上收到的最后一条消息是:

39790 [shutdownHook1] INFO org.spark-project.jetty.server.handler.ContextHandler  - stopped o.s.j.s.ServletContextHandler{/streaming,null}
39791 [shutdownHook1] INFO org.spark-project.jetty.server.handler.ContextHandler  - stopped o.s.j.s.ServletContextHandler{/streaming/batch,null}
39792 [shutdownHook1] INFO org.spark-project.jetty.server.handler.ContextHandler  - stopped o.s.j.s.ServletContextHandler{/static/streaming,null}
15/10/19 19:59:43 INFO handler.ContextHandler: stopped o.s.j.s.ServletContextHandler{/static/streaming,null}

我正在使用spark 1.4.1。我必须使用kill -9手动杀死该作业才能结束火花。这是预期的行为,还是我做错了什么?

1 个答案:

答案 0 :(得分:3)

Spark添加了自己的调用来停止StreamingContext。 See this email thread.

您的代码在1.4之前已经有效,现在它将在您遇到时挂起。您可以简单地删除挂钩,并且应该自动进行正常关闭。

现在可以使用以下配置参数来指定关闭是否应该是正常的:

spark.streaming.stopGracefullyOnShutdown

正常关闭后SparkContext将停止。见:

"Do not stop SparkContext, let its own shutdown hook stop it"

相关问题