Reactsf 2014-message-driven

Post on 02-Jul-2015

757 views 0 download

description

To Be Message Driven from React SF 2014

transcript

To Be Message-Driven

Todd L. Montgomery @toddlmontgomery

Life is Message Driven

CPUs are Message Driven

Browsers are “Message” Driven

Why is this?

The most scalable, resilient, &fast systems seem to followsome common principles…

Facilitating other traits

Why Message Driven?

It’s not what Message Passing provides…

It’s what Message Passing makes harder or even impossible

Boundaries

Boundaries are Good!

Forced Decoupling & Separation of Concerns

BinaryBoundary

AsynchronousBoundary

Ordering Errors asMessages

Asynchronous, BinaryBoundaries

Asynchronous

@toddlmontgomery

Request

Response

ProcessingCould do stuff while waiting!

Waiting at the mailbox…

Even traditional blocking operations can be decoupled

@toddlmontgomery

AsyncRequests

&Responses

Request

Request

RequestResponse

Response

Response

@toddlmontgomery

AsyncRequests

&Responses

Correlation!

Request 0

Request 1

Request 2Response 0

Response 1

Response 2

@toddlmontgomery

Correlation!

Request 0

Request 1

Request 2Response 0

Response 1

Response 2

Ordering

@toddlmontgomery

Correlation!

Request 0

Request 1

Request 2

Response 0

Response 1

Response 2

(Valid)Re-Ordering

@toddlmontgomery

Handling the Unexpected

Request 0

Response 1

Invalid, Drop We only know of 0.1 is unknown!

Binary

.addPayment(5)

Without a binary boundary,too easy to couple & conflate

struct PaymentMessage{ std::int32_t accountId; std::int32_t amount;};

When all you have is binary,harder to couple and/or conflate

Ordering

Duplicated

Re-Ordered

Lost

Packets, nay Messages!, Can Be…

TCP connections can…

be closedunexpectedly

end in anunknown state

be interceptedby idiots, er Proxies

Duplicated

Re-Ordered

Lost

Which meansData over TCP* might be…

* - When connections are re-established

Ordering is an Illusion!!

Compiler can re-order

Runtime can re-order

CPU can re-order

Which is whyLock-Free Programmingshares some behaviors

with Protocols…

Java

x86

C++11

http://en.wikipedia.org/wiki/Memory_ordering

Source Ordering

Message A and B from same source are ordered

Total Ordering

Message A and B from any 2+ sources are ordered the same at all destinations

Illusion of Ordering… bordering on “Delusion”

Causal Ordering

Message A and B from any source are ordered if B causally relates to A

Ordering can just fall out

0 1 2 3 4 5 6 7 8

0 1 3 4 5 6 7

2 8

S:

R:

File to Transfer

Recover

0 X bytes

Clark and Tennenhouse, ACM SIGCOMM CCR, Volume 20, Issue 4, Sept. 1990

Application Layer Framing

Dead Reckoning about Ordering!

Most of the time, Orderingsimply isn’t enough

Duplicated

Re-Ordered

Lost

Messages Can Be…

Transition Table?

Java enums?

JavaScript prototypes?

Table with Lambdas!?

public void onAck(final Event ev){

switch (currentState){

…case State.FIN_WAIT_1: // an ACK while in FIN_WAIT_1

currentState = State.FIN_WAIT_2;break;

…}

}

Event

CurrentState

NextState

State & Eventsbe explicit, do not hide behind

abstraction(s) Make them Observable!

State Machines…worth your time

RST

SimultaneousOpen

Closing &Dupes, etc.

State Machine Testing

1. Does my “code” implement it correctly?2. Is my design safe, correct, etc.?

VLSI Testing Techniquese.g. ARC/Branch Testing

Model Checking

SPIN

http://en.wikipedia.org/wiki/SPIN_model_checker

2002 ACM System Software Award

TLA+

http://research.microsoft.com/en-us/um/people/lamport/tla/tla.html

Idempotent Unit of WorkADU

1. Little to no ordering requirement2. Little to no state requirement

e.g. RESTThat stateless bit…

Responsive

No/Less waiting & No/Less contention…

Resilient

No/Less waiting & No/Less state…

Elastic

No contention, no shared state…

Because Amdahlwill hunt you down

@toddlmontgomery

Questions?

• Reactive Manifesto http://www.reactivemanifesto.com• Kaazing http://www.kaazing.com• SlideShare http://www.slideshare.com/toddleemontgomery• Twitter @toddlmontgomery

Thank You!