Upload
knoldus-software-llp
View
111
Download
2
Embed Size (px)
DESCRIPTION
Introduction to Akka 2.0 and how we used Akka to to build a massively scalable application which is processing north of 50 million feeds.
Citation preview
Achieving massive scalability with Akka
Vikas Hazrati @
2
about
CTO at Knoldus Software
CoFounder at MyCellWasStolen.com
Community Editor at InfoQ.com
Dabbling with Scala – last 40 months
Enterprise grade implementations on Scala – 18 months
akka
A actorbased concurrency framework
Provides solutions for non blocking concurrency
Written in Scala, also works in Java
Open source
Now at version 2.0.2
Lead developer and founder: Jonas Boner
JRockit, AspectWerkz, AspectJ, Terracotta
what?
Platform for next generation, event driven, scalable and fault tolerant
architectures on the JVM.
why akka
simpler concurrency
event driven
scale up or scale out
fault tolerance
location transparency / remoting
scala and java api
how to use
As a jar in your WEBINF/lib
As a microkernel and drop your application in it
aha actors
messagePassing Concurrency
share NOTHING
isolated lightweight processes
communicates through messages
asynchronous and nonblocking
actorsdefined in the 1973 paper by Carl Hewitt
popularized by Erlang
alleviates the dev
from explicit locking
and thread management
easy to write concurrent and parallel systems
actors like objects BUT dont share state
actor system
envision breaking task into subtasks
actor system
each actor has one supervisor
Nice co workers, dont bother others
Do not block (external interaction)
Do not pass mutable objects
mutability, aah!scala> var sum =0sum: Int = 0
scala> val list = (1 to 1000).toList.par
scala> list.foreach(sum += _); sumres7: Int = 452474
scala> var sum =0sum: Int = 0
scala> list.foreach(sum += _); sumres8: Int = 497761
scala> var sum =0sum: Int = 0
scala> list.foreach(sum += _); sumres9: Int = 422508
actor
Actor
state
behavior
mail-box
children
supervise strategy
actor reference
freely passed
Location transparency
hidesstate
defining an actor
import akka.actor.{ Actor, Props }
class MyFirstActor extends Actor { def receive = { case msg => println("Hello!!") }}
create
import akka.actor.{ ActorSystem, Props }
val system = ActorSystem("firstApp")val myFirstActor = system.actorOf(Props[MyFirstActor])
MyFirstActor is an ActorRefCreate a top level actor
messages
! fire and forget
? ask – send and receive future
import akka.pattern.ask
implicit val timeout = Timeout(50000 milliseconds)
val future = myActor ? "hello"
Await.result(future, timeout.duration).asInstanceOf[Int]
myFirstActor ! “Hello”
reply
import akka.actor.Actor
class LongWorkingActor extends Actor { def receive = { case number: Int => sender ! (“Hi I received ” + number) }}
stop
system stop myFirstActor
routers
RoundRobin
Random
SmallestMailBox
BroadCast
...
val router = system.actorOf(Props[RouterWorkerActor].withRouter(RoundRobinRouter(nrOfInstances = 5)))
fault tolerance
let it crash
linked set of actors
all for one
one for one
supervisor strategy
class Supervisor extends Actor { override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) { case _: ArithmeticException => Resume case _: NullPointerException => Restart case _: IllegalArgumentException => Stop case _: Exception => Escalate }}
supervisor hierarchies
other concepts
Remote Actors
Akka STM
Akka Serialization
Persistence
problem statement
considerations
hmm...
STM – X
Serialization – X
Persistence – X
Remoting – ?/X
dispatchers
Event based dispatcher
PinnedDispatcher
BalancingDispatcher
Calling ThreadDispatcher
ala carte'
used in ...
more information
http://blog.knoldus.com/tag/akka/
http://akka.io
https://github.com/knoldus/AkkaKnolX
Everyone ! “Thanks”