Spark Streaming初試

Spark Streaming初試html


yum install nc.x86_64git


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

敲入下面程序:shell

import org.apache.spark.SparkConfapache

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

import org.apache.spark.storage.StorageLevelide


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

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

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

    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

相關文章
相關標籤/搜索