作者left (881 forever)
看板Python
标题pyspark的一个问题
时间Thu Nov 17 11:57:50 2016
不晓得版上有没有人在玩pyspark的大大
目前在看线上文件遇到一个问题,网址如下:
http://spark.apache.org/docs/latest/programming-guide.html#understanding-closures-a-nameclosureslinka
里面有一个程式码范例以及说明如下
Consider the naive RDD element sum below, which may behave differently
depending on whether execution is happening within the same JVM.
A common example of this is when running Spark in local mode
(--master = local[n]) versus deploying a Spark application
to a cluster (e.g. via spark-submit to YARN):
他的意思是,如果在local mode下跑就可以改变counter的值,然後在cluster上跑
就无法改变counter的值 ?
我在local mode下跑下面这段程式码counter的值完全都不会改变啊
是我会错意?还是需要在设定什麽啊?
counter = 0
rdd = sc.parallelize(data)
# Wrong: Don't do this!!
def increment_counter(x):
global counter
counter += x
rdd.foreach(increment_counter)
print("Counter value: ", counter)
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 61.220.35.20
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1479355074.A.489.html
1F:推 Agamidae: 我跑scala版的local, counter会累加 11/19 18:06