object First {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("Simple Application").setMaster("local")
val sc = new SparkContext(conf)
val times = 10000
sc.parallelize(1 to times, 4).map{index=>(Random.nextBoolean(),1)}.reduceByKey(_+_).foreach(println) }}
输出如下
(false,5054)
16/11/02 14:41:40 INFO Executor: Finished task 1.0 in stage 1.0 (TID 4). 1165 bytes result sent to driver
16/11/02 14:41:40 INFO TaskSetManager: Starting task 3.0 in stage 1.0 (TID 5, localhost, partition 3,NODE_LOCAL, 1894 bytes)
16/11/02 14:41:40 INFO Executor: Running task 3.0 in stage 1.0 (TID 5)
16/11/02 14:41:40 INFO TaskSetManager: Finished task 1.0 in stage 1.0 (TID 4) in 53 ms on localhost (1/4)
(true,4946)```
感觉使用函数式语言开发是未来