58
Elasticity, Scalability & Location Transparency in Reactive Systems Deputy CTO @viktorklang

Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Embed Size (px)

Citation preview

Page 1: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Elasticity, Scalability &Location Transparencyin Reactive Systems

√Deputy CTO

@viktorklang

Page 2: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

1. Lead-In

2. Scale-Up

3. Scale-Out

4. Show-Down

2

Page 3: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

1. Lead-In

2. Scale-Up

3. Scale-Out

4. Show-Down

3

Page 4: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

The rules of the game

have changed

Page 5: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

5

Yesterday TodaySingle machines Clusters of machines

Single core processors Multicore processors

Expensive RAM Cheap RAM

Expensive disk Cheap disk

Slow networks Fast networks

Few concurrent users Lots of concurrent users

Small data sets Large data sets

Latency in seconds Latency in milliseconds

Page 6: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Tomorrow

Page 7: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

The Principles of Reactive Systems

Page 8: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Scale on Demand?

Why do we need to

Page 9: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

11

E l a s t i c i t y

«Lagom is a Swedish word, meaning "just the right amount"»

— Wikipedia

Page 10: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

scalability?what is

But

Page 11: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

15

“A service is said to be scalable if when we increase the resources in a system, it results in increased performance in

a manner proportional to resources added.” - Werner Vogels

Page 12: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

vs Scalability

Performance

Page 13: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

1. Lead-In

2. Scale-Up

3. Scale-Out

4. Show-Down

17

Page 14: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

UP

Scale

and down

Page 15: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

19

Modern CPU architecture

Page 16: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

The CPU is a notorious gambler

20

Page 17: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Maximize

Locality of Reference

Page 18: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Minimize

Contention

Page 19: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Common points of

23

ApplicationPhysical

contention

Page 20: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Block

24

Never ever

Page 21: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Async

25

BE

Page 22: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

26

NOTHINGshare

Page 23: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

DIVIDE&

conquer27

Page 24: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

28

Single Writer Principle

IO device

Producers

CONTENDED

IO device

Producers Writer

UNCONTENDED

Page 25: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

29

Page 26: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

30

Needs to be async and non-blockinga l l t h e w a y d o w n

Page 27: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

31

Universal Scalability Law

«N is the number of users;or the number of CPUs, is the contention level,α the coherency latency.β

C is the relative capacity»

Page 28: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Perfect

32

Load

Thro

ughp

ut

Page 29: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Imperfect

33

Load

Thro

ughp

ut

Page 30: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Bounded

34

Load

Thro

ughp

ut

Page 31: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Regressive

35

Load

Thro

ughp

ut

Page 32: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

The Role of Immutable State

• Great to represent facts

• Messages and Events

• Database snapshots

• Representing the succession of time

• Mutable State is ok if local and contained

• Allows Single-threaded processing

• Allows single writer principle

• Feels more natural

• Publish the results to the world as Immutable State

36

Page 33: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

on Demand

Scale

Page 34: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

1. Lead-In

2. Scale-Up

3. Scale-Out

4. Show-Down

38

Page 35: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

OUT

Scale

(and IN)

Page 36: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

• Mobile / IoT

• HTTP and Micro Services

• “NoSQL” DBs

• Big Data

• Fast Data

40

Distributed Computing is the new

normal

Page 37: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Reality check

• separation in space & time gives us

• communication for coordination

• variable delays

• partial failures

• partial/local/stale knowledge

41

Page 38: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Cluster/Rack/Datacenter

Cluster/Rack/Datacenter

Cluster/Rack/Datacenter

Middleware

Node Node Node

42

Node

Page 39: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

43

1. The network is reliable2. Latency is zero3. Bandwidth is infinite4. The network is secure5. Topology doesn't change6. There is one administrator7. Transport cost is zero8. The network is homogeneous

Peter Deutsch’s 8 Fallacies of

Distributed Computing

Page 40: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Maximize

Locality of Reference

Page 41: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Strong Consistency

Page 42: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

47

Linearizability

“Under linearizable consistency, all operations appear to have executed atomically in an order that is consistent with the

global real-time ordering of operations.” - Herlihy & Wing 1991

Page 43: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Strong Consistency Protocols

Page 44: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

(Coordination in the Cluster)

Minimize

Contention

Page 45: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

50

CAPTheorem

Page 46: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Consistency

Eventual

Page 47: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

52

CRDTCvRDTs/CmRDTs

Page 48: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

53

“In general, application developers simply do not implement large scalable applications assuming

distributed transactions.”- Pat Helland

Life beyond Distributed Transactions:

an Apostate’s Opinion

Page 49: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

The Event Log

• Append-Only Logging

• Database of Facts

• Two models:

• One single Event Log

• Strong Consistency

• Multiple sharded Event Logs

• Strong + Eventual Consistency

56

Page 50: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

1. Lead-In

2. Scale-Up

3. Scale-Out

4. Show-Down

57

Page 51: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

NOTHING

58

share

Page 52: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

TRANSPARENCY

59

location

Page 53: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

DataCenter

61

DataCenter

ClusterCluster MachineMachine JVMJVMNodeNode

ThreadThread CPUCPUCPU

SocketCPU

Socket

CPUCore

CPUCore

CPUL1/L2Cache

CPUL1/L2Cache

Page 54: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

62

Scaling Up / Out is essentially

the same thing

Page 55: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Elasticity requires amessage-drivenarchitecture

Page 56: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

Summary• Isolate & Contain + Distribute & Replicate

• Single Purpose Components

• Communicate asynchronously

• Divide & Conquer

• Avoid coordination & minimize contention

• Embrace inconsistency

• Strive for lagom amount of utilisation

64

Page 57: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems

EXPERT TRAININGDelivered on-site for Akka, Spark, Scala and Play

Help is just a click away. Get in touch with Typesafe about our training courses.

• Intro Workshop to Apache Spark • Fast Track & Advanced Scala• Fast Track to Akka with Java or Scala• Fast Track to Play with Java or Scala• Advanced Akka with Java or Scala

Ask us about local trainings available by 24 Typesafe partners in 14 countries around the world.

CONTACT US Learn more about on-site training

Page 58: Reactive Revealed Part 2: Scalability, Elasticity and Location Transparency in Reactive Systems