1. 安装
Linux环境
使用pyspark 和jupyter notebook作为交互工具。
具体看 Spark 初入门.
2. 第一个程序
计算圆周率:
import random
num_samples = 100000000
def inside(p):
x, y = random.random(), random.random()
return x*x + y*y < 1
count = sc.parallelize(range(0, num_samples)).filter(inside).count()
pi = 4 * count / num_samples
print(pi)
sc.stop()
运行结果:
3.1417056
参考: