SlideShare a Scribd company logo
 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
Ad

More Related Content

What's hot (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
krivachy
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
nartamonov
 
Akka Actor presentation
Akka Actor presentationAkka Actor presentation
Akka Actor presentation
Gene 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 elasticsearch
Anton Udovychenko
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
Troy 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 cluster
Gal Marder
 
Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in Scala
Alex Payne
 
Dive into spark2
Dive into spark2Dive into spark2
Dive into spark2
Gal 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 meetup
krivachy
 
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 optimizations
Gal Marder
 
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in Java
Yakov Fain
 
Play framework
Play frameworkPlay framework
Play framework
Andrew Skiba
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
Yung-Lin Ho
 
Akka.net versus microsoft orleans
Akka.net versus microsoft orleansAkka.net versus microsoft orleans
Akka.net versus microsoft orleans
Bill 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 8
Johan Andrén
 
What’s expected in Spring 5
What’s expected in Spring 5What’s expected in Spring 5
What’s expected in Spring 5
Gal Marder
 
Actor Model Akka Framework
Actor Model Akka FrameworkActor Model Akka Framework
Actor Model Akka Framework
Harinath Krishnamoorthy
 
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
krivachy
 
Above the clouds: introducing Akka
Above the clouds: introducing AkkaAbove the clouds: introducing Akka
Above the clouds: introducing Akka
nartamonov
 
Akka Actor presentation
Akka Actor presentationAkka Actor presentation
Akka Actor presentation
Gene 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 elasticsearch
Anton Udovychenko
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
Troy 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 cluster
Gal Marder
 
Building Distributed Systems in Scala
Building Distributed Systems in ScalaBuilding Distributed Systems in Scala
Building Distributed Systems in Scala
Alex Payne
 
Dive into spark2
Dive into spark2Dive into spark2
Dive into spark2
Gal 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 meetup
krivachy
 
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 optimizations
Gal Marder
 
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in Java
Yakov Fain
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
Yung-Lin Ho
 
Akka.net versus microsoft orleans
Akka.net versus microsoft orleansAkka.net versus microsoft orleans
Akka.net versus microsoft orleans
Bill 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 8
Johan Andrén
 
What’s expected in Spring 5
What’s expected in Spring 5What’s expected in Spring 5
What’s expected in Spring 5
Gal Marder
 

Similar to 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
Skills 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.0
Knoldus Inc.
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
Yaroslav Tkachenko
 
Building Stateful Microservices With Akka
Building Stateful Microservices With AkkaBuilding Stateful Microservices With Akka
Building Stateful Microservices With Akka
Yaroslav 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 Heroku
Salesforce Developers
 
Akka introtalk HyScala DEC 2016
Akka introtalk HyScala DEC 2016Akka introtalk HyScala DEC 2016
Akka introtalk HyScala DEC 2016
PrasannaKumar Sathyanarayanan
 
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
Jean-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 Spray
Jacob Park
 
Advanced akka features
Advanced akka featuresAdvanced akka features
Advanced akka features
Grzegorz Duda
 
Scale up your thinking
Scale up your thinkingScale up your thinking
Scale up your thinking
Yardena Meymann
 
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
Sören Stelzer
 
Overview of Akka
Overview of AkkaOverview of Akka
Overview of Akka
Ben 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 Camel
krasserm
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
Yung-Lin Ho
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOne
Konrad Malawski
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
Ajax Experience 2009
 
Akka Actors: an Introduction
Akka Actors: an IntroductionAkka Actors: an Introduction
Akka Actors: an Introduction
Roberto 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 spark
Rahul Kumar
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
Luka Zakrajšek
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
Manuel Bernhardt
 
Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_group
Skills 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.0
Knoldus Inc.
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
Yaroslav Tkachenko
 
Building Stateful Microservices With Akka
Building Stateful Microservices With AkkaBuilding Stateful Microservices With Akka
Building Stateful Microservices With Akka
Yaroslav 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 Heroku
Salesforce 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 Semdev2015
Jean-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 Spray
Jacob Park
 
Advanced akka features
Advanced akka featuresAdvanced akka features
Advanced akka features
Grzegorz 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.Net
Sören Stelzer
 
Overview of Akka
Overview of AkkaOverview of Akka
Overview of Akka
Ben 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 Camel
krasserm
 
Introduction to Actor Model and Akka
Introduction to Actor Model and AkkaIntroduction to Actor Model and Akka
Introduction to Actor Model and Akka
Yung-Lin Ho
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOne
Konrad Malawski
 
Laurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus PresentationLaurens Van Den Oever Xopus Presentation
Laurens Van Den Oever Xopus Presentation
Ajax Experience 2009
 
Akka Actors: an Introduction
Akka Actors: an IntroductionAkka Actors: an Introduction
Akka Actors: an Introduction
Roberto 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 spark
Rahul Kumar
 
Typesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and PlayTypesafe stack - Scala, Akka and Play
Typesafe stack - Scala, Akka and Play
Luka Zakrajšek
 
Reactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDaysReactive Web-Applications @ LambdaDays
Reactive Web-Applications @ LambdaDays
Manuel Bernhardt
 
Ad

Recently uploaded (20)

Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
Ad

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 [email protected]