Are shared variables supported in Spark Streaming?

廉价感情. 提交于 2019-12-12 02:55:37

问题


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


回答1:


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)

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.



来源:https://stackoverflow.com/questions/35097953/are-shared-variables-supported-in-spark-streaming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!