reactiveness all the way - sw architecture 2015 conference

Post on 13-Apr-2017

232 Views

Category:

Technology

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Tamir DresherSenior Software ArchitectNovember 2015

Reactiveness All The Way

About Me

• Software architect, consultant and instructor• Software Engineering Lecturer @ Ruppin Academic Center• Reactive Extensions in Action (Manning)

@tamir_dreshertamirdr@codevalue.nethttp://www.TamirDresher.com.

3

Software Architecture is like Pasta

By @benorama

4

Socialmedia

Stock tickers

RSS feeds

GPS

Server managementUI e

vents

Your System

5

Being Reactive

Responsive

Resilience

React to users

React to failures

http://www.reactivemanifesto.org/

6

Resiliency

You know you have a distributed system when the crash of a computer you’ve never heard of stops

you from getting any work done.

- Leslie Lamport -

7

Being Reactive

Responsive

Resilience

React to users

React to failures

8

Being Reactive

Responsive

Resilience

Message Driven

React to users

React to failures

React to messages

9

Being Reactive

Responsive

Elastic Resilience

Message Driven

React to users

React to failuresReact to load

React to messages

10

Being Reactive

Responsive

Elastic Resilience

Message Driven

React to users

React to failuresReact to load

React to messages

11

Reacting to Changes (notifications) with Rx• Observables• Observers• Operators• www.ReactiveX.io

g(x)

f(x)UI eve

nts

Stock tickers

12

Rx Example

1. At least 4 characters2. Don’t overflow server (0.5 sec delay)3. Don’t send the same string again4. Discard results if another search was requested

13

Rx Example

Rx.Observable.fromEvent($('#input'),'keyup') .map(e => e.target.value) .filter(text => text.length > 3) .throttle(500 /* ms */) .distinctUntilChanged() .flatMapLatest(searchWikipedia) .subscribe( data => { /* handle the results */}, error => { /* handle any errors */});

Observable.FromEventPattern(txtBox,“TextChanged”) .Select(_ => txtBox.Text); .Where(txt => txt.Length > 3); .Throttle(TimeSpan.FromSeconds(0.5)) .DistinctUntilChanged() .Select(text => SearchAsync(text)) .Switch() .Subscribe(

results => { /* handle the results */ },ex => { /* handle any errors */ } );

RxJS Rx.NET

14

Back Pressure

3 per sec 1 per sec

http://www.reactive-streams.org/

Publisher Subscriber

demand

• “Push” behavior when consumer is faster

• “Pull” behavior when producer is faster

15

The Actor Model (Hewitt et al. 1973)

Alice

Mailbox

Bob

Sally

Mailbox

Mailbox

“the Actor model retained more of what I thought

were the good features of the object idea.”

Alan Kay Object Orientation pioneer and Smalltalk co-designer

AliceParent

BobParent

SallyParent

16

Akka Exampleclass SimpleActor extends Actor { override def receive: Receive = { case x => println("Received message: " + x) }}

object Main extends App { val system = ActorSystem(“actor-system") val anActor: ActorRef = system.actorOf(Props[SimpleActor]) anActor ! "Hello world" }

akka { actor.deployment { /simpleActor { remote = "akka://actor-system@127.0.0.1:3232" } }}

17

Akka Parental Supervision

override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) { case _: ArithmeticException => Resume case _: NullPointerException => Restart case _: IllegalArgumentException => Stop case _: Exception => Escalate }

1. OneForOneStrategy – affect only the failing child2. AllForOneStrategy – affects the failing child & it’s siblings

Child

Parent

Child

Presenter contact detailst: @tamir_dreshere: tamirdr@codevalue.netb: TamirDresher.comw: www.codevalue.net

top related