美文网首页
使用spark来模拟硬币正反面概率

使用spark来模拟硬币正反面概率

作者: 奈文摩尔定律 | 来源:发表于2016-11-02 15:24 被阅读35次
    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)```
    感觉使用函数式语言开发是未来

    相关文章

      网友评论

          本文标题:使用spark来模拟硬币正反面概率

          本文链接:https://www.haomeiwen.com/subject/rzivuttx.html