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

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
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"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
 
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
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
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
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
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
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Kürzlich hochgeladen (20)

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
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
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
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"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
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
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
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
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
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
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
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

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