Evolution ¡of ¡an ¡Apache ¡Spark ¡ Architecture ¡for ¡Processing ¡ Game ¡Data
Nick ¡Afshartous WB ¡Analytics ¡ Platform May ¡17th 2017
May ¡17th, ¡2017
Evolution of an Apache Spark Nick Afshartous Architecture - - PowerPoint PPT Presentation
Evolution of an Apache Spark Nick Afshartous Architecture for Processing WB Analytics Game Data Platform May 17 th 2017 May 17 th , 2017 About Me nafshartous@wbgames.com
May ¡17th, ¡2017
Partitions Producers Consumers (Key, ¡Value) ¡at ¡ Partition, ¡Offset
Topics
message ¡to ¡partition
from ¡earliest, ¡latest, ¡or ¡from ¡ specific ¡offsets
JSON ¡
Hadoop ¡Map ¡Reduce
Vertica
Avro
Spark ¡Streaming
Redshift
Avro ¡Data
Event ¡ Ingestion
Schema ¡ Hash Avro ¡ Schema
Schema ¡ Registry
Schema ¡ Hash
Returned ¡hash ¡based ¡on ¡schema ¡fields/types Registration ¡triggers ¡Redshift ¡table ¡create/alter ¡ statements
Event ¡ Ingestion ¡ Service HTTPS
Event ¡Avro Schema ¡Hash Micro ¡Batch ¡
Spark ¡ Streaming
S3
Data ¡flow Invocation Kafka Data ¡topic Run ¡ COPY
Table person.txt 1|john ¡doe 2|sarah ¡smith create table if not exists public.person ( id integer, name varchar )
copy public.person from 's3://mybucket/person.txt'
Event ¡ Ingestion ¡ Service HTTPS
Event ¡Avro Schema ¡Hash Micro ¡Batch ¡
Spark ¡ Streaming
S3
Data ¡flow Invocation Kafka Data ¡topic
Reactive ¡Kafka Akka Streams Akka
Actor Queue http://akka.io
Source Sink Flow
val s = Source(1 to 2) s.map(x => println("Hello: " + x)) .runWith(Sink.ignore)
Hello: ¡1 Hello: ¡2 Output Not ¡executed ¡by ¡ calling ¡thread Nothing ¡happens ¡until ¡ run ¡method ¡is ¡invoked
https://github.com/akka/reactive-‑kafka
implicit val system = ActorSystem("Example") val consumerSettings = ConsumerSettings(system, new ByteArrayDeserializer, new StringDeserializer) .withBootstrapServers("localhost:9092") .withGroupId("group1") Consumer.plainSource(consumerSettings, Subscriptions.topics("topic.name")) .map { message => println("message: " + message.value()) } .runWith(Sink.ignore) Creates ¡Source that ¡ streams ¡elements ¡ from ¡Kafka Deserializers for ¡key, ¡value Consumer ¡ group
Kafka ¡endpoint ¡ message has ¡type ¡ ConsumerRecord (Kafka ¡API)
S3
Copy ¡Tasks Data ¡flow Invocation Game ¡ Clients ¡ Event ¡ Ingestion ¡ Service HTTPS
Event ¡ Avro
Spark ¡ Streaming Redshift ¡Loader Kafka Data ¡topic COPY ¡topic
Consumer.Control.shutdown()
Copy ¡table ¡A ¡ Copy ¡table ¡B ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ A, ¡B ¡locked Copy ¡table ¡B ¡ ¡ Copy ¡table ¡A ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ Wait ¡for ¡lock Deadlock
Transaction ¡1 Transaction ¡2 Time
import ¡org.apache.kafka.clients.consumer.ConsumerRecord import ¡akka.actor.{ActorRef, ¡ActorSystem} import ¡akka.stream.ActorMaterializer import ¡akka.stream.scaladsl.{Keep, ¡Sink, ¡Source} import ¡scala.util.{Success, ¡Failure} import ¡scala.concurrent.ExecutionContext.Implicits.global import ¡akka.kafka.ConsumerSettings import ¡org.apache.kafka.clients.consumer.ConsumerConfig import ¡org.apache.kafka.common.serialization.{StringDeserializer, ¡ByteArrayDeserializer} import ¡akka.kafka.Subscriptions import ¡akka.kafka.ConsumerMessage.{CommittableOffsetBatch, ¡CommittableMessage} import ¡akka.kafka.scaladsl.Consumer