Spark DStreams

Spark Streaming的 离散流(DStreams)上的转换、连接操作 离散流(DStreams)的简介: 离散流或DStream是Spark Streaming提供的基本抽象。它表示连续的数据流,可以是从源接收的输入数据流,并把数据分组为小的批次。也可以是通过转换输入流生成的已处理数据流,每个输入批次都形成一个RDD序列,每个RDD代表数据流中的一个时间片内的数据。如下图所示,DStream中的每个RDD都包含一定时间间隔内的数据。 一、连接操作 流流连接 流可以... 阅读详情

Spark DStreams

DStreams是什么

DStreams是构建在Spark RDD之上的一款流处理工具,意即Spark DStreams并不是一个严格意义上的流处理,底层通过将RDD 在时间轴上分解成多个小的 RDD-micro batch

流 | 批处理

计算类型数据量级计算延迟输入数据输出计算形式
批处理MB=>GB=>TB几十分钟|几个小时固定输入(全量)固定输出最终终止(时间限制)
流处理byte级别|记录级别亚秒级延迟持续输入(增量)持续输出24*7小时

流处理框架:Kafka Streaming(工具级别)、Storm(实时流处理)一代、Spark DStream(微批)-实时性差-二代、Flink (实时流处理)-三代

由于DStreams构建在RDD之上,对习惯了批处理的工程师来说,在使用上比较友好。很多大数据工程师都有着MapReduce的使用经验,如果使用批去模拟流,比较容易接受,同时DStreams是构建在RDD(批处理)之上,因此从使用角度上讲,DStreams操作流就好比是在操作批处理,因此在使用难度上比 Storm相对来说要简单。由于Spark框架实现的核心偏向批处理,流处理只是从批处理中演变而来,因此DStreams在做流处理的时候延迟较高

DStreams 原理

Discretized(离散) Streams (流)(DStreams)在内部的工作原理:Spark Streaming接收实时输入数据流并将数据分成批处理,然后由Spark引擎处理以批量生成最终结果流
在这里插入图片描述

快速入门

  • pom.xml文件
<dependency>
  <groupId>org.apache.spark</groupId>
  <artifactId>spark-streaming_${scala.version}</artifactId>
  <version>${spark.version}</version>
</dependency>
  • Driver程序
//1.创建StreamingContext
val sparkConf = new SparkConf().setMaster("local[5]").setAppName("HelloWorld")
var ssc=new StreamingContext(sparkConf,Seconds(1)) //1s一次微批处理
//2.构建DStream对象 -细化
val lineStream = ssc.socketTextStream("centos",9999)
//3.对数据流进行计算 mirco-rdd 转换
lineStream.flatMap(_.split("\\s+")) //细化
.map((_,1))
.reduceByKey(_+_)
.print() //将计算结果打印
//4.启动计算
ssc.start()
ssc.awaitTermination()
  • 启动网络服务
[root@centos ~]# yum install -y nc # 安装 netcat
[root@centos ~]# nc -lk 9999
this is a demo
this is a
this is

程序结构

  1. 创建StreamingContext
  2. 指定流处理的数据源 # socket-测试、文件系统-了解、Kafka-必须掌握、自定义Reciver-了解
  3. 对DStreams进行转换 # 基本上和RDD转换保持一致
  4. 启动任务ssc.start()
  5. 等待任务关闭ssc.awaitTermination() // 通过UI页面 kill

Input DStreams 和 Receivers

Spark的每一个InputDstream对应一个Receiver实现(除文件系统输入流以外),每一个Receiver对象负责接收外围系统的数据,并且将数据存储到Spark的内存中(设置存储级别-内存、磁盘),这也侧面反映了为什么说Spark DStreams吞吐量比较大

Spark提供了两种类型的输入源:

  • Basic sources:File System以及Socket 连接,无需用户导入第三方包
  • Advanced sources:Spark本身不提供,需要导入第三方依赖,比如:Kafka

一般来说一个Receiver需要消耗一个Core计算资源,在Spark运行流计算的时候,一定要提前预留多一些Core n,n > Receiver个数

File Streams

以流的形式读取静态的资源文件,系统会尝试检测文件系统,一旦文件系统有新的数据产生,系统会加载新文件(仅仅加载一次)

注意:一定要确保文件系统时间和计算节点时间保持同步

val linesStream = ssc.textFileStream("hdfs://centos:9000/words")
 linesStream.flatMap(_.split("\\s+")) //细化
      .map((_,1))
      .reduceByKey(_+_)
      .print() //将计算结果打印
  1. 先将需要采集的文件上传到HDFS的非采集目录

[root@centos ~]# hdfs dfs -put install.log /

  1. 将上传完成数据移动到采集目录

[root@centos ~]# hdfs dfs -mv /install.log /words

或者使用

 val linesStream = ssc.fileStream[LongWritable,Text,TextInputFormat]("hdfs://centos:9000/words")
 linesStream.flatMap(t=>t._2.toString.split("\\s+")) //细化
      .map((_,1))
      .reduceByKey(_+_)
      .print() //将计算结果打印

Socket形式(测试)

val linesStream = ssc.socketTextStream("centos",9999)

Custom Receivers

class CustomReciver(storageLevel: StorageLevel) extends Receiver[String](storageLevel: StorageLevel) with Logging{
    override def onStart(): Unit = {
        new Thread("Socket Receiver") {
            override def run() { receive() }
        }.start()
    }
    override def onStop(): Unit = {
        println("释放资源")
    }
    private def receive() { //负责从外围系统读取数据
        val lines = List("this is a demo","hello word","good good")
        try {
            var userInput:String=lines(new Random().nextInt(lines.size))
            while(!isStopped && userInput != null) {
                store(userInput) //将获取的数据存储到Spark的内存中
                Thread.sleep(800)
                userInput=lines(new Random().nextInt(lines.size))
            }
        } catch {
            case e: Exception =>
            restart("Error connecting to", e)
        }
    }
}
val linesStream = ssc.receiverStream[String](new CustomReciver(StorageLevel.MEMORY_ONLY))
//3.对数据流进行计算 mirco-rdd 转换
linesStream.flatMap(_.split("\\s+"))
.map((_,1))
.reduceByKey(_+_)
.print() //将计算结果打印

Spark和Kafka整合(掌握)

参考:http://spark.apache.org/docs/latest/streaming-kafka-integration.html

<!--适配kafka-0.10+-->
<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-streaming-kafka-0-10_${scala.version}</artifactId>
    <version>${spark.version}</version>
</dependency>
<!--kafka-0.10以前版本-->
<dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-streaming-kafka-0-8_${scala.version}</artifactId>
    <version>${spark.version}</version>
</dependency>

spark-streaming-kafka-0-10兼容kafka-0.10+版本,由于Kafka-0.8版本和Kafka-0.10版本的消费者API发生了变化,原因是由于在Kafka-0.10+开始消费者支持分区的自动发现。

//1.创建StreamingContext
val sparkConf = new SparkConf().setMaster("local[5]").setAppName("HelloWorld")
var ssc=new StreamingContext(sparkConf,Seconds(1))//1s一次微批处理

ssc.sparkContext.setLogLevel("FATAL")//关闭日志输出
//2.构建DStream对象 细化
val kafkaParams = Map[String, Object](
    ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG -> "CentOS:9092",
    ConsumerConfig.GROUP_ID_CONFIG -> "g1",
    ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG -> classOf[StringDeserializer],
    ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG -> classOf[StringDeserializer])

KafkaUtils.createDirectStream[String,String](
    ssc,
    LocationStrategies.PreferConsistent,
    ConsumerStrategies.Subscribe[String,String](Array[String]("topic01").toSet,kafkaParams)
)
.map(record=> (record.key(),record.partition(),record.offset(),record.value(),record.timestamp()))
    .map(t=>t._4)
    .flatMap(_.split("\\s+"))
    .map((_,1))
    .reduceByKey(_+_)
    .print()

//4.启动计算
ssc.start()
ssc.awaitTermination()

流计算的常见算子

由于Spark DStreams算子和RDD的算子几乎是一模一样,所以具体的算子的使用请参考RDD转换算子

TransformationMeaning
map(func)Return a new DStream by passing each element of the source DStream through a function func.
flatMap(func)Similar to map, but each input item can be mapped to 0 or more output items.
filter(func)Return a new DStream by selecting only the records of the source DStream on which func returns true.
repartition(numPartitions)Changes the level of parallelism in this DStream by creating more or fewer partitions.
union(otherStream)Return a new DStream that contains the union of the elements in the source DStream and otherDStream.
count()Return a new DStream of single-element RDDs by counting the number of elements in each RDD of the source DStream.
reduce(func)Return a new DStream of single-element RDDs by aggregating the elements in each RDD of the source DStream using a function func (which takes two arguments and returns one). The function should be associative and commutative so that it can be computed in parallel.
countByValue()When called on a DStream of elements of type K, return a new DStream of (K, Long) pairs where the value of each key is its frequency in each RDD of the source DStream.
reduceByKey(func, [numTasks])When called on a DStream of (K, V) pairs, return a new DStream of (K, V) pairs where the values for each key are aggregated using the given reduce function. Note: By default, this uses Spark’s default number of parallel tasks (2 for local mode, and in cluster mode the number is determined by the config property spark.default.parallelism) to do the grouping. You can pass an optional numTasks argument to set a different number of tasks.
join(otherStream, [numTasks])When called on two DStreams of (K, V) and (K, W) pairs, return a new DStream of (K, (V, W)) pairs with all pairs of elements for each key.
cogroup(otherStream, [numTasks])When called on a DStream of (K, V) and (K, W) pairs, return a new DStream of (K, Seq[V], Seq[W]) tuples.
transform(func)Return a new DStream by applying a RDD-to-RDD function to every RDD of the source DStream. This can be used to do arbitrary RDD operations on the DStream.
updateStateByKey(func)Return a new “state” DStream where the state for each key is updated by applying the given function on the previous state of the key and the new values for the key. This can be used to maintain arbitrary state data for each key.

join

//001 zhangsan
val userStream=ssc.socketTextStream("centos",9999)
.map(line=> line.split("\\s+"))
.map(ts=>(ts(0),ts(1)))
//001 apple
val orderStream=ssc.socketTextStream("centos",8888)
.map(line=> line.split("\\s+"))
.map(ts=>(ts(0),ts(1)))

userStream.join(orderStream)
.print()

countByValue

//this this is
ssc.socketTextStream("centos",9999)
    .flatMap(_.split("\\s+"))
    .countByValue()
    .print()// this 2 is 1

一般很少使用,原因是必须要保证需要join的数据同时发送出去,才可能发生join

transform

ssc.socketTextStream("centos",9999)
.map(line=> line.split("\\s+"))
.map(ts=>(ts(0),ts(1)))
.transform(rdd=> rdd.leftOuterJoin(userRDD))
.map(t=>(t._1,t._2._1,t._2._2.getOrElse("***")))
.print()

可以获取DStreams底层的RDD对象,直接操作RDD算子

其它算子的使用细节参考:https://blog.youkuaiyun.com/weixin_38231448/article/details/89516569

状态计算(重点)

Spark提供了两个算子updateStateByKey(func) | mapWithState,它们都可以完成对(K,V)结构的数据进行有状态计算和持续计算

updateStateByKey(func) - 全量更新
//1.创建StreamingContext
val sparkConf = new SparkConf().setMaster("local[5]").setAppName("HelloWorld")
var ssc=new StreamingContext(sparkConf,Seconds(1))//1s一次微批处理
ssc.sparkContext.setLogLevel("FATAL")//关闭日志输出
ssc.checkpoint("file:///D:/checkpoints")
ssc.socketTextStream("centos",9999)
.flatMap(_.split("\\s+"))
.map((_,1))
.updateStateByKey((values:Seq[Int],state:Option[Int])=>{
    Some(values.fold(0)(_+_)+state.getOrElse(0))
})
.print()
//4.启动计算
ssc.start()
ssc.awaitTermination()
mapWithState - 增量更新 √
val sparkConf = new SparkConf().setMaster("local[5]").setAppName("HelloWorld")
var ssc=new StreamingContext(sparkConf,Seconds(1))//1s一次微批处理
ssc.sparkContext.setLogLevel("FATAL")//关闭日志输出
ssc.checkpoint("file:///D:/checkpoints")
ssc.socketTextStream("centos",9999)
.flatMap(_.split("\\s+"))
.map((_,1))
.mapWithState(StateSpec.function((k:String,v:Option[Int],s:State[Int])=>{
    val historyCount = s.getOption().getOrElse(0) //从历史状态中获取数据
    s.update(historyCount+v.getOrElse(0))//更新历史状态
    (k,s.getOption().getOrElse(0))
}))
.print()
//4.启动计算
ssc.start()
ssc.awaitTermination()

如果用户想使用这些有状态算子,必须给Spark设置checkpointdir,存储程序运行过程中的计算状态

故障恢复

Spark在第一次启动的时候会尝试从checkpointDir进行恢复,该目录存储程序的执行流程以及状态数据,如果有则直接从检查点自动恢复,否则执行 () => StreamingContex函数重新计算

val checkpointDir="file:///D:/checkpoints"
val ssc:StreamingContext=StreamingContext.getOrCreate(checkpointDir,()=>{
    //1.创建StreamingContext
    val sparkConf = new SparkConf().setMaster("local[5]").setAppName("HelloWorld")
    var ssc=new StreamingContext(sparkConf,Seconds(1))//1s一次微批处理
    ssc.checkpoint(checkpointDir)
    ssc.socketTextStream("centos",9999)
    .flatMap(_.split("\\s+"))
    .map((_,1))
    .mapWithState(StateSpec.function((k:String,v:Option[Int],s:State[Int])=>{
        val historyCount = s.getOption().getOrElse(0) //从历史状态中获取数据
        s.update(historyCount+v.getOrElse(0))//更新历史状态
        (k,s.getOption().getOrElse(0))
    }))
    .print()
    ssc
})
ssc.sparkContext.setLogLevel("FATAL")//关闭日志输出
ssc.start()
ssc.awaitTermination()

窗口计算(重点)

基本概念

Spark Streaming支持针对某个时间窗内实现对数据计算,如下:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7DpjLw6o-1570946269433)(assets/1569722452360.png)]

上图描绘的是 以3倍的微批次作为一个窗口长度,并且以2倍微批次作为滑动间隔。将落入到相同时间窗口的微批次合并成一个相对较大的微批次-窗口批次。

Spark要求所有的窗口的长度以及滑动的间隔必须是微批次的整倍数。

  • 滑动窗口:窗口长度 > 滑动间隔 窗口与窗口之间存在元素的重叠。
  • 滚动窗口:窗口长度 = 滑动间隔 窗口与窗口之间没有元素的重叠。

目前不存在 窗口长度 < 滑动间隔这种窗口。

窗口计算时间属性:Event Time- 事件时间<Ingestion Time - 摄取时间<Processing Time -处理时间

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MBYR37v5-1570946269433)(assets/1569723509578.png)]

Spark DStreaming 目前仅仅支持 Processing Time -处理时间, 但是Spark的Structured Streaming 支持Event Time(后续讲解)

窗口算子
TransformationMeaning
window(windowLength, slideInterval)Return a new DStream which is computed based on windowed batches of the source DStream.
countByWindow(windowLength, slideInterval)Return a sliding window count of elements in the stream.
reduceByWindow(func, windowLength, slideInterval)Return a new single-element stream, created by aggregating elements in the stream over a sliding interval using func. The function should be associative and commutative so that it can be computed correctly in parallel.
reduceByKeyAndWindow(func, windowLength, slideInterval, [numTasks])When called on a DStream of (K, V) pairs, returns a new DStream of (K, V) pairs where the values for each key are aggregated using the given reduce function func over batches in a sliding window. Note: By default, this uses Spark’s default number of parallel tasks (2 for local mode, and in cluster mode the number is determined by the config property spark.default.parallelism) to do the grouping. You can pass an optional numTasks argument to set a different number of tasks.
reduceByKeyAndWindow(func, invFunc, windowLength, slideInterval, [numTasks])A more efficient version of the above reduceByKeyAndWindow() where the reduce value of each window is calculated incrementally using the reduce values of the previous window. This is done by reducing the new data that enters the sliding window, and “inverse reducing” the old data that leaves the window. An example would be that of “adding” and “subtracting” counts of keys as the window slides. However, it is applicable only to “invertible reduce functions”, that is, those reduce functions which have a corresponding “inverse reduce” function (taken as parameter invFunc). Like in reduceByKeyAndWindow, the number of reduce tasks is configurable through an optional argument. Note that checkpointing must be enabled for using this operation.
countByValueAndWindow(windowLength,slideInterval, [numTasks])When called on a DStream of (K, V) pairs, returns a new DStream of (K, Long) pairs where the value of each key is its frequency within a sliding window. Like in reduceByKeyAndWindow, the number of reduce tasks is configurable through an optional argument.
window(windowLength, slideInterval)
val sparkConf=new SparkConf().setAppName("WondowWordCount").setMaster("local[6]")
val ssc = new StreamingContext(sparkConf,Milliseconds(100))

ssc.socketTextStream("CentOS",9999,StorageLevel.MEMORY_AND_DISK)
.flatMap(_.split("\\s+"))
.map((_,1))
.window(Seconds(4),Seconds(2))
.reduceByKey(_+_)
.print()

ssc.start()
ssc.awaitTermination()

以上window后可以更的算子:count、reduce、reduceByKey、countByValue为了方便起见Spark提供合成算子例如

window+count 等价于 countByWindow**(windowLength, slideInterval)、window+reduceByKey 等价 reduceByKeyAndWindow

reduceByKeyAndWindow
val sparkConf=new SparkConf().setAppName("WondowWordCount").setMaster("local[6]")
val ssc = new StreamingContext(sparkConf,Milliseconds(100))
ssc.sparkContext.setLogLevel("FATAL")

ssc.socketTextStream("CentOS",9999,StorageLevel.MEMORY_AND_DISK)
    .flatMap(_.split("\\s+"))
    .map((_,1))
    .reduceByKeyAndWindow((v1:Int,v2:Int)=>v1+v2,Seconds(4),Seconds(3))
    .print()

ssc.start()
ssc.awaitTermination()

如果窗口重合过半,在计算窗口值的时候,可以使用下面方式计算结果

val sparkConf=new SparkConf().setAppName("WondowWordCount").setMaster("local[6]")
val ssc = new StreamingContext(sparkConf,Milliseconds(100))
ssc.sparkContext.setLogLevel("FATAL")
ssc.checkpoint("file:///D:/checkpoints")
ssc.socketTextStream("CentOS",9999,StorageLevel.MEMORY_AND_DISK)
.flatMap(_.split("\\s+"))
.map((_,1))
.reduceByKeyAndWindow(//当窗口重叠 超过50% ,使用以下计算效率较高
    (v1:Int,v2:Int)=>v1+v2,//上一个窗口结果+新进来的元素
    (v1:Int,v2:Int)=>v1-v2,//减去移出元素
    Seconds(4),
    Seconds(3),
    filterFunc = (t)=> t._2 > 0
)
.print()

ssc.start()
ssc.awaitTermination()

DStreams输出

Output OperationMeaning
print()Prints the first ten elements of every batch of data in a DStream on the driver node running the streaming application. This is useful for development and debugging.
foreachRDD(func)The most generic output operator that applies a function, func, to each RDD generated from the stream. This function should push the data in each RDD to an external system, such as saving the RDD to files, or writing it over the network to a database. Note that the function func is executed in the driver process running the streaming application, and will usually have RDD actions in it that will force the computation of the streaming RDDs.
val sparkConf=new SparkConf().setAppName("WondowWordCount").setMaster("local[6]")
val ssc = new StreamingContext(sparkConf,Milliseconds(100))
ssc.sparkContext.setLogLevel("FATAL")
ssc.socketTextStream("CentOS",9999,StorageLevel.MEMORY_AND_DISK)
.flatMap(_.split("\\s+"))
.map((_,1))
.reduceByKeyAndWindow(
    (v1:Int,v2:Int)=>v1+v2,//上一个窗口结果+新进来的元素
    Seconds(60),
    Seconds(1)
)
.filter(t=> t._2 > 10)
.foreachRDD(rdd=>{
    rdd.foreachPartition(vs=>{
        vs.foreach(v=>KafkaSink.send2Kafka(v._1,v._2.toString))
    })
})

ssc.start()
ssc.awaitTermination()
object KafkaSink {

  private def createKafkaProducer(): KafkaProducer[String, String] = {
    val props = new Properties()
    props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,"CentOS:9092")
    props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,classOf[StringSerializer])
    props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,classOf[StringSerializer])
    props.put(ProducerConfig.BATCH_SIZE_CONFIG,"10")
    props.put(ProducerConfig.LINGER_MS_CONFIG,"1000")
    new KafkaProducer[String,String](props)
  }
  val kafkaProducer:KafkaProducer[String,String]=createKafkaProducer()

  def send2Kafka(k:String,v:String): Unit ={
    val message = new ProducerRecord[String,String]("topic01",k,v)
    kafkaProducer.send(message)
  }
  Runtime.getRuntime.addShutdownHook(new Thread(){
    override def run(): Unit = {
      kafkaProducer.flush()
      kafkaProducer.close()
    }
  })
}
props.put(ProducerConfig.LINGER_MS_CONFIG,"1000")
new KafkaProducer[String,String](props)

}
val kafkaProducer:KafkaProducer[String,String]=createKafkaProducer()

def send2Kafka(k:String,v:String): Unit ={
val message = new ProducerRecordString,String
kafkaProducer.send(message)
}
Runtime.getRuntime.addShutdownHook(new Thread(){
override def run(): Unit = {
kafkaProducer.flush()
kafkaProducer.close()
}
})
}


> 对于Spark而言,默认只有当窗口的时间结束之后才会将窗口的计算结果最终输出,通常将该种输出方式为`钳制`输出形式。
Spark Streaming:通过Dstreams 或 DataFrames做流数据处理,结果写入ClickHouse或Hive表 Apache Spark 当前最流行的大数据处理框架之一。最初它是作为替代 Hadoop 的 MapReduce 批处理框架而创建的,但现在它也支持 SQL、机器学习和流处理。今天我们重点看看 Spark Streaming,展示常用流处理的方式。 流数据处理常出现在大数据用例中,用于连续生成动态数据的场景。在大多数情况下,数据以近似实时的方式处理,一次一条记录,处理结果用于提供及时的报警、呈现在仪表板上或者提供给机器学习模型,让我们基于数据的变化快速做出反应。 Dstre... 阅读详情

相关推荐

Spark系列--Spark Streaming(六)DStreams转换

前言 DStream上的原语与RDD的类似,分为Transformations(转换)和Output Operations(输出)两种,此外转换操作中还有一些比较特殊的原语,如:updateStateByKey()、transform()以及各种Window相关的原语。 Transformation Meaning map(func) 将源DStream中的每个元素...

淡淡的倔强的博客 1857

简单命令挺有用的

netstat -na | grep ESTAB | grep 80 | wc -l netstat -na | grep ESTAB | grep 8080 | wc -l

专注-享学课堂 3万+

Spark系列--Spark Streaming(三)DStreams输入--基本数据源及自定义Receiver

前言 Spark Streaming原生支持一些不同的数据源。一些“核心”数据源已经被打包到Spark Streaming 的 Maven 工件中,而其他的一些则可以通过 spark-streaming-kafka 等附加工件获取。每个接收器都以 Spark 执行器程序中一个长期运行的任务的形式运行,因此会占据分配给应用的 CPU 核心。此外,我们还需要有可用的 CPU 核心来处理数据。这意味着...

淡淡的倔强的博客 1643

Metasploit - auxiliary/gather/zoomeye_search

How to use ZoomEye API ?If you are a python developer, please view ZoomEye-SDK. If not, ZoomEye API Documentation is good for you.$ sudo easy_install zoomeye-SDKor$ sudo pip install git+https://github.

Nixawk 59万+

Spark流编程指引(四)---------------------------DStreams基本模型,输入DStreams和接收者

离散流(DStreams) 离散流或者称为DStreams是Spark流编程提供的基本抽象。它代表了持续的数据流,从一个数据源接收到的数据流或者是在一个输入流上应用转变操作处理后的数据流。 在内部实现上,DStream代表了一系列连续的RDDs.RDDs是Spark对不可变的,分布式数据集的抽象。DStream中的每个RDD包含了一定间隔内的数据,正如下图所示: 任何应用在DStream上的

happyAnger6的专栏 2936

JZZ-gui-Player:用于浏览器的MIDI播放器

JZZ-gui-Player 用于浏览器的MIDI播放器GUI 观看... 安装 npm install jzz-gui-player --save 或bower install jzz-gui-player 或yarn add jzz-gui-player 或从获取完整的开发版本和缩小的脚本 用法 Web组件(聚合物) https://github.com/jazz-soft/polymer-midi-player 纯HTML < script src =" JZZ.js " > </ script > < script src =" JZZ.midi.SMF.js " > </ script > < script src =" JZZ.gui.Player.js " > </ script > //... CDN(jsdelivr) < script src =" h

392. Is Subsequence

内容:Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string

zhangshjzzz的博客 2501

STM32红外遥控器密码锁

本实验开机在LCD上显示一些信息之后,即进入等待红外触发,如过接收到正确的红外信号,则解码,并在LCD上显示键值和所代表的意义,以及按键次数等信息。同样我们也是用DS0来指示程序正在运行。

使用官方提供的帮助也下载不了源码的解决方案

Downloading the Source Tree Installing Repo Repo is a tool that makes it easier to work with Git in the context of Android. For more information about Repo, see Version Control. To install, initia

android大牛MrJing 活动中心 2303

用Simulink复现Hopf振荡器:从数学公式到稳定极限环的保姆级仿真教程

本文详细介绍了如何在Simulink中实现Hopf振荡器,从数学原理到仿真建模的全过程。通过参数调试和波形分析,帮助读者掌握Hopf振荡器的核心特性及其在机器人控制等领域的应用。特别强调了自适应调节技巧,提升系统稳定性和鲁棒性。

weixin_29261711的博客 446

电源完整性之Cadence Sigrity Power SI_AC阻抗仿真

之前和大家分享过电源完整性之仿真设计原理链接: [link](https://blog.youkuaiyun.com/weixin_41808082/article/details/117065140?spm=1001.2014.3001.5501).今天接着上一篇文章总结一下电源AC阻抗的的仿真操作流程及一些simulation中的设置参数,用到的时候Cadence Sigrity 中的Power SI组件,下面开始享受仿真的快乐吧: 1.仿真模式选择与文件导入 选择Cadence Sigrity下的Power SI

刘小同学的博客 1万+

Spark Streaming核心概念二(DStreams)

一、DStreamsDStreams是最基础的抽象类在Spark Streaming,它代表持续不断的数据流,数据流要么来源于input 数据流,要么来源于一个DStreamsz进过转换后生成的另外一个DStreaming,实际上一个DStreams一系列的RDD.每一个RDD包含的数据是一个间隔内的数据(批次)对Dstreams操作算子,比如map/flatMap,其实底层都会被翻译为对DStr...

fengfengchen95的博客 520

手把手教你用Nangate 45nm开源工艺库搞定数字电路仿真(附FreePDK资源)

本文详细介绍了如何使用Nangate 45nm开源工艺库进行数字电路仿真,包括环境搭建、关键文件解析、仿真环境配置及低功耗设计等实战内容。特别推荐FreePDK资源,帮助读者快速掌握从理论到实践的全流程操作,适用于学术研究和小规模数字电路设计。

weixin_30352645的博客 491

Spark Streaming 输入DStreams 和 Receivers

1. 输入DStream与Receiver输入DStreams表示从源中获取输入数据流的DStreams。在指南一示例中,lines表示输入DStream,它代表从netcat服务器获取的数据流。每一个输入DStream(除 file stream)都 与一个接收器Receiver相关联,接收器从源中获取数据,并将数据存入Spark内存中来进行处理。 输入DStreams表示从数据源获取的原始数据

SmartSi 1451

Ubuntu系统下主板GPU温控pwm风扇

在Linux系统下——以Ubuntu为例,配置主板sys_fan等接口连接pwm温控风扇转速根据NVIDIA GPU温度,为服务器GPU等无主动散热显卡提供散热。

罗思哲的博客 5040

《Hadoop大数据技术原理与应用》(第2版)黑马程序员的课后习题答案

《Hadoop大数据技术原理与应用》(第2版)黑马程序员的课后习题答案

qq_36773158的博客 4656

Spark Streaming (DStreams) 和 Structured Streaming 中的状态管理

Spark流处理状态管理:有状态操作与容错机制 Spark流处理(DStreams/Structured Streaming)通过状态管理支持聚合、连接等有状态操作,确保容错性。核心包括: 有状态操作 聚合:DStreams使用updateStateByKey/mapWithState;Structured Streaming通过groupBy+窗口函数或mapGroupsWithState实现,需维护键值状态。 连接:流-流连接需缓存数据(状态)等待匹配,依赖水印防止状态无限增长。 其他:去重、会话跟踪等

csdn_tom_168的博客 790

华为2022数字芯片笔试题

单选 1、ASIC开发流程中,如下环节的先后顺序是? A. RTL-> Synthesis->P&R B. Synthesis->P&R->RTL C. Synthesis->RTL->P&R D.RTL->P&R->Synthesis 2、o10换算成十进制是多少? A. 8 B.16 C.10 D.2 3、reg [7:0] mem [1:256];initial $readmemh("me..

weixin_44072819的博客 1万+

[Spark]Spark Streaming 指南三 DStreams

离散流或者DStreams是Spark Streaming提供的基本抽象,它代表一个连续的数据流。从源中获取输入流,或者是输入流通过转换算子生成的处理后的数据流。在内部,DStreams由一系列连续的 RDD组成。这是Spark对不可变,分布式数据集的抽象(更多细节参见Spark编...

weixin_34041003的博客 122

第3版•系统集成项目管理工程师(中级) │ 第6章 数据工程

🥏第3版•系统集成项目管理工程师(中级) │ 第6章 数据工程

✨ 欢迎来到【Seal ^_^ 的优快云博客】!✨ 1万+

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

DStreams 和 Structured Streaming 的概念和使用方法

DStreams更加灵活,适合那些对延迟要求不是非常苛刻的应用场景。它基于微批处理机制,提供了丰富的 API 来处理流数据,但同时也带来了较高的延迟和复杂的状态管理需求。则提供了更低的延迟、更好的容错性和更简单的编程模型,尤其适合需要高一致性和精确一次语义的现代应用。其声明式的编程风格和内置的状态管理功能使得开发者可以更专注于业务逻辑,而无需过多考虑底层细节。

Davina_yu的博客 1232

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Spark系列--Spark Streaming(七)DStreams输出

前言 输出操作指定了对流数据经转化操作得到的数据所要执行的操作(例如把结果推入外部数据库或输出到屏幕上)。与 RDD 中的惰性求值类似,如果一个 DStream 及其派生出的 DStream 都没有被执行输出操作,那么这些 DStream 就都不会被求值。如果 StreamingContext 中没有设定输出操作,整个 context 就都不会启动。 Tables Are ...

淡淡的倔强的博客 729

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

我的大数据之旅-Spark DStreams输入

DStream输入 基本数据源 文件数据源 创建方式: StreamingContext.fileStream[KeyClass, ValueClass, InputFormatClass] 文本文件: streamingContext.textFileStream(dataDirectory) pom.xml <?xml version="1.0" enc...

远方·玲玲 301

结构化学习:构建高效知识框架的方法与实践

结构化学习是一种系统化的知识管理方法,通过建立概念间的逻辑关联形成知识网络。其核心原理基于认知心理学的图式理论,将零散信息整合为有机体系。这种方法能显著提升学习效率,在知识密集型行业如IT、教育等领域应用广泛。典型实践包括使用思维导图进行领域解构、通过双链笔记建立概念联系,以及构建多维验证体系。现代工具如Obsidian、Notion等为知识框架的构建和维护提供了技术支持。研究表明,采用结构化学习方法可使知识提取速度提升50%以上,是应对信息过载时代的有效策略。

weixin_33976072的博客 221
上一篇: Spark RDD学习资料
下一篇: Spark SQL
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值