streaming items through a cluster with spark streaming
play

Streaming items through a cluster with Spark Streaming Tathagata TD - PowerPoint PPT Presentation

Streaming items through a cluster with Spark Streaming Tathagata TD Das @tathadas CME 323: Distributed Algorithms and Optimization Stanford, May 6, 2015 Who am I? Who am I? > Project Management Committee (PMC) member of Apache Spark >


  1. Streaming items through a cluster with Spark Streaming Tathagata “TD” Das @tathadas CME 323: Distributed Algorithms and Optimization Stanford, May 6, 2015

  2. Who am I? Who am I? > Project Management Committee (PMC) member of Apache Spark > Lead developer of Spark Streaming > Formerly in AMPLab, UC Berkeley > Software developer at Databricks > Databricks was started by creators of Spark to provide Spark-as-a-service in the cloud

  3. Big Data Big Data

  4. Big Big Streaming Streaming Data Data

  5. Why process Big Why process Big Streaming Streaming Data? Data? Fraud detection in bank transactions Anomalies in sensor data Cat videos in tweets

  6. How to Process Big How to Process Big Streaming Streaming Data Data Ingest Process Store data data results Raw Tweets > Ingest – Receive and buffer the streaming data > Process – Clean, extract, transform the data > Store – Store transformed data for consumption

  7. How to Process Big How to Process Big Streaming Streaming Data Data Ingest Process Store data data results Raw Tweets > For big streams, every step requires a cluster > Every step requires a system that is designed for it

  8. Stream Ingestion Systems Stream Ingestion Systems Ingest Process Store data data results Raw Tweets Amazon Kinesis > Kafka – popular distributed pub-sub system > Kinesis – Amazon managed distributed pub-sub > Flume – like a distributed data pipe

  9. Stream Ingestion Systems Stream Ingestion Systems Ingest Process Store data data results Raw Tweets > Spark Streaming – most demanded > Storm – most widely deployed (as of now ;) ) > Samza – gaining popularity in certain scenarios

  10. Stream Ingestion Systems Stream Ingestion Systems Ingest Process Store data data results Raw Tweets > File systems – HDFS, Amazon S3, etc. > Key-value stores – HBase, Cassandra, etc. > Databases – MongoDB, MemSQL, etc.

  11. Producers and Consumers Producers and Consumers Topic X Producer 1 Consumer (topicX, data1) (topicX, data3) (topicY, data2) (topicX, data1) (topicX, data3) (topicY, data2) Topic Y Kafka Cluster Producer 2 Consumer > Producers publish data tagged by “topic” > Consumers subscribe to data of a particular “topic”

  12. Topics and Partitions Topics and Partitions > Topic = category of message, divided into partitions > Partition = ordered, numbered stream of messages > Producer decides which (topic, partition) to put each message in

  13. Topics and Partitions Topics and Partitions > Topic = category of message, divided into partitions > Partition = ordered, numbered stream of messages > Producer decides which (topic, partition) to put each message in > Consumer decides which (topic, partition) to pull messages from - High-level consumer – handles fault-recovery with Zookeeper - Simple consumer – low-level API for greater control

  14. How to process Kafka messages? How to process Kafka messages? Ingest Process Store data data results Raw Tweets > Incoming tweets received in distributed manner and buffered in Kafka > How to process them?

  15. treaming

  16. What is Spark Streaming? What is Spark Streaming? Scalable, fault-tolerant stream processing system High-level API Fault-tolerant Integration joins, windows, … Exactly-once semantics, Integrate with MLlib, SQL, often 5x less code even for stateful ops DataFrames, GraphX Kafka Kafka File systems File systems Flume Flume Databases Databases HDFS HDFS Kinesis Kinesis Dashboards Dashboards Twitter Twitter

  17. How does Spark Streaming work? How does Spark Streaming work? > Receivers chop up data streams into batches of few seconds > Spark processing engine processes each batch and pushes out the results to external data stores Receivers Receivers data streams data streams results as results as batches as batches as RDDs RDDs RDDs RDDs

  18. Spark Programming Model Spark Programming Model > Resilient distributed datasets (RDDs) - Distributed, partitioned collection of objects - Manipulated through parallel transformations (map, filter, reduceByKey, …) - All transformations are lazy, execution forced by actions (count, reduce, take, …) - Can be cached in memory across cluster - Automatically rebuilt on failure

  19. Spark Streaming Programming Model Spark Streaming Programming Model > Discretized Stream (DStream) - Represents a stream of data - Implemented as a infinite sequence of RDDs > DStreams API very similar to RDD API - Functional APIs in - Create input DStreams from Kafka, Flume, Kinesis, HDFS, … - Apply transformations

  20. Example – Get Example – Get hashtags hashtags from Twitter from Twitter val ¡ssc ¡= ¡new ¡StreamingContext(conf, ¡Seconds(1)) ¡ StreamingContext ¡ is ¡the ¡star)ng ¡ Batch ¡interval, ¡by ¡which ¡ point ¡of ¡all ¡streaming ¡func)onality ¡ streams ¡will ¡be ¡chopped ¡up ¡

  21. Example – Get Example – Get hashtags hashtags from Twitter from Twitter val ¡ssc ¡= ¡new ¡StreamingContext(conf, ¡Seconds(1)) ¡ val ¡tweets ¡= ¡TwitterUtils.createStream(ssc, ¡auth) ¡ Input ¡DStream ¡ TwiCer ¡Streaming ¡API ¡ batch ¡@ ¡t ¡ batch ¡@ ¡t+1 ¡ batch ¡@ ¡t+2 ¡ tweets ¡DStream ¡ replicated ¡and ¡stored ¡in ¡ memory ¡as ¡RDDs ¡

  22. Example – Get Example – Get hashtags hashtags from Twitter from Twitter val ¡tweets ¡= ¡TwitterUtils.createStream(ssc, ¡None) ¡ val ¡hashTags ¡= ¡tweets.flatMap(status ¡=> ¡getTags(status)) ¡ transformed ¡ transforma0on : ¡modify ¡data ¡in ¡one ¡ DStream ¡ DStream ¡to ¡create ¡another ¡DStream ¡ ¡ batch ¡@ ¡t ¡ batch ¡@ ¡t+1 ¡ batch ¡@ ¡t+2 ¡ tweets ¡DStream ¡ flatMap ¡ flatMap ¡ flatMap ¡ hashTags ¡Dstream ¡ … new ¡RDDs ¡created ¡ [#cat, ¡#dog, ¡… ¡] ¡ for ¡every ¡batch ¡ ¡

  23. Example – Get hashtags Example – Get hashtags from Twitter from Twitter val ¡tweets ¡= ¡TwitterUtils.createStream(ssc, ¡None) ¡ val ¡hashTags ¡= ¡tweets.flatMap(status ¡=> ¡getTags(status)) ¡ hashTags.saveAsTextFiles("hdfs://...") ¡ output ¡opera0on : ¡to ¡push ¡data ¡to ¡external ¡storage ¡ batch ¡@ ¡t ¡ batch ¡@ ¡t+1 ¡ batch ¡@ ¡t+2 ¡ tweets ¡DStream ¡ flatMap flatMap flatMap hashTags ¡DStream ¡ save save save every ¡batch ¡ saved ¡to ¡HDFS ¡

  24. Example – Get hashtags Example – Get hashtags from Twitter from Twitter val ¡tweets ¡= ¡TwitterUtils.createStream(ssc, ¡None) ¡ val ¡hashTags ¡= ¡tweets.flatMap(status ¡=> ¡getTags(status)) ¡ hashTags.foreachRDD(hashTagRDD ¡=> ¡{ ¡... ¡}) ¡ foreachRDD : ¡do ¡whatever ¡you ¡want ¡with ¡the ¡processed ¡data ¡ batch ¡@ ¡t ¡ batch ¡@ ¡t+1 ¡ batch ¡@ ¡t+2 ¡ tweets ¡DStream ¡ flatMap flatMap flatMap hashTags ¡DStream ¡ foreach foreach foreach Write ¡to ¡a ¡database, ¡update ¡analy)cs ¡ UI, ¡do ¡whatever ¡you ¡want ¡

  25. Example – Get Example – Get hashtags hashtags from Twitter from Twitter val ¡tweets ¡= ¡TwitterUtils.createStream(ssc, ¡None) ¡ val ¡hashTags ¡= ¡tweets.flatMap(status ¡=> ¡getTags(status)) ¡ hashTags.foreachRDD(hashTagRDD ¡=> ¡{ ¡... ¡}) ¡ ¡ ¡ all ¡of ¡this ¡was ¡just ¡setup ¡for ¡what ¡to ¡do ¡when ¡ streaming ¡data ¡is ¡receiver ¡ ¡ ¡ ¡ this ¡actually ¡starts ¡the ¡receiving ¡and ¡processing ¡ ssc.start() ¡ ¡

  26. What’s going on inside? What’s going on inside? > Receiver buffers tweets Spark Cluster in Executors’ memory > Spark Streaming Driver launch tasks to launches tasks to process tweets process tweets Buffered Receiver Twitter Tweets Buffered Tweets Raw Tweets Driver running DStreams Executors

  27. What’s going on inside? What’s going on inside? Kafka Cluster Spark Cluster Receiver launch tasks to process data receive data in parallel Receiver Driver Receiver running DStreams Executors

  28. Performance Performance Can process 60M records/sec (6 GB/sec) 60M records/sec (6 GB/sec) on 100 nodes 100 nodes at sub-second sub-second latency 3.5 ¡ 7 ¡ Cluster ¡Thhroughput ¡(GB/s) ¡ WordCount ¡ Cluster ¡Throughput ¡(GB/s) ¡ Grep ¡ 6 ¡ 3 ¡ 2.5 ¡ 5 ¡ 4 ¡ 2 ¡ 3 ¡ 1.5 ¡ 2 ¡ 1 ¡ 1 ¡sec ¡ 1 ¡sec ¡ 1 ¡ 0.5 ¡ 2 ¡sec ¡ 2 ¡sec ¡ 0 ¡ 0 ¡ 0 ¡ 50 ¡ 100 ¡ 0 ¡ 50 ¡ 100 ¡ # ¡Nodes ¡in ¡Cluster ¡ # ¡Nodes ¡in ¡Cluster ¡

  29. Window-based Transformations Window-based Transformations val ¡tweets ¡= ¡ TwitterUtils.createStream(ssc, ¡auth) ¡ val ¡hashTags ¡= ¡tweets.flatMap(status ¡=> ¡getTags(status)) ¡ val ¡tagCounts ¡= ¡hashTags.window(Minutes(1), ¡Seconds(5)).countByValue() ¡ sliding ¡window ¡ window ¡length ¡ sliding ¡interval ¡ opera)on ¡ window ¡length ¡ DStream ¡of ¡data ¡ sliding ¡interval ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend