Building Massively Scalable application with Akka 2.0

2,132 views

Published on

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.

Published in: Technology, Education
  • Be the first to comment

Building Massively Scalable application with Akka 2.0

  1. 1. Achieving massive scalability with Akka Vikas Hazrati @
  2. 2. aboutCTO at Knoldus SoftwareCo­Founder at MyCellWasStolen.comCommunity Editor at InfoQ.comDabbling with Scala – last 40 monthsEnterprise grade implementations on Scala – 18 months  2
  3. 3. akkaA actor­based concurrency frameworkProvides solutions for non blocking  concurrencyWritten in Scala, also works in Java  Open source   Now at version 2.0.2Lead developer and founder: Jonas BonerJRockit, AspectWerkz, AspectJ, Terracotta
  4. 4. what?Platform for next generation, event  driven, scalable and fault tolerant  architectures on the JVM.
  5. 5. why akka simpler concurrency event driven scale up or scale out fault tolerancelocation transparency / remoting scala and java api
  6. 6. how to useAs a jar in your WEB­INF/libAs a microkernel and drop your application in it
  7. 7. aha actorsmessage­Passing Concurrency share NOTHINGisolated lightweight processes communicates through messagesasynchronous and non­blocking
  8. 8. actorsdefined in the 1973 paper by Carl Hewittpopularized by Erlangalleviates the dev from explicit lockingand thread managementeasy to write concurrent and parallel  systemsactors like objects BUT dont share state
  9. 9. actor systemenvision breaking task into subtasks
  10. 10. actor system each actor has one  supervisorNice co workers, dont bother othersDo not block (external interaction)Do not pass mutable objects
  11. 11. mutability, aah!scala> var sum =0sum: Int = 0scala> val list = (1 to 1000).toList.parscala> list.foreach(sum += _); sumres7: Int = 452474scala> var sum =0sum: Int = 0scala> list.foreach(sum += _); sumres8: Int = 497761scala> var sum =0sum: Int = 0scala> list.foreach(sum += _); sumres9: Int = 422508
  12. 12. actor state freely passed behaviorActor Location transparency mail-box children actor reference supervise strategy hides state
  13. 13. defining an actorimport akka.actor.{ Actor, Props }class MyFirstActor extends Actor {  def receive = {    case msg => println("Hello!!")  }}
  14. 14. createimport akka.actor.{ ActorSystem, Props }val system = ActorSystem("firstApp")val myFirstActor = system.actorOf(Props[MyFirstActor]) MyFirstActor is an ActorRef Create a top level actor
  15. 15. messages! fire and forget myFirstActor ! “Hello”? 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]
  16. 16. replyimport akka.actor.Actorclass LongWorkingActor extends Actor {  def receive = {    case number: Int =>      sender ! (“Hi I received ” + number)  }}
  17. 17. stopsystem stop myFirstActor
  18. 18. routers RoundRobin Random SmallestMailBox BroadCast ...val router = system.actorOf(Props[RouterWorkerActor].withRouter(RoundRobinRouter(nrOfInstances = 5)))
  19. 19. fault tolerancelet it crashlinked set of actors
  20. 20. all for one
  21. 21. one for one
  22. 22. supervisor strategyclass Supervisor extends Actor {  override val supervisorStrategy =  OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) {    case _: ArithmeticException => Resume    case _: NullPointerException => Restart    case _: IllegalArgumentException => Stop    case _: Exception => Escalate  }}
  23. 23. supervisor hierarchies
  24. 24. other concepts Akka STMRemote Actors Akka Serialization Persistence
  25. 25. problem statement
  26. 26. considerations
  27. 27. hmm... STM – XSerialization – XPersistence – XRemoting – ?/X
  28. 28. dispatchersEvent based dispatcherPinnedDispatcherBalancingDispatcherCalling ThreadDispatcher
  29. 29. ala carte
  30. 30. used in ...
  31. 31. more informationhttp://akka.iohttp://blog.knoldus.com/tag/akka/vikas@knoldus.comhttps://github.com/knoldus/AkkaKnolX
  32. 32. Everyone ! “Thanks”

×