data at the speed of your users
play

Data at the Speed of your Users Apache Cassandra and Spark for - PowerPoint PPT Presentation

Data at the Speed of your Users Apache Cassandra and Spark for simple, distributed, near real-time stream processing. GOTO Copenhagen 2014 Rustam Aliyev Solution Architect at . @rstml Big Data? Photo:


  1. Data at the Speed of your Users Apache Cassandra and Spark for simple, distributed, near real-time stream processing. GOTO Copenhagen 2014

  2. Rustam Aliyev Solution Architect at . � � @rstml

  3. Big Data? Photo: Flickr / Watches En Masse

  4. � � � Volume Variety Velocity

  5. Velocity = Near Real Time

  6. Near Real Time?

  7. Near Real Time 0.5 sec ≤ ≤ 60 sec

  8. Use Cases Photo: Flickr / Swiss Army / Jim Pennucci

  9. Web Analytics Dynamic Pricing Recommendation Fraud Detection

  10. Architecture Photo: Ilkin Kangarli / Baku Haydar Aliyev Center

  11. Architecture Goals Low Latency High Availability Horizontal Scalability Simplicity

  12. Stream Processing � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � Collection Processing Storing Delivery

  13. Stream Processing  � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � Collection Delivery � � Spark Cassandra

  14. Cassandra Distributed Database Photo: Flickr / Hypostyle Hall / Jorge Láscar

  15. Data Model

  16. Partition Cell 1 Cell 2 Cell 3 … Partition Key

  17. Partition os: storage: version: weight: Nexus 5 Android 32GB 4.4 130g sort order on disk

  18. Table os: storage: version: weight: Nexus 5 Android 32GB 4.4 130g os: storage: version: weight: iPhone 6 iOS 64GB 8.0 129g os: memory: version: weight: Other

  19. Distribution

  20. 0000 Nexus 5 3D97 2000 E000 C000 4000 6000 A000 8000

  21. 0000 iPhone 6 9C4F 2000 E000 C000 4000 3D97 6000 A000 8000

  22. Replication

  23. 1 replica 0000 2000 E000 C000 4000 3D97 6000 A000 9C4F 8000

  24. 2 replicas 0000 2000 E000 C000 4000 3D97 9C4F 6000 A000 3D97 9C4F 8000

  25. Spark Distributed Data Processing Engine Photo: Flickr / Sparklers / Alexandra Compo / CreativeCommons

  26. Fast In-memory

  27. Logistic Regression 4000 3000 Running Time (s) Spark 2000 Hadoop 1000 1 5 10 20 30 Number of Iterations

  28. Easy

  29. map reduce �

  30. map reduce sample filter count take groupBy fold first sort reduceByKey partitionBy union groupByKey mapWith join cogroup pipe leftOuterJoin cross save 
 rightOuterJoin zip ...

  31. RDD Resilient Distributed Datasets Node 2 Node 1 Node 3 Node 2 Node 1 Node 3

  32. Operator DAG groupBy join map filter Disk RDD Memory RDD

  33. Spark Streaming Micro-batching

  34. RDD Data Stream DStream

  35. Spark + Cassandra DataStax Spark Cassandra Connector

  36. https://github.com/datastax/spark-cassandra-connector

  37.    M    Cassandra   Spark Worker M  Spark Master & Worker M

  38. Demo � � Twitter Analytics

  39. Cassandra Data Model

  40. ALL: 2014-09-21: 2014-09-20: 2014-09-19: #hashtag 7139 220 309 129 sort order

  41. CREATE ¡TABLE ¡hashtags ¡( ¡ ¡ ¡ ¡ ¡hashtag ¡text, ¡ ¡ ¡ ¡ ¡interval ¡text, ¡ ¡ ¡ ¡ ¡mentions ¡counter, ¡ ¡ ¡ ¡ ¡PRIMARY ¡KEY((hashtag), ¡interval) ¡ ) ¡WITH ¡CLUSTERING ¡ORDER ¡BY ¡(interval ¡DESC); ¡

  42. Processing Data Stream

  43. import ¡com.datastax.spark.connector.streaming._ ¡ � val ¡sc ¡= ¡new ¡SparkConf() ¡ ¡ ¡.setMaster("spark://127.0.0.1:7077") ¡ ¡ ¡.setAppName("Twitter-­‑Demo") ¡ ¡ ¡.setJars("demo-­‑assembly-­‑1.0.jar")) ¡ ¡ ¡.set("spark.cassandra.connection.host", ¡"127.0.0.1") ¡ � val ¡ssc ¡= ¡new ¡StreamingContext(sc, ¡Seconds(2)) ¡ � val ¡stream ¡= ¡TwitterUtils. ¡ ¡ ¡createStream(ssc, ¡None, ¡Nil, ¡storageLevel ¡= ¡StorageLevel.MEMORY_ONLY_SER_2) ¡ � val ¡hashTags ¡= ¡stream.flatMap(tweet ¡=> ¡ ¡ ¡tweet.getText.toLowerCase.split(" ¡"). ¡ ¡ ¡filter(tags.contains(Seq("#iphone", ¡"#android")))) ¡ � val ¡tagCounts ¡= ¡hashTags.map((_, ¡1)).reduceByKey(_ ¡+ ¡_) ¡ � val ¡tagCountsAll ¡= ¡tagCounts.map{ ¡ ¡ case ¡(tag, ¡mentions) ¡=> ¡(tag, ¡mentions, ¡"ALL") ¡ } ¡ � tagCountsAll.saveToCassandra( ¡

  44. import ¡com.datastax.spark.connector.streaming._ ¡ � val ¡sc ¡= ¡new ¡SparkConf() ¡ ¡ ¡.setMaster("spark://127.0.0.1:7077") ¡ ¡ ¡.setAppName("Twitter-­‑Demo") ¡ ¡ ¡.setJars("demo-­‑assembly-­‑1.0.jar")) ¡ ¡ ¡.set("spark.cassandra.connection.host", ¡"127.0.0.1") ¡ � val ¡ssc ¡= ¡new ¡StreamingContext(sc, ¡Seconds(2)) ¡ � val ¡stream ¡= ¡TwitterUtils. ¡ ¡ ¡createStream(ssc, ¡None, ¡Nil, ¡storageLevel ¡= ¡StorageLevel.MEMORY_ONLY_SER_2) ¡ � val ¡hashTags ¡= ¡stream.flatMap(tweet ¡=> ¡ ¡ ¡tweet.getText.toLowerCase.split(" ¡"). ¡ ¡ ¡filter(tags.contains(Seq("#iphone", ¡"#android")))) ¡ � val ¡tagCounts ¡= ¡hashTags.map((_, ¡1)).reduceByKey(_ ¡+ ¡_) ¡ � val ¡tagCountsAll ¡= ¡tagCounts.map{ ¡ ¡ case ¡(tag, ¡mentions) ¡=> ¡(tag, ¡mentions, ¡"ALL") ¡ } ¡ � tagCountsAll.saveToCassandra( ¡

  45. import ¡com.datastax.spark.connector.streaming._ ¡ � val ¡sc ¡= ¡new ¡SparkConf() ¡ ¡ ¡.setMaster("spark://127.0.0.1:7077") ¡ ¡ ¡.setAppName("Twitter-­‑Demo") ¡ ¡ ¡.setJars("demo-­‑assembly-­‑1.0.jar")) ¡ ¡ ¡.set("spark.cassandra.connection.host", ¡"127.0.0.1") ¡ � val ¡ssc ¡= ¡new ¡StreamingContext(sc, ¡Seconds(2)) ¡ � val ¡stream ¡= ¡TwitterUtils. ¡ ¡ ¡createStream(ssc, ¡None, ¡Nil, ¡storageLevel ¡= ¡StorageLevel.MEMORY_ONLY_SER_2) ¡ � val ¡hashTags ¡= ¡stream.flatMap(tweet ¡=> ¡ ¡ ¡tweet.getText.toLowerCase.split(" ¡"). ¡ ¡ ¡filter(tags.contains(Seq("#iphone", ¡"#android")))) ¡ � val ¡tagCounts ¡= ¡hashTags.map((_, ¡1)).reduceByKey(_ ¡+ ¡_) ¡ � val ¡tagCountsAll ¡= ¡tagCounts.map{ ¡ ¡ case ¡(tag, ¡mentions) ¡=> ¡(tag, ¡mentions, ¡"ALL") ¡ } ¡ � tagCountsAll.saveToCassandra( ¡

  46. � val ¡ssc ¡= ¡new ¡StreamingContext(sc, ¡Seconds(2)) ¡ � val ¡stream ¡= ¡TwitterUtils. ¡ ¡ ¡createStream(ssc, ¡None, ¡Nil, ¡storageLevel ¡= ¡StorageLevel.MEMORY_ONLY_SER_2) ¡ � val ¡hashTags ¡= ¡stream.flatMap(tweet ¡=> ¡ ¡ ¡tweet.getText.toLowerCase.split(" ¡"). ¡ ¡ ¡filter(tags.contains(Seq("#iphone", ¡"#android")))) ¡ � val ¡tagCounts ¡= ¡hashTags.map((_, ¡1)).reduceByKey(_ ¡+ ¡_) ¡ � val ¡tagCountsAll ¡= ¡tagCounts.map{ ¡ ¡ case ¡(tag, ¡mentions) ¡=> ¡(tag, ¡mentions, ¡"ALL") ¡ } ¡ � tagCountsAll.saveToCassandra( ¡ ¡ "demo_ks", ¡"hashtags", ¡Seq("hashtag", ¡"mentions", ¡"interval")) ¡ � ssc.start() ¡ ssc.awaitTermination() ¡

  47. � val ¡ssc ¡= ¡new ¡StreamingContext(sc, ¡Seconds(2)) ¡ � val ¡stream ¡= ¡TwitterUtils. ¡ ¡ ¡createStream(ssc, ¡None, ¡Nil, ¡storageLevel ¡= ¡StorageLevel.MEMORY_ONLY_SER_2) ¡ � val ¡hashTags ¡= ¡stream.flatMap(tweet ¡=> ¡ ¡ ¡tweet.getText.toLowerCase.split(" ¡"). ¡ ¡ ¡filter(tags.contains(Seq("#iphone", ¡"#android")))) ¡ � val ¡tagCounts ¡= ¡hashTags.map((_, ¡1)).reduceByKey(_ ¡+ ¡_) ¡ � val ¡tagCountsByDay ¡= ¡tagCounts.map{ ¡ ¡ case ¡(tag, ¡mentions) ¡=> ¡(tag, ¡mentions, ¡DateTime.now.toString("yyyyMMdd")) ¡ } ¡ � tagCountsByDay.saveToCassandra( ¡ ¡ "demo_ks", ¡"hashtags", ¡Seq("hashtag", ¡"mentions", ¡"interval")) ¡ � ssc.start() ¡ ssc.awaitTermination() ¡

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