microservice protocols of interaction

88
Microservice Protocols of Interaction Todd L. Montgomery @toddlmontgomery

Upload: todd-montgomery

Post on 15-Apr-2017

358 views

Category:

Software


3 download

TRANSCRIPT

Page 1: Microservice Protocols of Interaction

Microservice Protocols of Interaction

Todd L. Montgomery @toddlmontgomery

Page 2: Microservice Protocols of Interaction

About me…

Page 3: Microservice Protocols of Interaction

What is a Protocol?

Why should we care!?

Page 4: Microservice Protocols of Interaction

@toddlmontgomery

pro·to·col noun \ˈprō-tə-ˌko ̇l, -ˌkōl, -ˌkäl, -kəl\

...

3 b : a set of conventions governing the treatment and especially the formatting of data in an electronic communications system <network protocols>

...

3 a : a code prescribing strict adherence to correct etiquette and precedence (as in diplomatic exchange and in the military services) <a breach of protocol>

Page 5: Microservice Protocols of Interaction

Protocols of Interaction

Wire Protocol, Method Calls, Shared Memory Interactions, etc.

Page 6: Microservice Protocols of Interaction

Microservice Architectures

Page 7: Microservice Protocols of Interaction

Forced Decoupling

via an“Asynchronous, Binary Boundary”

Page 8: Microservice Protocols of Interaction

Forced Loose Coupling

Page 9: Microservice Protocols of Interaction

The truth is…

Protocols can and do Couple

Page 10: Microservice Protocols of Interaction

Protocols of Interactionare quite important!

Protocols of Interaction Matter!

Page 11: Microservice Protocols of Interaction

The Environment

Page 12: Microservice Protocols of Interaction

Networks, and especially the Internet,are Hostile Environments

Page 13: Microservice Protocols of Interaction
Page 14: Microservice Protocols of Interaction

Data can be lost,

duplicated, and re-ordered!!

Page 15: Microservice Protocols of Interaction

TCP connections can…

be closedunexpectedly

end in anunknown state

be interceptedby idiots, er Proxies

Page 16: Microservice Protocols of Interaction

Duplicated

Re-Ordered

Lost

Which meansData over TCP* might be…

* - When connections are re-established

Page 17: Microservice Protocols of Interaction

Don’t assume the networkis reliable

https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing

Page 18: Microservice Protocols of Interaction

Case Studies

Page 19: Microservice Protocols of Interaction

Case Study 1

Loose Ordering

Page 20: Microservice Protocols of Interaction

@toddlmontgomery

SyncRequests

&Responses

Request

Request

RequestResponse

Response

Response

Throughput limited by Round-Trip Time (RTT)!

Page 21: Microservice Protocols of Interaction

@toddlmontgomery

AsyncRequests

&Responses

Request

Request

RequestResponse

Response

Response

Throughput less limited by Round-Trip Time!

Page 22: Microservice Protocols of Interaction

@toddlmontgomery

AsyncRequests

&Responses

Correlation!

Request 0

Request 1

Request 2Response 0

Response 1

Response 2

Page 23: Microservice Protocols of Interaction

Aside…

Page 24: Microservice Protocols of Interaction

Ordering is an Illusion!!

Page 25: Microservice Protocols of Interaction

Compiler can re-order

Runtime can re-order

CPU can re-order

Page 26: Microservice Protocols of Interaction

Ordering has to be imposed!

Page 27: Microservice Protocols of Interaction

@toddlmontgomery

AsyncRequests

&Responses

Correlation!

Request 0

Request 1

Request 2Response 0

Response 1

Response 2

Page 28: Microservice Protocols of Interaction

@toddlmontgomery

Correlation!

Request 0

Request 1

Request 2Response 0

Response 1

Response 2

Ordering

Page 29: Microservice Protocols of Interaction

@toddlmontgomery

Correlation!

Request 0

Request 1

Request 2

Response 0

Response 1

Response 2

(Valid)Re-Ordering

(one of many)

Page 30: Microservice Protocols of Interaction

@toddlmontgomery

Handling the Unexpected

Request 0Response 1

Invalid, Drop We only know of 0.1 is unknown!

Page 31: Microservice Protocols of Interaction

SCTPHTTP/2 (SPDY)

…most OSI Layer 4 protocols

Page 32: Microservice Protocols of Interaction

Case Study 2

Can you hear me now?Timeouts & Retries

Page 33: Microservice Protocols of Interaction

@toddlmontgomery

Request

ACK

Processing

Handling the unexpected

Page 34: Microservice Protocols of Interaction

@toddlmontgomery

Request

Tim

eout

Inte

rval

X

Page 35: Microservice Protocols of Interaction

@toddlmontgomery

Request

ACK

Processing

XTi

meo

ut In

terv

al

Retransmit at end of interval

Page 36: Microservice Protocols of Interaction

@toddlmontgomery

ACK

Processing…

Avoid Spurious Retransmits

Retransmit

Original

Tim

eout

Inte

rval

Page 37: Microservice Protocols of Interaction

@toddlmontgomery

Interval = N x “typical” RTT

Account for processing delay

XTi

meo

ut In

terv

al

“Average”

Page 38: Microservice Protocols of Interaction

@toddlmontgomery

Measure! But very “noisy”?

RTT

Mea

sure

men

t

Variances inprocessing,

transmission,etc.

Page 39: Microservice Protocols of Interaction

TCP Retransmit Timeout (RTO)

Err = M - A A <- A + gErrD <- D + h(|Err| - D)RTO = A + 4D

M = measurement, A = smoothed average, D = smoothed mean deviation,

g and h = gain constants (0 to 1)

Page 40: Microservice Protocols of Interaction

TCP Retransmit Timeout (RTO)

Err = M - A A <- A + gErrD <- D + h(|Err| - D)RTO = A + 4D

Do you measure on a Retransmit? NO!

Page 41: Microservice Protocols of Interaction

@toddlmontgomery

Does processing twice hurt?

X

Original

ACK

Retrans

Process Once

Process Twice

Tim

eout

Inte

rval

Page 42: Microservice Protocols of Interaction

@toddlmontgomery

Are Original & Retransmit treated the same?

X

Original

ACK

Retrans

Process Once

Process Twice

Tim

eout

Inte

rval

Page 43: Microservice Protocols of Interaction

TCPSCTPAeron

…anything with reliability

Page 44: Microservice Protocols of Interaction

Case Study 3

What I Need! When I Need It!“Lifetime” Management

Page 45: Microservice Protocols of Interaction

“Managing” Application Working Set

or

Service Liveness

Page 46: Microservice Protocols of Interaction

Caching Algorithms

LRU, MRU, PLRU, RR,SLRU, LFU, …

“Liveness” is essential

Page 47: Microservice Protocols of Interaction
Page 48: Microservice Protocols of Interaction

@toddlmontgomery

Request

ACK

Service Ais Alive!

Service Bis Alive!

Service A Service B

Consequence of Processing

Page 49: Microservice Protocols of Interaction

@toddlmontgomery

Keepalive

Keepal

ive

Service Ais Alive!

Service Bis Alive!

Service A Service B

Absence of Processing

Page 50: Microservice Protocols of Interaction

RIP Route Deletion

Step 0 - route info broadcast @30 secondsStep 1 (3 min) - Set Distance to Infinity (16) Step 2 (+1 min) - Delete Route

Aside… RIP… aptly named

Page 51: Microservice Protocols of Interaction

Aeron Driver Keepalive

Time of Last Activity = Shared Variable

Doesn’t need to be a message…

Page 52: Microservice Protocols of Interaction

@toddlmontgomery

Bye

Bye

Service Ais gone!

Service Bis gone!

Service A Service B

Optimization, but insufficient with arbitrary failures

Page 53: Microservice Protocols of Interaction

Liveness often exists acrosstransient connectivity

Page 54: Microservice Protocols of Interaction

So…Don’t conflate transport

state with liveness!

Like TCP connection state

Page 55: Microservice Protocols of Interaction

Dead TCP connection !=

Dead Service

Page 56: Microservice Protocols of Interaction

Live TCP connection !=

Live Service

Page 57: Microservice Protocols of Interaction

BGPOSPF

Transports…

almost every protocol

Page 58: Microservice Protocols of Interaction

Case Study 4

Elasti-What?Self-Similar Behavior

Page 59: Microservice Protocols of Interaction

Request X

Request X

Request X

Request X, X, X

Multiple same/similar requests at the same time

Response X, X, X

Page 60: Microservice Protocols of Interaction

Similar Problem…

Reliable Multicast

Page 61: Microservice Protocols of Interaction

1, 2, 3

1, 2, 3 1, 2, 3 1, 2, 3

Non-correlated loss

X X X

Page 62: Microservice Protocols of Interaction

NAK 1, 2, 3

NAK 2

NAK 1

NAK 3

Request individual lost data

Retransmit 1, 2, 3

Page 63: Microservice Protocols of Interaction

1, 2, 3

1, 2, 3 1, 2, 3 1, 2, 3

Temporally/Spatially Correlated Loss

X X X

Page 64: Microservice Protocols of Interaction

NAK 2

NAK 2

NAK 2

NAK 2, 2, 2

Multiple requests for same data

Retransmit 2, 2, 2

Page 65: Microservice Protocols of Interaction

Request 2

Request 2

Request 2

Request 2, 2, 2

It’s a generic problem!

Page 66: Microservice Protocols of Interaction

Request 2

Request 2

Request 2

Request 2, 2, 2

Overloading Responder & Network

Page 67: Microservice Protocols of Interaction
Page 68: Microservice Protocols of Interaction

Request 2

Publish RequestsDon’t Immediately Request, Listen first

Timeout!Request

2Request

2

Suppress Request

Page 69: Microservice Protocols of Interaction

Request 2

How long to wait & listen for?

Timeout!Request

2Request

2

Suppress Request

Page 70: Microservice Protocols of Interaction

Statistics to the Rescue!

Page 71: Microservice Protocols of Interaction

SRM Backoff

RandomBackoff = [C1, C1+C2] * 1-way delay

Random is more than good enough

Page 72: Microservice Protocols of Interaction

Request 2

Request 2

Request 2, 2

Must also shed duplicates on the responder

Response 2, 2

Shed second “Request 2” if too soon

X

X

Page 73: Microservice Protocols of Interaction

SRMPGMAeron

http://en.wikipedia.org/wiki/Scalable_Reliable_Multicasthttp://www.eurecom.fr/en/publication/107/detail/optimal-multicast-feedback

Page 74: Microservice Protocols of Interaction

Case Study 5

Hey, Slow Down!Flow (& Congestion) Control

Page 75: Microservice Protocols of Interaction
Page 76: Microservice Protocols of Interaction

@toddlmontgomery

Data

Data

DataACK

ACK

ACK

Throughput = Data Length / RTT

RTT

Stop-And-WaitFlow Control

Page 77: Microservice Protocols of Interaction

Delay

Bandwidth

BDP = (Byte / sec) * sec = Bytes

BDP(Buffer)

Page 78: Microservice Protocols of Interaction

@toddlmontgomery

Data

ACKRT

T

Throughput = N * Data Length / RTT

… N Data“Blobs”

Page 79: Microservice Protocols of Interaction

So…How big is N?

This is surprisingly hard to answer

Page 80: Microservice Protocols of Interaction

It depends…

Page 81: Microservice Protocols of Interaction

Big… but

Don’t overflow receiver

Don’t overflow “network”

Page 82: Microservice Protocols of Interaction

TCP Flow Control

Receiver advertises N

Page 83: Microservice Protocols of Interaction

TCP Congestion Control

Sender probes for network N

Page 84: Microservice Protocols of Interaction

TCP Sender

min(Receiver N, Network N)

Only go as fast as Network & Receiver

Page 85: Microservice Protocols of Interaction

ReactiveStreams

Subscriber uses explicit request(N)

Publisher assumes best case

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

Page 86: Microservice Protocols of Interaction

Takeaways!

Page 87: Microservice Protocols of Interaction

Protocols of interaction are important & can be tremendously impactful

for better or worse…

Page 88: Microservice Protocols of Interaction

@toddlmontgomery

Questions?

• IETF http://www.ietf.org/• Aeron https://github.com/real-logic/Aeron• Twitter @toddlmontgomery

Thank You!