reactiveness all the way - sw architecture 2015 conference

19
Tamir Dresher Senior Software Architect November 2015 Reactiveness All The Way

Upload: tamir-dresher

Post on 13-Apr-2017

232 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: Reactiveness All The Way - SW Architecture 2015 Conference

Tamir DresherSenior Software ArchitectNovember 2015

Reactiveness All The Way

Page 2: Reactiveness All The Way - SW Architecture 2015 Conference

About Me

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

@[email protected]://www.TamirDresher.com.

Page 3: Reactiveness All The Way - SW Architecture 2015 Conference

3

Software Architecture is like Pasta

By @benorama

Page 4: Reactiveness All The Way - SW Architecture 2015 Conference

4

Socialmedia

Stock tickers

RSS feeds

GPS

Server managementUI e

vents

Your System

Page 5: Reactiveness All The Way - SW Architecture 2015 Conference

5

Being Reactive

Responsive

Resilience

React to users

React to failures

http://www.reactivemanifesto.org/

Page 6: Reactiveness All The Way - SW Architecture 2015 Conference

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 -

Page 7: Reactiveness All The Way - SW Architecture 2015 Conference

7

Being Reactive

Responsive

Resilience

React to users

React to failures

Page 8: Reactiveness All The Way - SW Architecture 2015 Conference

8

Being Reactive

Responsive

Resilience

Message Driven

React to users

React to failures

React to messages

Page 9: Reactiveness All The Way - SW Architecture 2015 Conference

9

Being Reactive

Responsive

Elastic Resilience

Message Driven

React to users

React to failuresReact to load

React to messages

Page 10: Reactiveness All The Way - SW Architecture 2015 Conference

10

Being Reactive

Responsive

Elastic Resilience

Message Driven

React to users

React to failuresReact to load

React to messages

Page 11: Reactiveness All The Way - SW Architecture 2015 Conference

11

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

g(x)

f(x)UI eve

nts

Stock tickers

Page 12: Reactiveness All The Way - SW Architecture 2015 Conference

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

Page 13: Reactiveness All The Way - SW Architecture 2015 Conference

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

Page 14: Reactiveness All The Way - SW Architecture 2015 Conference

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

Page 15: Reactiveness All The Way - SW Architecture 2015 Conference

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

Page 16: Reactiveness All The Way - SW Architecture 2015 Conference

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://[email protected]:3232" } }}

Page 17: Reactiveness All The Way - SW Architecture 2015 Conference

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

Page 19: Reactiveness All The Way - SW Architecture 2015 Conference

Presenter contact detailst: @tamir_dreshere: [email protected]: TamirDresher.comw: www.codevalue.net