Scaling Up & Out with Actors: Introducing Akka



Similar documents
Above the Clouds: Introducing Akka

Monitoring Hadoop with Akka. Clint Combs Senior Software Engineer at Collective

Akka Streams. Dr. Roland Typesafe

Wisdom from Crowds of Machines

Scala Actors Library. Robert Hilbrich

Elastic Application Platform for Market Data Real-Time Analytics. for E-Commerce

TYPESAFE TOGETHER - SUBSCRIBER TRAINING. Training Classes

Glassfish Architecture.

Apache Tomcat. Load-balancing and Clustering. Mark Thomas, 20 November Pivotal Software, Inc. All rights reserved.

REACTIVE systems [1] currently lie on the final frontier

membase.org: The Simple, Fast, Elastic NoSQL Database NorthScale Matt Ingenthron OSCON 2010

Building Scalable Big Data Infrastructure Using Open Source Software. Sam William

In-Memory BigData. Summer 2012, Technology Overview

High Availability with Elixir

FioranoMQ 9. High Availability Guide

Reactive Applications: What if Your Internet of Things has 1000s of Things?

Building Scalable Messaging Systems with Qpid. Lessons Learned from PayPal

ACTOR-BASED MODEL FOR CONCURRENT PROGRAMMING. Sander Sõnajalg

Request Routing, Load-Balancing and Fault- Tolerance Solution - MediaDNS

Deploying complex applications to Google Cloud. Olia Kerzhner

OpenSER the open SIP Server. Bogdan-Andrei Iancu CEO Voice System Co-Founder OpenSER Project

Spark Job Server. Evan Chan and Kelvin Chu. Date

Developing Scalable Smart Grid Infrastructure to Enable Secure Transmission System Control

Clustering with Tomcat. Introduction. O'Reilly Network: Clustering with Tomcat. by Shyam Kumar Doddavula 07/17/2002

Building Heavy Load Messaging System

F1: A Distributed SQL Database That Scales. Presentation by: Alex Degtiar (adegtiar@cmu.edu) /21/2013

A distributed system is defined as

Big Data Analytics! Architectures, Algorithms and Applications! Part #3: Analytics Platform

Architectures for massive data management

GlassFish v3. Building an ex tensible modular Java EE application server. Jerome Dochez and Ludovic Champenois Sun Microsystems, Inc.

Redis Cluster. a pragmatic approach to distribution

Sentinet for Windows Azure SENTINET

Streaming items through a cluster with Spark Streaming

RED HAT JBOSS FUSE. An open source enterprise service bus

Clustering/HA. Introduction, Helium Capabilities, and Potential Lithium Enhancements.

Amazon Kinesis and Apache Storm

VMware vrealize Automation

BSC vision on Big Data and extreme scale computing

JoramMQ, a distributed MQTT broker for the Internet of Things

<Insert Picture Here> GlassFish v3 - A Taste of a Next Generation Application Server

Deployment Topologies

Responsive, resilient, elastic and message driven system

LOAD BALANCING TECHNIQUES FOR RELEASE 11i AND RELEASE 12 E-BUSINESS ENVIRONMENTS

Developing modular Java applications

Disaster Recovery White Paper

Exploring Oracle E-Business Suite Load Balancing Options. Venkat Perumal IT Convergence

The Service Availability Forum Specification for High Availability Middleware

Apache Tomcat Clustering

Networks and Services

Contents Huntcliff, Suite 1350, Atlanta, Georgia, 30350, USA

High Availability Essentials

VMware vcloud Automation Center 6.1

Ecomm Enterprise High Availability Solution. Ecomm Enterprise High Availability Solution (EEHAS) Page 1 of 7

Overview. Elements of Programming Languages. Advanced constructs. Motivating inner class example

Layer 4-7 Server Load Balancing. Security, High-Availability and Scalability of Web and Application Servers

ViSION Status Update. Dan Savu Stefan Stancu. D. Savu - CERN openlab

Hadoop IST 734 SS CHUNG

Unified Big Data Processing with Apache Spark. Matei

Configuring Nex-Gen Web Load Balancer

Sentinet for BizTalk Server SENTINET

Building Reliable, Scalable AR System Solutions. High-Availability. White Paper

LinuxWorld Conference & Expo Server Farms and XML Web Services

Comparing Microsoft SQL Server 2005 Replication and DataXtend Remote Edition for Mobile and Distributed Applications

Spark ΕΡΓΑΣΤΗΡΙΟ 10. Prepared by George Nikolaides 4/19/2015 1

Disaster Recovery Design Ehab Ashary University of Colorado at Colorado Springs

Couchbase Server Technical Overview. Key concepts, system architecture and subsystem design

Operations Orchestration Automating Your Data Center May 21, 2014

Lambda Architecture for Batch and Real- Time Processing on AWS with Spark Streaming and Spark SQL. May 2015

Windows Azure and private cloud

12 Factor App. Best Practices for Scala Deployment

CSci 8980 Mobile Cloud Computing. Mobile Cloud Programming

Monitor Your Key Performance Indicators using WSO2 Business Activity Monitor

Write a technical report Present your results Write a workshop/conference paper (optional) Could be a real system, simulation and/or theoretical

TIBCO FTL Glossary. Software Release 4.3 November Two-Second Advantage

VMware vrealize Automation

Building Hyper-Scale Platform-as-a-Service Microservices with Microsoft Azure. Patriek van Dorp and Alex Thissen

CONSUL AS A MONITORING SERVICE

DB2 Connect for NT and the Microsoft Windows NT Load Balancing Service

Realization of Inventory Databases and Object-Relational Mapping for the Common Information Model

Asynchronous Peer-to- Peer Web Services and Firewalls

Advanced LCR (Least Cost Router) With SIP Proxy Server

Architectures for massive data management

Deploying Windows Streaming Media Servers NLB Cluster and metasan

Based on Geo Clustering for SUSE Linux Enterprise Server High Availability Extension

OpenPaaS Le réseau social d'entreprise

Intro to Load-Balancing Tomcat with httpd and mod_jk

Chao Chen 1 Michael Lang 2 Yong Chen 1. IEEE BigData, Department of Computer Science Texas Tech University

Performance Prediction, Sizing and Capacity Planning for Distributed E-Commerce Applications

Android Developer Fundamental 1

Routing Security Server failure detection and recovery Protocol support Redundancy

Optimizing High-Performance Trading Solutions: An Engineering Perspective

Availability Digest. Redundant Load Balancing for High Availability July 2013

WELCOME TO Open Source Enterprise Architecture

A Brief. Introduction. of MG-SOFT s SNMP Network Management Products. Document Version 1.3, published in June, 2008

Productionizing a 24/7 Spark Streaming Service on YARN

Load balancing in SOAJA (Service Oriented Java Adaptive Applications)

EWeb: Highly Scalable Client Transparent Fault Tolerant System for Cloud based Web Applications

PLUMgrid Toolbox: Tools to Install, Operate and Monitor Your Virtual Network Infrastructure

18.2 user guide No Magic, Inc. 2015

Chapter 2 TOPOLOGY SELECTION. SYS-ED/ Computer Education Techniques, Inc.

Transcription:

Scaling Up & Out with Actors: Introducing Akka Akka Tech Lead Email: viktor.klang@typesafe.com Twitter: @viktorklang

The problem It is way too hard to build: 1. correct highly concurrent systems 2. truly scalable systems 3. fault-tolerant systems that self-heals...using state-of-the-art tools

Introducing

Introducing Akka (Áhkká): The name comes from the goddess in the Sami mythology that represented all the wisdom and beauty in the world. It is also the name of a beautiful mountain in Laponia in the north part of Sweden

Introducing View from the summit

Vision Simpler Concurrency Scalability Fault-tolerance

Vision...with a single unified Programming Model Managed Runtime Open Source Distribution

Manage system overload

Scale up & Scale out

Replicate and distribute for fault-tolerance

Transparent load balancing

INTRODUCING Akka 2.0

Akka 2.0-RC1

636 tickets closed

1011 files changed

96261 lines added

56733 lines removed

56733 lines removed

ARCHITECTURE CORE SERVICES

ADD-ON MODULES ARCHITECTURE

ARCHITECTURE TYPESAFE STACK ADD-ONS

WHERE IS AKKA USED? SOME EXAMPLES: FINANCE Stock trend Analysis & Simulation Event-driven messaging systems BETTING & GAMING Massive multiplayer online gaming High throughput and transactional betting TELECOM Streaming media network gateways SIMULATION 3D simulation engines E-COMMERCE Social media community sites

Scale up

What is an Actor?

Actor Behavior State

Eventdriven Actor Behavior State

Eventdriven Actor Behavior State

Eventdriven Actor Behavior State

Eventdriven Actor Behavior State

Eventdriven Actor Behavior State

Actor Behavior State

Eventdriven Actor Behavior State

Akka Actors one tool in the toolbox

Actors case object Tick class Counter extends Actor { var counter = 0 } def receive = { case Tick => counter += 1 println(counter) } Scala API

Actors class Counter extends UntypedActor { int counter = 0; } void onreceive(object msg) { if (msg.equals( Tick )) { counter += 1; System.out.println(counter); } } Java API

Create Application val conf = ConfigFactory.load( application ) val system = ActorSystem( my-app, conf) Scala API

Create Application Config conf = ConfigFactory.load( application ); ActorSystem system = ActorSystem.create( my-app, conf); Java API

Create Actors val counter = system.actorof(props[counter]) counter is an ActorRef Creates a top-level actor Scala API

Create Actors ActorRef counter = system.actorof(new Props(Counter.class)); Creates a top-level actor Java API

Stop actors system.stop(counter)...also stops all actors in the hierarchy below

Send:! counter! Tick fire-forget Scala API

...or use tell counter tell Tick fire-forget Scala API

...or use tell counter.tell(tick); fire-forget Java API

Send:? import akka.patterns.ask // returns a future val future = actor? message future onsuccess { case x => println(x) } returns the Future directly Scala API

...or use ask import akka.patterns.ask // returns a future val future = actor ask message future onsuccess { case x => println(x) } returns the Future directly Scala API

Reply class SomeActor extends Actor { def receive = { case User(name) => // reply to sender sender! ( Hi + name) } } Scala API

Reply class SomeActor extends UntypedActor { void onreceive(object msg) { if (msg instanceof User) { User user = (User) msg; // reply to sender getsender().tell( Hi + user.name); } } } Java API

...or use ask import akka.patterns.ask // returns a future val future = actor ask message future onsuccess { case x => println(x) } Scala API

...or use ask import static akka.patterns.patterns.ask; Future<Object> future = ask(actor, message, timeout); future.onsuccess(new OnSuccess<Object>() { public void onsuccess(string result) { System.out.println(result); } }); Java API

Future val f = Promise[String]() f oncomplete {... } onsuccess {... } onfailure {... } f foreach {... } f map {... } f flatmap {... } f filter {... } f zip otherf f fallbackto otherf Await.result(f, 5 seconds) Scala API

Future firstcompletedof find sequence fold traverse reduce Combinators for collections of Futures

become context become { // new body case NewMessage =>... } Scala API

become context.become(new Procedure[Object]() { void apply(object msg) { // new body if (msg instanceof NewMessage) { NewMessage newmsg = (NewMessage)msg;... } } }); Java API

unbecome context.unbecome()

Routers val router = system.actorof( Props[SomeActor].withRouter( RoundRobinRouter(nrOfInstances = 5))) Scala API

Router + Resizer val resizer = DefaultResizer(lowerBound = 2, upperbound = 15) val router = system.actorof( Props[ExampleActor1].withRouter( RoundRobinRouter(resizer = Some(resizer)) ) ) Scala API

Scale up?

ThreadPoolExecutor

ThreadPoolExecutor

new ForkJoinPool

new ForkJoinPool

Scale out

New Remote Actors

Name val actor = system.actorof(props[myactor], my-service ) Bind the actor to a name Scala API

Name ActorRef actor = system.actorof( new Props(MyActor.class), my-service ) Bind the actor to a name Java API

Deployment Actor name is virtual and decoupled from how it is deployed

Deployment If no deployment configuration exists then actor is deployed as local

Deployment The same system can be configured as distributed without code change (even change at runtime)

Deployment Write as local but deploy as distributed in the cloud without code change

Deployment Allows runtime to dynamically and adaptively change topology

Deployment configuration akka { actor { deployment { /my-service { router = "round-robin" nr-of-instances = 3 target { nodes = ["wallace:2552", "gromit:2552"] } } } } }

Let it crash fault-tolerance

The Erlang model

9 nines

...let s take a standard OO application

Which components have critically important state and explicit error handling?

Fault-tolerant onion-layered Error Kernel

Error Kernel

Error Kernel

Error Kernel

Error Kernel

Error Kernel

Error Kernel

Node 1 Node 2

Parental automatic supervision // from within an actor val child = context.actorof(props[myactor], my-actor ) transparent and automatic fault handling by design Scala API

Parental automatic supervision // from within an actor ActorRef child = getcontext().actorof( new Props(MyActor.class), my-actor ); transparent and automatic fault handling by design Java API

Parental automatic supervision Guardian System Actor

Parental automatic supervision Guardian System Actor system.actorof(props[foo], Foo )

Parental automatic supervision Guardian System Actor Foo system.actorof(props[foo], Foo )

Parental automatic supervision Guardian System Actor Foo context.actorof(props[a], A )

Parental automatic supervision Guardian System Actor Foo A context.actorof(props[a], A )

Parental automatic supervision Guardian System Actor Foo Bar A C A B E B C D

Name resolution Guardian System Actor Foo Bar A C A B E B C D

Name resolution Guardian System Actor /Foo Foo Bar A C A B E B C D

Name resolution Guardian System Actor /Foo Foo Bar /Foo/A A C A B E B C D

Name resolution Guardian System Actor /Foo Foo Bar /Foo/A A C A /Foo/A/B B E B C D

Name resolution Guardian System Actor /Foo Foo Bar /Foo/A A C A /Foo/A/B B E B C /Foo/A/D D

Supervision class MySupervisor extends Actor { def supervisorstrategy = OneForOneStrategy({ case _: ActorKilledException => Stop case _: ArithmeticException => Resume case _: Exception => Restart case _ => Escalate }, maxnrofretries = None, withintimerange = None) def receive = { case NewUser(name) =>... = context.actorof[user](name) } } Scala API

Supervision class MySupervisor extends Actor { def supervisorstrategy = AllForOneStrategy OneForOneStrategy({ case _: ActorKilledException => Stop case _: ArithmeticException => Resume case _: Exception => Restart case _ => Escalate }, maxnrofretries = None, withintimerange = None) } def receive = { case NewUser(name) =>... = context.actorof[user](name) } Scala API

Manage failure class FaultTolerantService extends Actor {... override def prerestart( reason: Throwable, message: Option[Any]) = {... // clean up before restart } override def postrestart(reason: Throwable) = {... // init after restart } } Scala API

watch/unwatch val buddy: ActorRef =... val watcher = system.actorof(props( new Actor { context.watch(buddy) } )) def receive = { case t: Terminated =>... } Scala API

Akka 2.1+

The runtime provides Decentralized P2P gossip-based cluster membership (dynamo-style w/ vector clocks, hand-off on fail-over etc.)

The runtime provides Automatic adaptive cluster rebalancing

The runtime provides Automatic cluster-wide deployment

The runtime provides Highly available configuration service

The runtime provides Automatic replication with automatic fail-over upon node crash

The runtime provides Transparent and user-configurable load-balancing

Akka Node

Akka Node val ping = actorof(props[ping], ping ) val pong = actorof(props[pong], pong ) ping! Ball(pong)

Akka Node val ping = actorof(props[ping], ping ) val pong = actorof(props[pong], pong ) ping! Ball(pong) Ping Pong

Akka Node Akka Cluster Node Ping Pong

Akka Cluster Node Akka Node Akka Cluster Node Akka Cluster Node Ping Pong Akka Cluster Node Akka Cluster Node

Akka Cluster Node Akka Cluster Node Akka Cluster Node Ping Pong Akka Cluster Node Akka Cluster Node

Akka Cluster Node Akka Cluster Node Ping akka { actor { deployment { /ping {} /pong { router = "round-robin" nr-of-instances = 3 } } Pong } } Akka Cluster Node Akka Cluster Node Akka Cluster Node

Akka Cluster Node Akka Cluster Ping Node akka { actor { deployment { /ping {} /pong { router = "round-robin" nr-of-instances = 3 } } Pong } } Akka Cluster Node Akka Cluster Node Akka Cluster Node

Akka Pong Cluster Node Akka Cluster Ping Node akka { actor { deployment { /ping {} /pong { router = "round-robin" nr-of-instances = 3 } } } } Akka Pong Cluster Node Akka Pong Cluster Node Akka Cluster Node

...and much much more HTTP Transactors FSM Durable Mailboxes Microkernel SLF4J Camel NIO ZeroMQ Dataflow AMQP Agents Spring TestKit

Get it and learn more http://akka.io http://typesafe.com

EOF