SlideShare una empresa de Scribd logo
1 de 38
Descargar para leer sin conexión
Akka in Production
Our Story
Evan Chan
PNWScala 2013

Saturday, October 19, 13
Who is this guy?
• Staff Engineer, Compute and Data Services, Ooyala
• Building multiple web-scale real-time systems on top of
C*, Kafka, Storm, etc.
• github.com/velvia
• Author of ScalaStorm, Scala DSL for Storm
• @evanfchan

2
Saturday, October 19, 13
WANT REACTIVE?
event-driven, scalable, resilient and responsive

3
Saturday, October 19, 13
SCALA AND AKKA
AT OOYALA

4
Saturday, October 19, 13
COMPANY OVERVIEW
Founded in 2007
Commercially launch in 2009
230+ employees in Silicon Valley, LA, NYC,
London, Paris, Tokyo, Sydney & Guadalajara
Global footprint, 200M unique users,
110+ countries, and more than 6,000 websites
Over 1 billion videos played per month
and 2 billion analytic events per day
25% of U.S. online viewers watch video
powered by Ooyala

CONFIDENTIAL—DO NOT DISTRIBUTE
Saturday, October 19, 13

5
How we started using Scala
• Ooyala was a mostly Ruby company - even MR jobs
• Lesson - don’t use Ruby for big data
• Started exploring Scala for real-time analytics and MR
• Realized a 1-2 orders of magnitude performance boost
from Scala
• Today use Scala, Akka with Storm, Spark, MR,
Cassandra, all new big data pipelines

Saturday, October 19, 13
Ingesting 2 Billion Events / Day
Consumer watches
video

Storm

Nginx

Raw Log
Feeder

Kafka

New Stuff

Saturday, October 19, 13
Livelogsd - Akka/Kafka file tailer
Current
File

Coordinator

Rotated
File

File
Reader
Actor

File
Reader
Actor
Kafka

Kafka Feeder

Saturday, October 19, 13

Rotated
File 2
Storm - with or without Akka?
Kafka
Spout

• Actors talking to each other within a
bolt for locality
• Don’t really need Actors in Storm

Bolt

• In production, found Storm too
complex to troubleshoot

Actor
Actor

Saturday, October 19, 13

• It’s 2am - what should I restart?
Supervisor? Nimbus? ZK?
Akka Cluster-based Pipeline
Kafka
Consumer

Kafka
Consumer

Kafka
Consumer

Kafka
Consumer

Kafka
Consumer

Spray
endpoint

Spray
endpoint

Spray
endpoint

Spray
endpoint

Spray
endpoint

Cluster
Router

Cluster
Router

Cluster
Router

Cluster
Router

Cluster
Router

Processing
Actors

Processing
Actors

Processing
Actors

Processing
Actors

Processing
Actors

Saturday, October 19, 13
Lessons Learned
• Still too complex -- would we want to get paged for this
system?
• Akka cluster in 2.1 was not ready for production (newer
2.2.x version is stable)
• Mixture of actors and futures for HTTP requests
became hard to grok
• Actors were much easier for most developers to
understand

Saturday, October 19, 13
Simplified Ingestion Pipeline
Kafka
Partition
1

Kafka
SimpleConsumer

Kafka
Partition
2

Kafka
SimpleConsumer

• Kafka used to partition
messages
• Single process - super
simple!
• No distribution of data

Converter Actor

Converter Actor

Cassandra Writer
Actor

Cassandra Writer
Actor

Saturday, October 19, 13

• Linear actor pipeline very easy to understand
STACKABLE ACTOR TRAITS

13
Saturday, October 19, 13
Why Stackable Traits?
• Keep adding monitoring, logging, metrics, tracing code
gets pretty ugly and repetitive
• We want some standard behavior around actors -- but
we need to wrap the actor Receive block:
class someActor extends Actor {
def wrappedReceive: Receive = {
case x => blah
}
def receive = {
case x =>
println(“Do something before...”)
wrappedReceive(x)
println(“Do something after...”)
}
}

Saturday, October 19, 13
Start with a base trait...

trait
/**
*
*/
def

ActorStack extends Actor {
Actor classes should implement this partialFunction for standard
actor message handling
wrappedReceive: Receive

/** Stackable traits should override and call super.receive(x) for
* stacking functionality
*/
def receive: Receive = {
case x => if (wrappedReceive.isDefinedAt(x)) wrappedReceive(x) else unhandled(x)
}
}

Saturday, October 19, 13
Instrumenting Traits...
trait Instrument1 extends ActorStack {
override def receive: Receive = {
case x =>
println("Do something before...")
super.receive(x)
println("Do something after...")
}
}

trait Instrument2 extends ActorStack {
override def receive: Receive = {
case x =>
println("Antes...")
super.receive(x)
println("Despues...")
}
}

Saturday, October 19, 13
Now just mix the Traits in....
• Traits add instrumentation; Actors stay clean!
• Order of mixing in traits matter
class DummyActor extends Actor with Instrument1 with Instrument2 {
def wrappedReceive = {
case "something" => println("Got something")
case x => println("Got something else: " + x)
}
}

Antes...
Do something before...
Got something
Do something after...
Despues...

Saturday, October 19, 13
PRODUCTIONIZING AKKA

18
Saturday, October 19, 13
Our Akka Stack
• Spray - high performance HTTP
• SLF4J / Logback
• Yammer Metrics
• spray-json
• Akka 2.x
• Scala 2.9 / 2.10

Saturday, October 19, 13
On distributed systems:
“The only thing that matters is
Visibility”

20
Saturday, October 19, 13
Using Logback with Akka
• Pretty easy setup
• Include the Logback jar
• In your application.conf:
event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]

• Use a custom logging trait, not ActorLogging
• ActorLogging does not allow adjustable logging levels
• Want the Actor path in your messages?
•

Saturday, October 19, 13

org.slf4j.MDC.put(“actorPath”, self.path.toString)
Using Logback with Akka

trait Slf4jLogging extends Actor with ActorStack {
val logger = LoggerFactory.getLogger(getClass)
private[this] val myPath = self.path.toString
logger.info("Starting actor " + getClass.getName)
override def receive: Receive = {
case x =>
org.slf4j.MDC.put("akkaSource", myPath)
super.receive(x)
}
}

Saturday, October 19, 13
Akka Performance Metrics
• We define a trait that adds two metrics for every actor:
• frequency of messages handled (1min, 5min, 15min
moving averages)
• time spent in receive block
• All metrics exposed via a Spray route /metricz
• Daemon polls /metricz and sends to metrics service
• Would like: mailbox size, but this is hard

Saturday, October 19, 13
Akka Performance Metrics

trait ActorMetrics extends ActorStack {
// Timer includes a histogram of wrappedReceive() duration as well as moving avg of rate
of invocation
val metricReceiveTimer = Metrics.newTimer(getClass, "message-handler",
TimeUnit.MILLISECONDS, TimeUnit.SECONDS)
override def receive: Receive = {
case x =>
val context = metricReceiveTimer.time()
try {
super.receive(x)
} finally {
context.stop()
}
}
}

Saturday, October 19, 13
Performance Metrics (cont’d)

Saturday, October 19, 13
Performance Metrics (cont’d)

Saturday, October 19, 13
Flow control
• By default, actor mailboxes are unbounded
• Using bounded mailboxes
• When mailbox is full, messages go to DeadLetters
• mailbox-push-timeout-time: how long to wait
when mailbox is full
• Doesn’t work for distributed Akka systems!
• Real flow control: pull, push with acks, etc.
• Works anywhere, but more work

Saturday, October 19, 13
Flow control (Cont’d)
• A working flow control system causes the rate of all
actor components to be in sync.
• Witness this message flow rate graph of the start of
event processing:

Saturday, October 19, 13
VisualVM and Akka
• Bounded mailboxes = time spent enqueueing msgs

Saturday, October 19, 13
VisualVM and Akka

• My dream: a VisualVM plugin to visualize Actor
utilization across threads

Saturday, October 19, 13
Tracing Akka Message Flows
• Stack trace is very useful for traditional apps, but for
Akka apps, you get this:
at akka.dispatch.Future$$anon$3.liftedTree1$1(Future.scala:195) ~[akka-actor-2.0.5.jar:2.0.5]
at akka.dispatch.Future$$anon$3.run(Future.scala:194) ~[akka-actor-2.0.5.jar:2.0.5]
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:94) [akka-actor-2.0.5.jar:2.0.5]
at akka.jsr166y.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1381) [akka-actor-2.0.5.jar:2.0.5]
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259) [akka-actor-2.0.5.jar:2.0.5]
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) [akka-actor-2.0.5.jar:2.0.5]
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479) [akka-actor-2.0.5.jar:2.0.5]
at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) [akka-actor-2.0.5.jar:2.0.5]

• What if you could get an Akka message trace?
--> trAKKAr message trace <-akka://Ingest/user/Super --> akka://Ingest/user/K1: Initialize
akka://Ingest/user/K1 --> akka://Ingest/user/Converter: Data

Saturday, October 19, 13
Tracing Akka Message Flows

Saturday, October 19, 13
Tracing Akka Message Flows
trait TrakkarExtractor extends TrakkarBase with ActorStack {
import TrakkarUtils._
val messageIdExtractor: MessageIdExtractor = randomExtractor
override def receive: Receive = {
case x =>
lastMsgId = (messageIdExtractor orElse randomExtractor)(x)
Collector.sendEdge(sender, self, lastMsgId, x)
super.receive(x)
}
}

• Trait sends an Edge(source, dest, messageInfo) to a
local Collector actor
• Aggregate edges across nodes, graph and profit!

Saturday, October 19, 13
Good Akka development practices
• Don't put things that can fail into Actor constructor
• Default supervision strategy stops an Actor which
cannot initialize itself
• Instead use an Initialize message
• Put your messages in the Actor’s companion object
• Namespacing is nice

Saturday, October 19, 13
PUTTING IT ALL TOGETHER

35
Saturday, October 19, 13
Akka Visibility, Minimal Footprint

trait InstrumentedActor extends Slf4jLogging with ActorMetrics with TrakkarExtractor
object MyWorkerActor {
case object Initialize
case class DoSomeWork(desc: String)
}
class MyWorkerActor extends InstrumentedActor {
def wrappedReceive = {
case Initialize =>
case DoSomeWork(desc) =>
}
}

Saturday, October 19, 13
Next Steps

• Name?
• Open source?
• Talk to me if you’re interested in contributing

Saturday, October 19, 13
THANK YOU
And YES, We’re HIRING!!
ooyala.com/careers

Saturday, October 19, 13

Más contenido relacionado

Más de Evan Chan

Designing Stateful Apps for Cloud and Kubernetes
Designing Stateful Apps for Cloud and KubernetesDesigning Stateful Apps for Cloud and Kubernetes
Designing Stateful Apps for Cloud and KubernetesEvan Chan
 
Histograms at scale - Monitorama 2019
Histograms at scale - Monitorama 2019Histograms at scale - Monitorama 2019
Histograms at scale - Monitorama 2019Evan Chan
 
FiloDB: Reactive, Real-Time, In-Memory Time Series at Scale
FiloDB: Reactive, Real-Time, In-Memory Time Series at ScaleFiloDB: Reactive, Real-Time, In-Memory Time Series at Scale
FiloDB: Reactive, Real-Time, In-Memory Time Series at ScaleEvan Chan
 
Building a High-Performance Database with Scala, Akka, and Spark
Building a High-Performance Database with Scala, Akka, and SparkBuilding a High-Performance Database with Scala, Akka, and Spark
Building a High-Performance Database with Scala, Akka, and SparkEvan Chan
 
700 Updatable Queries Per Second: Spark as a Real-Time Web Service
700 Updatable Queries Per Second: Spark as a Real-Time Web Service700 Updatable Queries Per Second: Spark as a Real-Time Web Service
700 Updatable Queries Per Second: Spark as a Real-Time Web ServiceEvan Chan
 
Building Scalable Data Pipelines - 2016 DataPalooza Seattle
Building Scalable Data Pipelines - 2016 DataPalooza SeattleBuilding Scalable Data Pipelines - 2016 DataPalooza Seattle
Building Scalable Data Pipelines - 2016 DataPalooza SeattleEvan Chan
 
FiloDB - Breakthrough OLAP Performance with Cassandra and Spark
FiloDB - Breakthrough OLAP Performance with Cassandra and SparkFiloDB - Breakthrough OLAP Performance with Cassandra and Spark
FiloDB - Breakthrough OLAP Performance with Cassandra and SparkEvan Chan
 
Breakthrough OLAP performance with Cassandra and Spark
Breakthrough OLAP performance with Cassandra and SparkBreakthrough OLAP performance with Cassandra and Spark
Breakthrough OLAP performance with Cassandra and SparkEvan Chan
 
Productionizing Spark and the Spark Job Server
Productionizing Spark and the Spark Job ServerProductionizing Spark and the Spark Job Server
Productionizing Spark and the Spark Job ServerEvan Chan
 
MIT lecture - Socrata Open Data Architecture
MIT lecture - Socrata Open Data ArchitectureMIT lecture - Socrata Open Data Architecture
MIT lecture - Socrata Open Data ArchitectureEvan Chan
 
OLAP with Cassandra and Spark
OLAP with Cassandra and SparkOLAP with Cassandra and Spark
OLAP with Cassandra and SparkEvan Chan
 
Spark Summit 2014: Spark Job Server Talk
Spark Summit 2014:  Spark Job Server TalkSpark Summit 2014:  Spark Job Server Talk
Spark Summit 2014: Spark Job Server TalkEvan Chan
 
Spark Job Server and Spark as a Query Engine (Spark Meetup 5/14)
Spark Job Server and Spark as a Query Engine (Spark Meetup 5/14)Spark Job Server and Spark as a Query Engine (Spark Meetup 5/14)
Spark Job Server and Spark as a Query Engine (Spark Meetup 5/14)Evan Chan
 
Cassandra Day 2014: Interactive Analytics with Cassandra and Spark
Cassandra Day 2014: Interactive Analytics with Cassandra and SparkCassandra Day 2014: Interactive Analytics with Cassandra and Spark
Cassandra Day 2014: Interactive Analytics with Cassandra and SparkEvan Chan
 
Real-time Analytics with Cassandra, Spark, and Shark
Real-time Analytics with Cassandra, Spark, and SharkReal-time Analytics with Cassandra, Spark, and Shark
Real-time Analytics with Cassandra, Spark, and SharkEvan Chan
 

Más de Evan Chan (15)

Designing Stateful Apps for Cloud and Kubernetes
Designing Stateful Apps for Cloud and KubernetesDesigning Stateful Apps for Cloud and Kubernetes
Designing Stateful Apps for Cloud and Kubernetes
 
Histograms at scale - Monitorama 2019
Histograms at scale - Monitorama 2019Histograms at scale - Monitorama 2019
Histograms at scale - Monitorama 2019
 
FiloDB: Reactive, Real-Time, In-Memory Time Series at Scale
FiloDB: Reactive, Real-Time, In-Memory Time Series at ScaleFiloDB: Reactive, Real-Time, In-Memory Time Series at Scale
FiloDB: Reactive, Real-Time, In-Memory Time Series at Scale
 
Building a High-Performance Database with Scala, Akka, and Spark
Building a High-Performance Database with Scala, Akka, and SparkBuilding a High-Performance Database with Scala, Akka, and Spark
Building a High-Performance Database with Scala, Akka, and Spark
 
700 Updatable Queries Per Second: Spark as a Real-Time Web Service
700 Updatable Queries Per Second: Spark as a Real-Time Web Service700 Updatable Queries Per Second: Spark as a Real-Time Web Service
700 Updatable Queries Per Second: Spark as a Real-Time Web Service
 
Building Scalable Data Pipelines - 2016 DataPalooza Seattle
Building Scalable Data Pipelines - 2016 DataPalooza SeattleBuilding Scalable Data Pipelines - 2016 DataPalooza Seattle
Building Scalable Data Pipelines - 2016 DataPalooza Seattle
 
FiloDB - Breakthrough OLAP Performance with Cassandra and Spark
FiloDB - Breakthrough OLAP Performance with Cassandra and SparkFiloDB - Breakthrough OLAP Performance with Cassandra and Spark
FiloDB - Breakthrough OLAP Performance with Cassandra and Spark
 
Breakthrough OLAP performance with Cassandra and Spark
Breakthrough OLAP performance with Cassandra and SparkBreakthrough OLAP performance with Cassandra and Spark
Breakthrough OLAP performance with Cassandra and Spark
 
Productionizing Spark and the Spark Job Server
Productionizing Spark and the Spark Job ServerProductionizing Spark and the Spark Job Server
Productionizing Spark and the Spark Job Server
 
MIT lecture - Socrata Open Data Architecture
MIT lecture - Socrata Open Data ArchitectureMIT lecture - Socrata Open Data Architecture
MIT lecture - Socrata Open Data Architecture
 
OLAP with Cassandra and Spark
OLAP with Cassandra and SparkOLAP with Cassandra and Spark
OLAP with Cassandra and Spark
 
Spark Summit 2014: Spark Job Server Talk
Spark Summit 2014:  Spark Job Server TalkSpark Summit 2014:  Spark Job Server Talk
Spark Summit 2014: Spark Job Server Talk
 
Spark Job Server and Spark as a Query Engine (Spark Meetup 5/14)
Spark Job Server and Spark as a Query Engine (Spark Meetup 5/14)Spark Job Server and Spark as a Query Engine (Spark Meetup 5/14)
Spark Job Server and Spark as a Query Engine (Spark Meetup 5/14)
 
Cassandra Day 2014: Interactive Analytics with Cassandra and Spark
Cassandra Day 2014: Interactive Analytics with Cassandra and SparkCassandra Day 2014: Interactive Analytics with Cassandra and Spark
Cassandra Day 2014: Interactive Analytics with Cassandra and Spark
 
Real-time Analytics with Cassandra, Spark, and Shark
Real-time Analytics with Cassandra, Spark, and SharkReal-time Analytics with Cassandra, Spark, and Shark
Real-time Analytics with Cassandra, Spark, and Shark
 

Último

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 

Último (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 

Akka in Production: Our Story

  • 1. Akka in Production Our Story Evan Chan PNWScala 2013 Saturday, October 19, 13
  • 2. Who is this guy? • Staff Engineer, Compute and Data Services, Ooyala • Building multiple web-scale real-time systems on top of C*, Kafka, Storm, etc. • github.com/velvia • Author of ScalaStorm, Scala DSL for Storm • @evanfchan 2 Saturday, October 19, 13
  • 3. WANT REACTIVE? event-driven, scalable, resilient and responsive 3 Saturday, October 19, 13
  • 4. SCALA AND AKKA AT OOYALA 4 Saturday, October 19, 13
  • 5. COMPANY OVERVIEW Founded in 2007 Commercially launch in 2009 230+ employees in Silicon Valley, LA, NYC, London, Paris, Tokyo, Sydney & Guadalajara Global footprint, 200M unique users, 110+ countries, and more than 6,000 websites Over 1 billion videos played per month and 2 billion analytic events per day 25% of U.S. online viewers watch video powered by Ooyala CONFIDENTIAL—DO NOT DISTRIBUTE Saturday, October 19, 13 5
  • 6. How we started using Scala • Ooyala was a mostly Ruby company - even MR jobs • Lesson - don’t use Ruby for big data • Started exploring Scala for real-time analytics and MR • Realized a 1-2 orders of magnitude performance boost from Scala • Today use Scala, Akka with Storm, Spark, MR, Cassandra, all new big data pipelines Saturday, October 19, 13
  • 7. Ingesting 2 Billion Events / Day Consumer watches video Storm Nginx Raw Log Feeder Kafka New Stuff Saturday, October 19, 13
  • 8. Livelogsd - Akka/Kafka file tailer Current File Coordinator Rotated File File Reader Actor File Reader Actor Kafka Kafka Feeder Saturday, October 19, 13 Rotated File 2
  • 9. Storm - with or without Akka? Kafka Spout • Actors talking to each other within a bolt for locality • Don’t really need Actors in Storm Bolt • In production, found Storm too complex to troubleshoot Actor Actor Saturday, October 19, 13 • It’s 2am - what should I restart? Supervisor? Nimbus? ZK?
  • 11. Lessons Learned • Still too complex -- would we want to get paged for this system? • Akka cluster in 2.1 was not ready for production (newer 2.2.x version is stable) • Mixture of actors and futures for HTTP requests became hard to grok • Actors were much easier for most developers to understand Saturday, October 19, 13
  • 12. Simplified Ingestion Pipeline Kafka Partition 1 Kafka SimpleConsumer Kafka Partition 2 Kafka SimpleConsumer • Kafka used to partition messages • Single process - super simple! • No distribution of data Converter Actor Converter Actor Cassandra Writer Actor Cassandra Writer Actor Saturday, October 19, 13 • Linear actor pipeline very easy to understand
  • 14. Why Stackable Traits? • Keep adding monitoring, logging, metrics, tracing code gets pretty ugly and repetitive • We want some standard behavior around actors -- but we need to wrap the actor Receive block: class someActor extends Actor { def wrappedReceive: Receive = { case x => blah } def receive = { case x => println(“Do something before...”) wrappedReceive(x) println(“Do something after...”) } } Saturday, October 19, 13
  • 15. Start with a base trait... trait /** * */ def ActorStack extends Actor { Actor classes should implement this partialFunction for standard actor message handling wrappedReceive: Receive /** Stackable traits should override and call super.receive(x) for * stacking functionality */ def receive: Receive = { case x => if (wrappedReceive.isDefinedAt(x)) wrappedReceive(x) else unhandled(x) } } Saturday, October 19, 13
  • 16. Instrumenting Traits... trait Instrument1 extends ActorStack { override def receive: Receive = { case x => println("Do something before...") super.receive(x) println("Do something after...") } } trait Instrument2 extends ActorStack { override def receive: Receive = { case x => println("Antes...") super.receive(x) println("Despues...") } } Saturday, October 19, 13
  • 17. Now just mix the Traits in.... • Traits add instrumentation; Actors stay clean! • Order of mixing in traits matter class DummyActor extends Actor with Instrument1 with Instrument2 { def wrappedReceive = { case "something" => println("Got something") case x => println("Got something else: " + x) } } Antes... Do something before... Got something Do something after... Despues... Saturday, October 19, 13
  • 19. Our Akka Stack • Spray - high performance HTTP • SLF4J / Logback • Yammer Metrics • spray-json • Akka 2.x • Scala 2.9 / 2.10 Saturday, October 19, 13
  • 20. On distributed systems: “The only thing that matters is Visibility” 20 Saturday, October 19, 13
  • 21. Using Logback with Akka • Pretty easy setup • Include the Logback jar • In your application.conf: event-handlers = ["akka.event.slf4j.Slf4jEventHandler"] • Use a custom logging trait, not ActorLogging • ActorLogging does not allow adjustable logging levels • Want the Actor path in your messages? • Saturday, October 19, 13 org.slf4j.MDC.put(“actorPath”, self.path.toString)
  • 22. Using Logback with Akka trait Slf4jLogging extends Actor with ActorStack { val logger = LoggerFactory.getLogger(getClass) private[this] val myPath = self.path.toString logger.info("Starting actor " + getClass.getName) override def receive: Receive = { case x => org.slf4j.MDC.put("akkaSource", myPath) super.receive(x) } } Saturday, October 19, 13
  • 23. Akka Performance Metrics • We define a trait that adds two metrics for every actor: • frequency of messages handled (1min, 5min, 15min moving averages) • time spent in receive block • All metrics exposed via a Spray route /metricz • Daemon polls /metricz and sends to metrics service • Would like: mailbox size, but this is hard Saturday, October 19, 13
  • 24. Akka Performance Metrics trait ActorMetrics extends ActorStack { // Timer includes a histogram of wrappedReceive() duration as well as moving avg of rate of invocation val metricReceiveTimer = Metrics.newTimer(getClass, "message-handler", TimeUnit.MILLISECONDS, TimeUnit.SECONDS) override def receive: Receive = { case x => val context = metricReceiveTimer.time() try { super.receive(x) } finally { context.stop() } } } Saturday, October 19, 13
  • 27. Flow control • By default, actor mailboxes are unbounded • Using bounded mailboxes • When mailbox is full, messages go to DeadLetters • mailbox-push-timeout-time: how long to wait when mailbox is full • Doesn’t work for distributed Akka systems! • Real flow control: pull, push with acks, etc. • Works anywhere, but more work Saturday, October 19, 13
  • 28. Flow control (Cont’d) • A working flow control system causes the rate of all actor components to be in sync. • Witness this message flow rate graph of the start of event processing: Saturday, October 19, 13
  • 29. VisualVM and Akka • Bounded mailboxes = time spent enqueueing msgs Saturday, October 19, 13
  • 30. VisualVM and Akka • My dream: a VisualVM plugin to visualize Actor utilization across threads Saturday, October 19, 13
  • 31. Tracing Akka Message Flows • Stack trace is very useful for traditional apps, but for Akka apps, you get this: at akka.dispatch.Future$$anon$3.liftedTree1$1(Future.scala:195) ~[akka-actor-2.0.5.jar:2.0.5] at akka.dispatch.Future$$anon$3.run(Future.scala:194) ~[akka-actor-2.0.5.jar:2.0.5] at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:94) [akka-actor-2.0.5.jar:2.0.5] at akka.jsr166y.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1381) [akka-actor-2.0.5.jar:2.0.5] at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:259) [akka-actor-2.0.5.jar:2.0.5] at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) [akka-actor-2.0.5.jar:2.0.5] at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1479) [akka-actor-2.0.5.jar:2.0.5] at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104) [akka-actor-2.0.5.jar:2.0.5] • What if you could get an Akka message trace? --> trAKKAr message trace <-akka://Ingest/user/Super --> akka://Ingest/user/K1: Initialize akka://Ingest/user/K1 --> akka://Ingest/user/Converter: Data Saturday, October 19, 13
  • 32. Tracing Akka Message Flows Saturday, October 19, 13
  • 33. Tracing Akka Message Flows trait TrakkarExtractor extends TrakkarBase with ActorStack { import TrakkarUtils._ val messageIdExtractor: MessageIdExtractor = randomExtractor override def receive: Receive = { case x => lastMsgId = (messageIdExtractor orElse randomExtractor)(x) Collector.sendEdge(sender, self, lastMsgId, x) super.receive(x) } } • Trait sends an Edge(source, dest, messageInfo) to a local Collector actor • Aggregate edges across nodes, graph and profit! Saturday, October 19, 13
  • 34. Good Akka development practices • Don't put things that can fail into Actor constructor • Default supervision strategy stops an Actor which cannot initialize itself • Instead use an Initialize message • Put your messages in the Actor’s companion object • Namespacing is nice Saturday, October 19, 13
  • 35. PUTTING IT ALL TOGETHER 35 Saturday, October 19, 13
  • 36. Akka Visibility, Minimal Footprint trait InstrumentedActor extends Slf4jLogging with ActorMetrics with TrakkarExtractor object MyWorkerActor { case object Initialize case class DoSomeWork(desc: String) } class MyWorkerActor extends InstrumentedActor { def wrappedReceive = { case Initialize => case DoSomeWork(desc) => } } Saturday, October 19, 13
  • 37. Next Steps • Name? • Open source? • Talk to me if you’re interested in contributing Saturday, October 19, 13
  • 38. THANK YOU And YES, We’re HIRING!! ooyala.com/careers Saturday, October 19, 13