SlideShare ist ein Scribd-Unternehmen logo
1 von 29
Downloaden Sie, um offline zu lesen
 Scaling Web Apps with Akka 
Maciej Matyjas
London Scala User Group
Skills Matter
2010 July 14
“ Simple Scalability, 
    Fault-Tolerance, Concurrency & 
    Remoting through Actors”
akkasource.org
Scaling Web Apps with Akka

Characteristics      Techniques
 High Availability    Hardware
 Quick Page Loads     Load Balancing
 Fast Reads/Writes    Caching
                      Partitioning
                      Queues/Messaging
                      Replication
                      CDN
Scaling Web Apps with Akka
Scaling Web Apps with Akka

  Range of mountains in Sweden

  Open Source Project

  Written in Scala with Scala/Java APIs
Scaling Web Apps with Akka

  Actors Model

  Multi-Core and Cloud Infrastructure

  Graceful Failure a la Erlang OTP

  Transactions a la Clojure

  NoSQL and Distributed Data Stores

  Flexible Dispatch Strategies
Actors Model of Computing


 Defined in 1963 by Carl Hewitt

 Used by Erlang to support reliability (99.9999999% uptime)
Actors Model of Computing

 "encapsulates state and behavior into a lightweight
 process/thread" - Jonas Bonér
 Asynchronous message passing between Actors
 Messages are immutable
 Synchronized mailbox
 Mailbox is read with pattern matching
 No shared state
 No locks
 Safe concurrency
No shared state
        +
    No locks
        =
Safe concurrency
Actors Model Implementations

 Erlang
 Scala Thread based
 Scala Event based
 Lift Actors
 Akka
Erlang Actors Example
-module(mypackage).

myErlangActor() ->
receive
{msgType, Msg} ->
  io:format(" p n", [Msg]),
  myErlangActor()
Other ->
  io:format("wholy canoli, this is unmatched! n"),
  myErlangActor()
end.

c(mypackage).
Pid = spawn(fun mypackage:myErlangActor/0).
Pid ! {msgType, "Erlang is for the discerning programmer"}.
Scala Thread Based Actors
import scala.actor.Actor
import scala.actor.Actor._

case class Message(msg: String)

class AnActor extends Actor {
   def act() = receive {
     case Message(m) => println(m)
     case _ => println("unknown message")
   }
}

class Director {
   val myActor = new AnActor
   myActor.start
   myActor ! Message("threedz can haz block?")
}
Scala Event Based Actors
import scala.actor.Actor
import scala.actor.Actor._

case class Message(msg: String)

class AnActor extends Actor {
   def act() = loop {
                 react {
                   case Message(m) => println(m)
                   case _ => println("unknown message")
}}}

class Director {
   val myActor = new AnActor
   myActor.start
   myActor ! Message("eventz iz lightweight?")
}
Lift Actors

case class Message(msg: String)

class AnActor extends LiftActor {
 def messageHandler = {
   case Message(m) => println(m)
   case _ => println("unknown message")
}}

class Director {
   val myActor = new AnActor
   myActor ! Message("Lift Actors is lightest & rulz!")
}
Akka Actors
import se.scalablesolutions.akka.actor.Actor
case class Message(msg: String)

class AnActor extends Actor {
   def receive = {
     case Message(m) => println(m)
     case _ => println("unknown message")
   }
}

class Director {
   val myActor = Actor.actorOf[AnActor]
   myActor.start
   myActor ! Message("akkastic!")
}
Leverage Multi-Core and Distributed
Cloud Infrastructure
 Millions of lightweight actors on commodity hardware

 Safe Concurrency

 Remote Actors
Leverage Multi-Core and Distributed
Cloud Infrastructure: Remote Actors
import se.scalablesolutions.akka.remote.RemoteNode

spawnRemote[MyActor](host, port)

spawnLinkRemote[MyActor](host, port)
startLinkRemote(myActor, host, port)
Handle Failure Gracefully

  "Let it Crash"
  Actor exceptions w/out supervision do not behave well
  Remote Actors w/out supervision are unmanaged
  Linking Actors
  Supervisor
     Manages linked Actors
     Notified when linked Actor crashes
     OneForOne
     AllForOne
  Works with Remote Actors
Handle Failure Gracefully: Supervisor
 val supervisor = Supervisor(
  SupervisorConfig(
   RestartStrategy(OneForOne, 3, 1000, List(classOf[Exception])),
  Supervise(
   actorOf[MyActor],
   LifeCycle(Permanent)) ::
  Nil))

supervisor.link(actorOf[MyActor])

class MyActor extends Actor {
    self.lifeCycle = Some(LifeCycle(Permanent))
    override def preRestart(reason: Throwable) {
      // clean things up
   }
}
Manage Transactions
 Software Transactional Memory (STM)
    Thanks Clojure!
    Addresses fundamental weakness of Actors Model
    Hello Shared State!
    Transactional but still no locks
    In memory
    Map, Vector, & Ref throw exceptions if modified outside
    of transaction
    ACI but no D
 Transactors
    Transactional Actors
    Actors + STM
    If Actor's writes clash, rollback memory and retried
Manage Transactions: Transactors
import se.scalablesolutions.akka.actor.Transactor
import se.scalablesolutions.akka.stm._

class MyActor extends Transactor {
   def receive = {
      case Increment(counter) => counter.swap(counter.get + 1)
   }
}

class Director {
   lazy val counter = Ref(0)
   //counter.swap(7) // blows up, cannot mutate outside transaction
   myActor ! Increment(counter)
}
NoSQL & Distributed Data Stores

 Pluggable Storage Back Ends
     Cassandra
     Redis
     MongoDB
     Others...
 Brings the D in ACID
 Works with STM and Transactors
NoSQL & Distributed Data Stores:
Casssandra
import se.scalablesolutions.akka._
import stm.Transaction.Local._
import persistence.cassandra._

val map = CassandraStorage.newMap(myId)
// map += "myKey" -> Value(someSuch) // exception
atomic {
   map += "myKey" -> Value(someSuch)
}
Flexible Dispatch Strategies

 Default is Single-threaded, Event-based dispatcher
 Work-stealing, Event-based
 Reactor-base, Event-driven
 Thread-based
 Event-based
Flexible Dispatch Strategies

class MyActor extends Actor {

  self.dispatcher = Dispatchers.
newExecutorBasedEventDrivenDispatche(name)

    dispatcher
       .withNewThreadPoolWithBoundedBlockingQueue(100)
       .setCorePoolSize(16)
       .setMaxPoolSize(128)
       .setKeepAliveTimeInMillis(60000)
       .setRejectionPolicy(new CallerRunsPolicy)
       .buildThreadPool
}
Here Comes the Code
Demo Time!
Versions

 Scala 2.8.0.RC6
 Lift 2.0-scala2.8.0-SNAPSHOT
 Akka 2.8.0.RC3 0.9.1
 sbt 0.7.4
 ensime master on github.com
Alternatives
Before Drinking the Kool-Aid or Flogging Your Fav Tool


 Other Actor Impls                More Options
    scalaz                          JVM
    FunctionalJava                      Fork/Join
    GParallelizer                       ESB
    Kilim                               Netty
    ActorFoundry                        HawtDispatch
    Actors Guild                    Erlang
    Jetlang                         RabbitMQ
    Actorom                         Hadoop
    Fan Actors                      OpenMP
                                    MPI
Questions About Akka?

 http://akkasource.org
 http://groups.google.com/group/akka-user
 Course at Skills Matter Oct 13-14
 LSUG talk on Oct 13
 Ask me:
     @matyjas
     matyjas@gmail.com

Weitere ähnliche Inhalte

Was ist angesagt?

The dark side of Akka and the remedy
The dark side of Akka and the remedyThe dark side of Akka and the remedy
The dark side of Akka and the remedykrivachy
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akkanartamonov
 
Akka Actor presentation
Akka Actor presentationAkka Actor presentation
Akka Actor presentationGene Chang
 
Search and analyze your data with elasticsearch
Search and analyze your data with elasticsearchSearch and analyze your data with elasticsearch
Search and analyze your data with elasticsearchAnton Udovychenko
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN StackTroy Miles
 
Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster OpenCredo
 
Stream processing from single node to a cluster
Stream processing from single node to a clusterStream processing from single node to a cluster
Stream processing from single node to a clusterGal Marder
 
Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in ScalaAlex Payne
 
Dive into spark2
Dive into spark2Dive into spark2
Dive into spark2Gal Marder
 
2014-02-20 | Akka Concurrency (Vienna Scala User Group)
2014-02-20 | Akka Concurrency (Vienna Scala User Group)2014-02-20 | Akka Concurrency (Vienna Scala User Group)
2014-02-20 | Akka Concurrency (Vienna Scala User Group)Dominik Gruber
 
The dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetupThe dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetupkrivachy
 
Implementing Micro Services Tasks (service discovery, load balancing etc.) - ...
Implementing Micro Services Tasks (service discovery, load balancing etc.) - ...Implementing Micro Services Tasks (service discovery, load balancing etc.) - ...
Implementing Micro Services Tasks (service discovery, load balancing etc.) - ...Gal Marder
 
Spark real world use cases and optimizations
Spark real world use cases and optimizationsSpark real world use cases and optimizations
Spark real world use cases and optimizationsGal Marder
 
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in JavaYakov Fain
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and AkkaYung-Lin Ho
 
Akka.net versus microsoft orleans
Akka.net versus microsoft orleansAkka.net versus microsoft orleans
Akka.net versus microsoft orleansBill Tulloch
 
Introduction to akka actors with java 8
Introduction to akka actors with java 8Introduction to akka actors with java 8
Introduction to akka actors with java 8Johan Andrén
 
What’s expected in Spring 5
What’s expected in Spring 5What’s expected in Spring 5
What’s expected in Spring 5Gal Marder
 

Was ist angesagt? (20)

The dark side of Akka and the remedy
The dark side of Akka and the remedyThe dark side of Akka and the remedy
The dark side of Akka and the remedy
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
 
Akka Actor presentation
Akka Actor presentationAkka Actor presentation
Akka Actor presentation
 
Search and analyze your data with elasticsearch
Search and analyze your data with elasticsearchSearch and analyze your data with elasticsearch
Search and analyze your data with elasticsearch
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster Spring Boot Microservices vs Akka Actor Cluster
Spring Boot Microservices vs Akka Actor Cluster
 
Stream processing from single node to a cluster
Stream processing from single node to a clusterStream processing from single node to a cluster
Stream processing from single node to a cluster
 
Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in Scala
 
Dive into spark2
Dive into spark2Dive into spark2
Dive into spark2
 
2014-02-20 | Akka Concurrency (Vienna Scala User Group)
2014-02-20 | Akka Concurrency (Vienna Scala User Group)2014-02-20 | Akka Concurrency (Vienna Scala User Group)
2014-02-20 | Akka Concurrency (Vienna Scala User Group)
 
The dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetupThe dark side of Akka and the remedy - bp.scala meetup
The dark side of Akka and the remedy - bp.scala meetup
 
Implementing Micro Services Tasks (service discovery, load balancing etc.) - ...
Implementing Micro Services Tasks (service discovery, load balancing etc.) - ...Implementing Micro Services Tasks (service discovery, load balancing etc.) - ...
Implementing Micro Services Tasks (service discovery, load balancing etc.) - ...
 
Spark real world use cases and optimizations
Spark real world use cases and optimizationsSpark real world use cases and optimizations
Spark real world use cases and optimizations
 
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in Java
 
Play framework
Play frameworkPlay framework
Play framework
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
 
Akka.net versus microsoft orleans
Akka.net versus microsoft orleansAkka.net versus microsoft orleans
Akka.net versus microsoft orleans
 
Introduction to akka actors with java 8
Introduction to akka actors with java 8Introduction to akka actors with java 8
Introduction to akka actors with java 8
 
What’s expected in Spring 5
What’s expected in Spring 5What’s expected in Spring 5
What’s expected in Spring 5
 
Actor Model Akka Framework
Actor Model Akka FrameworkActor Model Akka Framework
Actor Model Akka Framework
 

Ähnlich wie Scaling Web Apps with Akka

Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_groupSkills Matter
 
Building Massively Scalable application with Akka 2.0
Building Massively Scalable application with Akka 2.0Building Massively Scalable application with Akka 2.0
Building Massively Scalable application with Akka 2.0Knoldus Inc.
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And DesignYaroslav Tkachenko
 
Building Stateful Microservices With Akka
Building Stateful Microservices With AkkaBuilding Stateful Microservices With Akka
Building Stateful Microservices With AkkaYaroslav Tkachenko
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuSalesforce Developers
 
Scala Programming for Semantic Web Developers ESWC Semdev2015
Scala Programming for Semantic Web Developers ESWC Semdev2015Scala Programming for Semantic Web Developers ESWC Semdev2015
Scala Programming for Semantic Web Developers ESWC Semdev2015Jean-Paul Calbimonte
 
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 SprayJacob Park
 
Advanced akka features
Advanced akka featuresAdvanced akka features
Advanced akka featuresGrzegorz Duda
 
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.NetSören Stelzer
 
Overview of Akka
Overview of AkkaOverview of Akka
Overview of AkkaBen James
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camelkrasserm
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and AkkaYung-Lin Ho
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneKonrad Malawski
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationAjax Experience 2009
 
Akka Actors: an Introduction
Akka Actors: an IntroductionAkka Actors: an Introduction
Akka Actors: an IntroductionRoberto Casadei
 
Reactive app using actor model & apache spark
Reactive app using actor model & apache sparkReactive app using actor model & apache spark
Reactive app using actor model & apache sparkRahul Kumar
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayLuka Zakrajšek
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysManuel Bernhardt
 

Ähnlich wie Scaling Web Apps with Akka (20)

Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_group
 
Building Massively Scalable application with Akka 2.0
Building Massively Scalable application with Akka 2.0Building Massively Scalable application with Akka 2.0
Building Massively Scalable application with Akka 2.0
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
 
Building Stateful Microservices With Akka
Building Stateful Microservices With AkkaBuilding Stateful Microservices With Akka
Building Stateful Microservices With Akka
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and Heroku
 
Akka introtalk HyScala DEC 2016
Akka introtalk HyScala DEC 2016Akka introtalk HyScala DEC 2016
Akka introtalk HyScala DEC 2016
 
Scala Programming for Semantic Web Developers ESWC Semdev2015
Scala Programming for Semantic Web Developers ESWC Semdev2015Scala Programming for Semantic Web Developers ESWC Semdev2015
Scala Programming for Semantic Web Developers ESWC Semdev2015
 
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
 
Advanced akka features
Advanced akka featuresAdvanced akka features
Advanced akka features
 
Scale up your thinking
Scale up your thinkingScale up your thinking
Scale up your thinking
 
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
 
Overview of Akka
Overview of AkkaOverview of Akka
Overview of Akka
 
System Integration with Akka and Apache Camel
System Integration with Akka and Apache CamelSystem Integration with Akka and Apache Camel
System Integration with Akka and Apache Camel
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOne
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
 
Akka Actors: an Introduction
Akka Actors: an IntroductionAkka Actors: an Introduction
Akka Actors: an Introduction
 
Reactive app using actor model & apache spark
Reactive app using actor model & apache sparkReactive app using actor model & apache spark
Reactive app using actor model & apache spark
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
 

Kürzlich hochgeladen

Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"DianaGray10
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioChristian Posta
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 

Kürzlich hochgeladen (20)

Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
UiPath Clipboard AI: "A TIME Magazine Best Invention of 2023 Unveiled"
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
Comparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and IstioComparing Sidecar-less Service Mesh from Cilium and Istio
Comparing Sidecar-less Service Mesh from Cilium and Istio
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 

Scaling Web Apps with Akka

  • 1.  Scaling Web Apps with Akka  Maciej Matyjas London Scala User Group Skills Matter 2010 July 14
  • 2. “ Simple Scalability,      Fault-Tolerance, Concurrency &      Remoting through Actors” akkasource.org
  • 3. Scaling Web Apps with Akka Characteristics Techniques High Availability Hardware Quick Page Loads Load Balancing Fast Reads/Writes Caching Partitioning Queues/Messaging Replication CDN
  • 4. Scaling Web Apps with Akka
  • 5. Scaling Web Apps with Akka Range of mountains in Sweden Open Source Project Written in Scala with Scala/Java APIs
  • 6. Scaling Web Apps with Akka Actors Model Multi-Core and Cloud Infrastructure Graceful Failure a la Erlang OTP Transactions a la Clojure NoSQL and Distributed Data Stores Flexible Dispatch Strategies
  • 7. Actors Model of Computing Defined in 1963 by Carl Hewitt Used by Erlang to support reliability (99.9999999% uptime)
  • 8. Actors Model of Computing "encapsulates state and behavior into a lightweight process/thread" - Jonas Bonér Asynchronous message passing between Actors Messages are immutable Synchronized mailbox Mailbox is read with pattern matching No shared state No locks Safe concurrency
  • 9. No shared state + No locks = Safe concurrency
  • 10. Actors Model Implementations Erlang Scala Thread based Scala Event based Lift Actors Akka
  • 11. Erlang Actors Example -module(mypackage). myErlangActor() -> receive {msgType, Msg} -> io:format(" p n", [Msg]), myErlangActor() Other -> io:format("wholy canoli, this is unmatched! n"), myErlangActor() end. c(mypackage). Pid = spawn(fun mypackage:myErlangActor/0). Pid ! {msgType, "Erlang is for the discerning programmer"}.
  • 12. Scala Thread Based Actors import scala.actor.Actor import scala.actor.Actor._ case class Message(msg: String) class AnActor extends Actor { def act() = receive { case Message(m) => println(m) case _ => println("unknown message") } } class Director { val myActor = new AnActor myActor.start myActor ! Message("threedz can haz block?") }
  • 13. Scala Event Based Actors import scala.actor.Actor import scala.actor.Actor._ case class Message(msg: String) class AnActor extends Actor { def act() = loop { react { case Message(m) => println(m) case _ => println("unknown message") }}} class Director { val myActor = new AnActor myActor.start myActor ! Message("eventz iz lightweight?") }
  • 14. Lift Actors case class Message(msg: String) class AnActor extends LiftActor { def messageHandler = { case Message(m) => println(m) case _ => println("unknown message") }} class Director { val myActor = new AnActor myActor ! Message("Lift Actors is lightest & rulz!") }
  • 15. Akka Actors import se.scalablesolutions.akka.actor.Actor case class Message(msg: String) class AnActor extends Actor { def receive = { case Message(m) => println(m) case _ => println("unknown message") } } class Director { val myActor = Actor.actorOf[AnActor] myActor.start myActor ! Message("akkastic!") }
  • 16. Leverage Multi-Core and Distributed Cloud Infrastructure Millions of lightweight actors on commodity hardware Safe Concurrency Remote Actors
  • 17. Leverage Multi-Core and Distributed Cloud Infrastructure: Remote Actors import se.scalablesolutions.akka.remote.RemoteNode spawnRemote[MyActor](host, port) spawnLinkRemote[MyActor](host, port) startLinkRemote(myActor, host, port)
  • 18. Handle Failure Gracefully "Let it Crash" Actor exceptions w/out supervision do not behave well Remote Actors w/out supervision are unmanaged Linking Actors Supervisor Manages linked Actors Notified when linked Actor crashes OneForOne AllForOne Works with Remote Actors
  • 19. Handle Failure Gracefully: Supervisor val supervisor = Supervisor( SupervisorConfig( RestartStrategy(OneForOne, 3, 1000, List(classOf[Exception])), Supervise( actorOf[MyActor], LifeCycle(Permanent)) :: Nil)) supervisor.link(actorOf[MyActor]) class MyActor extends Actor { self.lifeCycle = Some(LifeCycle(Permanent)) override def preRestart(reason: Throwable) { // clean things up } }
  • 20. Manage Transactions Software Transactional Memory (STM) Thanks Clojure! Addresses fundamental weakness of Actors Model Hello Shared State! Transactional but still no locks In memory Map, Vector, & Ref throw exceptions if modified outside of transaction ACI but no D Transactors Transactional Actors Actors + STM If Actor's writes clash, rollback memory and retried
  • 21. Manage Transactions: Transactors import se.scalablesolutions.akka.actor.Transactor import se.scalablesolutions.akka.stm._ class MyActor extends Transactor { def receive = { case Increment(counter) => counter.swap(counter.get + 1) } } class Director { lazy val counter = Ref(0) //counter.swap(7) // blows up, cannot mutate outside transaction myActor ! Increment(counter) }
  • 22. NoSQL & Distributed Data Stores Pluggable Storage Back Ends Cassandra Redis MongoDB Others... Brings the D in ACID Works with STM and Transactors
  • 23. NoSQL & Distributed Data Stores: Casssandra import se.scalablesolutions.akka._ import stm.Transaction.Local._ import persistence.cassandra._ val map = CassandraStorage.newMap(myId) // map += "myKey" -> Value(someSuch) // exception atomic { map += "myKey" -> Value(someSuch) }
  • 24. Flexible Dispatch Strategies Default is Single-threaded, Event-based dispatcher Work-stealing, Event-based Reactor-base, Event-driven Thread-based Event-based
  • 25. Flexible Dispatch Strategies class MyActor extends Actor { self.dispatcher = Dispatchers. newExecutorBasedEventDrivenDispatche(name) dispatcher .withNewThreadPoolWithBoundedBlockingQueue(100) .setCorePoolSize(16) .setMaxPoolSize(128) .setKeepAliveTimeInMillis(60000) .setRejectionPolicy(new CallerRunsPolicy) .buildThreadPool }
  • 26. Here Comes the Code Demo Time!
  • 27. Versions Scala 2.8.0.RC6 Lift 2.0-scala2.8.0-SNAPSHOT Akka 2.8.0.RC3 0.9.1 sbt 0.7.4 ensime master on github.com
  • 28. Alternatives Before Drinking the Kool-Aid or Flogging Your Fav Tool Other Actor Impls More Options scalaz JVM FunctionalJava Fork/Join GParallelizer ESB Kilim Netty ActorFoundry HawtDispatch Actors Guild Erlang Jetlang RabbitMQ Actorom Hadoop Fan Actors OpenMP MPI
  • 29. Questions About Akka? http://akkasource.org http://groups.google.com/group/akka-user Course at Skills Matter Oct 13-14 LSUG talk on Oct 13 Ask me: @matyjas matyjas@gmail.com