码迷,mamicode.com
首页 > 其他好文 > 详细

Spark Streaming初试

时间:2015-09-01 20:07:57      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:

Spark Streaming初试


yum install nc.x86_64


./bin/spark-shell --total-executor-cores 34 

敲入下面程序:

import org.apache.spark.SparkConf

import org.apache.spark.streaming.{Seconds, StreamingContext}

import org.apache.spark.storage.StorageLevel


    val ssc = new StreamingContext(sc, Seconds(1))

    val lines = ssc.socketTextStream("hostname", 9999, StorageLevel.MEMORY_AND_DISK_SER)

    val words = lines.flatMap(_.split(" "))

    val wordCounts = words.map(x => (x, 1)).reduceByKey(_ + _)

    wordCounts.print()

    ssc.start()

    ssc.awaitTermination()

    

    

在hostname机器,安装nc后,nc -lk 9999

不断输入字符,例如hello world,会在启动spark-shell的机器不断统计每次输入数据的字符频率统计。  

   

   参考 

    http://spark.apache.org/docs/latest/streaming-programming-guide.html

    https://github.com/apache/spark/blob/master/examples/src/main/scala/org/apache/spark/examples/streaming/NetworkWordCount.scala


Spark Streaming初试

标签:

原文地址:http://my.oschina.net/forrest420/blog/500301

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!