Spark Summit 2014: Spark Streaming for Realtime Auctions

6,844 views

Published on

Spark Summit (2014-06-30)
http://spark-summit.org/2014/talk/building-a-data-processing-system-for-real-time-auctions

What do you do when you need to update your models sooner than your existing batch workflows provide? At Sharethrough we faced the same question. Although we use Hadoop extensively for batch processing we needed a system to process click stream data as soon as possible for our real time ad auction platform. We found Spark Streaming to be a perfect fit for us because of it’s easy integration into the Hadoop ecosystem, powerful functional programming API, and low friction interoperability with our existing batch workflows.
In this talk, we’ll present about some of the use cases that led us to choose a stream processing system and why we use Spark Streaming in particular. We’ll also discuss how we organized our jobs to promote reusability between batch and streaming workflows as well as improve testability

Published in: Data & Analytics, Technology
0 Comments
41 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,844
On SlideShare
0
From Embeds
0
Number of Embeds
3,127
Actions
Shares
0
Downloads
212
Comments
0
Likes
41
Embeds 0
No embeds

No notes for slide

Spark Summit 2014: Spark Streaming for Realtime Auctions

  1. 1. Spark Streaming for Realtime Auctions @russellcardullo Sharethrough
  2. 2. Agenda • Sharethrough? • Streaming use cases • How we use Spark • Next steps
  3. 3. Sharethrough vs
  4. 4. The Sharethrough Native Exchange
  5. 5. How can we use streaming data?
  6. 6. Use Cases Creative Optimization Spend Tracking Operational Monitoring $µ* = max { µk } k
  7. 7. Creative Optimization • Choose best performing variant • Short feedback cycle required impression: {! device: “iOS”,! geocode: “C967”,! pkey: “p193”,! …! } Variant 1 Variant 2 Variant 3 Click! Content Here Hello Friend ? ? ?
  8. 8. Spend Tracking • Spend on visible impressions and clicks • Actual spend happens asynchronously • Want to correct prediction for optimal serving Predicted Spend Actual Spend
  9. 9. Operational Monitoring • Detect issues with content served on third party sites • Use same logs as reporting Placement Click Rates P1 P5 P2 P3 P4 P6 P7 P8
  10. 10. We can directly measure business impact of using this data sooner
  11. 11. Why use Spark to build these features?
  12. 12. Why Spark? • Scala API • Supports batch and streaming • Active community support • Easily integrates into existing Hadoop ecosystem • But it doesn’t require Hadoop in order to run
  13. 13. How we’ve integrated Spark
  14. 14. Existing Data Pipeline web! server log file flume HDFS web! server log file flume web! server log file flume analytics! web! service database
  15. 15. Pipeline with Streaming web! server log file flume HDFS web! server log file flume web! server log file flume analytics! web! service database
  16. 16. Batch Streaming • “Real-Time” reporting • Low latency to use data • Only reliable as source • Low latency > correctness • Daily reporting • Billing / earnings • Anything with strict SLA • Correctness > low latency
  17. 17. Spark Job Abstractions
  18. 18. Job Organization nterSource Transform Sink Job
  19. 19. Sources ! case class BeaconLogLine(! timestamp: String,! uri: String,! beaconType: String,! pkey: String,! ckey: String! )! ! object BeaconLogLine {! ! def newDStream(ssc: StreamingContext, inputPath: String): DStream[BeaconLogLine] = {! ssc.textFileStream(inputPath).map { parseRawBeacon(_) }! }! ! def parseRawBeacon(b: String): BeaconLogLine = {! ...! }! }! case class! for pattern! matching generate! DStream encapsulate ! common! operations
  20. 20. Transformations ! ! def visibleByPlacement(source: DStream[BeaconLogLine]): DStream[(String, Long)] = {! source.! filter(data => {! data.uri == "/strbeacon" && data.beaconType == "visible"! }).! map(data => (data.pkey, 1L)).! reduceByKey(_ + _)! }! ! type safety! from! case class
  21. 21. Sinks ! ! class RedisSink @Inject()(store: RedisStore) {! ! def sink(result: DStream[(String, Long)]) = {! result.foreachRDD { rdd =>! rdd.foreach { element =>! val (key, value) = element! store.merge(key, value)! }! }! }! }! ! custom! sinks for! new stores
  22. 22. Jobs ! object ImpressionsForPlacements {! ! def run(config: Config, inputPath: String) {! val conf = new SparkConf().! setMaster(config.getString("master")).! setAppName("Impressions for Placement")! ! val sc = new SparkContext(conf)! val ssc = new StreamingContext(sc, Seconds(5))! ! val source = BeaconLogLine.newDStream(ssc, inputPath)! val visible = visibleByPlacement(source)! sink(visible)! ! ssc.start! ssc.awaitTermination! }! }! source transform sink
  23. 23. Advantages?
  24. 24. Code Reuse ! object PlacementVisibles {! …! val source = BeaconLogLine.newDStream(ssc, inputPath)! val visible = visibleByPlacement(source)! sink(visible)! …! }! ! …! ! object PlacementEngagements {! …! val source = BeaconLogLine.newDStream(ssc, inputPath)! val engagements = engagementsByPlacement(source)! sink(engagements)! …! } composable! jobs
  25. 25. Readability ! ssc.textFileStream(inputPath).! map { parseRawBeacon(_) }.! filter(data => {! data._2 == "/strbeacon" && data._3 == "visible"! }).! map(data => (data._4, 1L)).! reduceByKey(_ + _).! foreachRDD { rdd =>! rdd.foreach { element =>! store.merge(element._1, element._2)! }! }! ?
  26. 26. Readability ! ! val source = BeaconLogLine.newDStream(ssc, inputPath)! val visible = visibleByPlacement(source)! redis.sink(visible)! !
  27. 27. Testing def assertTransformation[T: Manifest, U: Manifest](! transformation: T => U,! input: Seq[T],! expectedOutput: Seq[U]! ): Unit = {! val ssc = new StreamingContext("local[1]", "Testing", Seconds(1))! val source = ssc.queueStream(new SynchronizedQueue[RDD[T]]())! val results = transformation(source)! ! var output = Array[U]()! results.foreachRDD { rdd => output = output ++ rdd.collect() }! ssc.start! rddQueue += ssc.sparkContext.makeRDD(input, 2)! Thread.sleep(jobCompletionWaitTimeMillis)! ssc.stop(true)! ! assert(output.toSet === expectedOutput.toSet)! }! function,! input,! expectation test
  28. 28. Testing ! ! test("#visibleByPlacement") {! ! val input = Seq(! "pkey=abcd, …",! "pkey=abcd, …",! "pkey=wxyz, …",! )! ! val expectedOutput = Seq( ("abcd",2),("wxyz", 1) )! ! assertTransformation(visibleByPlacement, input, expectedOutput)! }! ! use our! test helper
  29. 29. Other Learnings
  30. 30. Other Learnings • Keeping your driver program healthy is crucial • 24/7 operation and monitoring • Spark on Mesos? Use Marathon. • Pay attention to settings for spark.cores.max • Monitor data rate and increase as needed • Serialization on classes • Java • Kryo
  31. 31. What’s next?
  32. 32. Twitter Summingbird • Write-once, run anywhere • Supports: • Hadoop MapReduce • Storm • Spark (maybe?)
  33. 33. Amazon Kinesis web! server Kinesis web! server web! server other! applications mobile! device app! logs
  34. 34. Thanks!

×