SlideShare una empresa de Scribd logo
1 de 27
Suraj Atreya
Data Engineer
Glassbeam

Introduction
to
What we do
●

Machine log analytics company

●

Scala shop

●

Akka is used extensively

●

We are a bunch of passionate hackers who solve
concurrency, race conditions, memory overcommit issues

●

We process 1 TB worth of logs everyday

●

Akka, Cassandra, Solr, H2
Akka
●

Pronounced as 'Ahkka', part of Typesafe stack

●

Framework for:
–

Distributed

–

Asynchronous

–

Concurrent

–

Non-blocking

–

Event driven

–

Message passing
Actor Model
Based on Carl Hewitt 1973 paper
Actor Model
●

3 axioms – When an Actor receives a message
it can:
–

Create new Actors

–

Send messages to other Actors

–

Decide how it should handle the next message it
receives
Akka Actors
●
●

High level abstraction
No need to worry about thread locking and
synchronization

●

Fault tolerant

●

Location transparent

●

Support for Java and Scala APIs
Create Actor
case class HelloWorld(who: String)
class HelloWorldActor extends Actor with ActorLogging {
def receive = {
case HelloWorld(person) ⇒ log.info("Hello " + person)
}
}
object TestHelloWorld {
def main(args: Array[String]): Unit = {
val system = ActorSystem("MySystem")
val helloWorldActorRef = system.actorOf(Props[HelloWorldActor], name = "hello")
helloWorldActorRef ! HelloWorld("Mr.X")
}
}
Create Actor
case class HelloWorld(who: String)
class HelloWorldActor extends Actor with ActorLogging {
def receive = {
case HelloWorld(person) ⇒ log.info("Hello " + person)
}
}

Create an
object TestHelloWorld {Actor System
def main(args: Array[String]): Unit = {
val system = ActorSystem("MySystem")
val helloWorldActorRef = system.actorOf(Props[HelloWorldActor], name = "hello")
helloWorldActorRef ! HelloWorld("Mr.X")
}
}
Create Actor
case class HelloWorld(who: String)
class HelloWorldActor extends Actor with ActorLogging {
def receive = {
case HelloWorld(person) ⇒ log.info("Hello " + person)
}
}

Create an
object TestHelloWorld {Actor System

Create an Actor

def main(args: Array[String]): Unit = {
val system = ActorSystem("MySystem")
val helloWorldActorRef = system.actorOf(Props[HelloWorldActor], name = "hello")
helloWorldActorRef ! HelloWorld("Mr.X")
}
}
Create Actor
case class HelloWorld(who: String)
class HelloWorldActor extends Actor with ActorLogging {
def receive = {
case HelloWorld(person) ⇒ log.info("Hello " + person)
}
}

Create an
object TestHelloWorld {Actor System

Create an Actor

def main(args: Array[String]): Unit = {
Send message
val system = ActorSystem("MySystem")
val helloWorldActorRef = system.actorOf(Props[HelloWorldActor], name = "hello")
helloWorldActorRef ! HelloWorld("Mr.X")
}
}
Actor hierarchy
Guardian System Actor
Actor hierarchy
Guardian System Actor

HelloWorldActor

system.actorOf(Props[HelloWorldActor], name = "hello")
Actor hierarchy
Guardian System Actor

HelloWorldActor

system.actorOf(Props[HelloWorldActor], name = "hello")
File system like name resolution
Guardian System Actor

/HelloWorldActor
HelloWorldActor

system.actorOf(Props[HelloWorldActor], name = "hello")

B
/HelloWorldActor/A

A

/HelloWorldActor/B
Under the hood

Actor mailbox

Actor 1

...

Actor 2

.......
m2 m1
Time elapsed
Message delivery
●

At most once semantics

●

Ordering of messages sender-receiver pair
Actors != Threads
●

General confusion that actors are threads. They
are not!

●

Actors are perceived as processes

●

Actors are assigned to threads by 'Dispatcher'

●

Many different kinds of dispatchers:
–

Default dispatcher

–

Pinned dispatcher

–

Balancing dispatcher (not covered in this talk)

–

CallingThreadDispatcher (not covered in this talk)
Routers
●

●

Router is an actor that first receives messages and
routes them to other actors
Can be configured to be any one of the routers:
–

Round Robin

–

Random Router

–

Smallest Mailbox

–

Broadcast Router

–

Scatter Gather First Completed

–

Consistent Hashing
Create a router
val router1 =
system.actorOf(Props[ExampleActor1]
.withRouter(RoundRobinRouter(nrOfInstances = 5)))
Sending messages to router
router1 ! MyMsg
RoundRobin router
Routee 1

Routee 2
Router

router1 ! MyMsg

Routee 3

Routee 4

Routee 5
RoundRobin router
Routee 1

Routee 2
Router

router1 ! MyMsg

Routee 3

Routee 4

Routee 5
SmallestMailBox router
Routee 1

Routee 2
Router

router1 ! MyMsg

Routee 3

Routee 4

Routee 5
Pinned dispatcher demo
Pinned dispatcher
.......................
.......................
.......................
.......................
.......................
.......................
.......................
.......................
.......................
.......................
......................

.......................
.......................
.......................
.......................
.......................
.......................
.......................
.......................
.......................
.......................
.......................
.......................

Log file

Chuncked file

Chunk 1

Chunk 2

Chunk 3

Pinned dispatcher

Chunk 4
Best practices
●

●

●

●

Do not block inside an Actor Eg: a big while
loop, network socket etc
Prefer immutable messages between actors
instead of mutable objects
Do not create too many “ActorSystem”s.
Instead create as many actors as you want.
Do not send behaviour as messages. Might
accidently share state.
EOF

Más contenido relacionado

La actualidad más candente

Optimizing Tcl Bytecode
Optimizing Tcl BytecodeOptimizing Tcl Bytecode
Optimizing Tcl Bytecode
Donal Fellows
 

La actualidad más candente (20)

Scala for Java programmers
Scala for Java programmersScala for Java programmers
Scala for Java programmers
 
Clojure Intro
Clojure IntroClojure Intro
Clojure Intro
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
JS OO and Closures
JS OO and ClosuresJS OO and Closures
JS OO and Closures
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?
 
Spark Schema For Free with David Szakallas
 Spark Schema For Free with David Szakallas Spark Schema For Free with David Szakallas
Spark Schema For Free with David Szakallas
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
JavaOne 2013 - Clojure for Java Developers
JavaOne 2013 - Clojure for Java DevelopersJavaOne 2013 - Clojure for Java Developers
JavaOne 2013 - Clojure for Java Developers
 
Making an Object System with Tcl 8.5
Making an Object System with Tcl 8.5Making an Object System with Tcl 8.5
Making an Object System with Tcl 8.5
 
Optimizing Tcl Bytecode
Optimizing Tcl BytecodeOptimizing Tcl Bytecode
Optimizing Tcl Bytecode
 
Scala - en bedre Java?
Scala - en bedre Java?Scala - en bedre Java?
Scala - en bedre Java?
 
R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011
 
Hw09 Hadoop + Clojure
Hw09   Hadoop + ClojureHw09   Hadoop + Clojure
Hw09 Hadoop + Clojure
 
Clojure, Plain and Simple
Clojure, Plain and SimpleClojure, Plain and Simple
Clojure, Plain and Simple
 
GPars (Groovy Parallel Systems)
GPars (Groovy Parallel Systems)GPars (Groovy Parallel Systems)
GPars (Groovy Parallel Systems)
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 
JDBC Core Concept
JDBC Core ConceptJDBC Core Concept
JDBC Core Concept
 

Similar a Meetup slides

Scaling Web Apps with Akka
Scaling Web Apps with AkkaScaling Web Apps with Akka
Scaling Web Apps with Akka
Maciej Matyjas
 
Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_group
Skills Matter
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
Kat Roque
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
Vaclav Pech
 

Similar a Meetup slides (20)

Akka lsug skills matter
Akka lsug skills matterAkka lsug skills matter
Akka lsug skills matter
 
Scaling Web Apps with Akka
Scaling Web Apps with AkkaScaling Web Apps with Akka
Scaling Web Apps with Akka
 
Reactive Programming in .Net - actorbased computing with Akka.Net
Reactive Programming in .Net - actorbased computing with Akka.NetReactive Programming in .Net - actorbased computing with Akka.Net
Reactive Programming in .Net - actorbased computing with Akka.Net
 
Actor Model Akka Framework
Actor Model Akka FrameworkActor Model Akka Framework
Actor Model Akka Framework
 
Scale up your thinking
Scale up your thinkingScale up your thinking
Scale up your thinking
 
Activator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetupActivator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetup
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
 
Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_group
 
The Actor Model - Towards Better Concurrency
The Actor Model - Towards Better ConcurrencyThe Actor Model - Towards Better Concurrency
The Actor Model - Towards Better Concurrency
 
Developing a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and SprayDeveloping a Real-time Engine with Akka, Cassandra, and Spray
Developing a Real-time Engine with Akka, Cassandra, and Spray
 
SAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginnersSAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginners
 
Akka with Scala
Akka with ScalaAkka with Scala
Akka with Scala
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
Message-based communication patterns in distributed Akka applications
Message-based communication patterns in distributed Akka applicationsMessage-based communication patterns in distributed Akka applications
Message-based communication patterns in distributed Akka applications
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
Concurrency and scalability with akka
Concurrency and scalability  with akkaConcurrency and scalability  with akka
Concurrency and scalability with akka
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Reversing JavaScript
Reversing JavaScriptReversing JavaScript
Reversing JavaScript
 
Advanced akka features
Advanced akka featuresAdvanced akka features
Advanced akka features
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

Meetup slides