Spark Streaming StreamingContext 活动计数

Spark streaming StreamingContext active count

spark docs状态:

Only one StreamingContext can be active in a JVM at the same time.

想象这样一种情况,我打算 read/process 来自两个 Kafka 主题的数据,其中一个作业从一个 Kafka 主题获取数据,另一个从另一个 Kafka 主题获取数据。我可以在同一个 hadoop 集群上同时触发这两个作业吗?

它还指出,

Once a context has been stopped, it cannot be restarted.

所以如果由于某种原因我必须停止 spark 作业,有什么方法可以重新启动它?我是否通过 oozie 或其他方式触发它?

Can I trigger these two jobs in parallel on the same hadoop cluster simultaneously?

为了简单起见,让我们把术语弄清楚。 StreamingContext 在 Spark 作业中是唯一的。如果您想在 同一作业 中读取多个流,您可以通过将相同的 StreamingContext 两次传递给不同的 KafkaUtils.createStream 方法来实现。

如果您提交给 Spark 的 多个作业 ,那么每个作业都可以有自己的 StreamingContext。每个作业都有自己的 JVM 实例。

So if I have to stop the spark job due to some reason, what is the way to get it restarted?

实现您想要的目标的一种可能方法是使用 Spark 的集群模式 运行 您的流作业并传递 --supervise 标志。 Spark Master 将确保作业在失败时重新启动。

您可以在 Sparks "Submitting Applications" 文档中阅读更多相关信息。