Spark Streaming是否支持共享变量? [英] Are shared variables supported in Spark Streaming?

查看:88
本文介绍了Spark Streaming是否支持共享变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spark为两种常用用法模式提供了两种有限类型的共享变量:广播变量和累加器,Spark Streaming是否支持它们?

Spark provide two limited types of shared variables for two common usage patterns: broadcast variables and accumulators, are they supported in Spark Streaming??

推荐答案

是的,您可以像通常通过 SparkContext 那样使用它们.唯一的区别是您需要从 SparkStreamingContext 中获取它:

Yes, you can use them as you'd normally do via SparkContext. The only difference is that you need to get it from SparkStreamingContext:

val sparkConf = new SparkConf().setAppName("MyApp")
val ssc = new StreamingContext(sparkConf, Seconds(1))
ssc.sparkContext.broadcast(myValue)

使用Spark Streaming时,您可能需要在某个时候更新该值,为此,您应该使用

With spark streaming you might want to update that value at some point, to do that you should use unpersist() (or the blocking version) and broadcast again.

这篇关于Spark Streaming是否支持共享变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆