Designing for concurrency and performance

60
Designing for Concurrency & Performance Vikas Hazrati Knoldus Software LLP

description

Knoldus speaking at the IndicThreads 2013 conference in New Delhi on how Scala and Akka can help in building reactive applications. References 1) Concurrency talk to Klang and Kuhn at ScalaDays 2013 2) Reactive applications talk by Boner at ScalaDays 2013 3) Reactive Manifesto 4) Blog.knoldus.com

Transcript of Designing for concurrency and performance

Page 1: Designing for concurrency and performance

Designing for Concurrency & Performance

Vikas Hazrati

Knoldus Software LLP

Page 2: Designing for concurrency and performance

2

vikas hazrati

CTO and Co-Founder @ Knoldus Software

16 years

Still on the JVM though with Scala

Big data systems with massive computations

Page 3: Designing for concurrency and performance

3

concurrency & performance

»What?

Page 4: Designing for concurrency and performance

4

Page 5: Designing for concurrency and performance

5

Page 6: Designing for concurrency and performance

6

performance == scalability ?

Page 7: Designing for concurrency and performance

7

performance != scalability

Page 8: Designing for concurrency and performance

8

Page 9: Designing for concurrency and performance

9

latency == throughput

Page 10: Designing for concurrency and performance

10

ways to manage concurrency

Page 11: Designing for concurrency and performance

11

threads

Mapped to cpuMapped to cpu

High degree of control

To the metal – no overhead

heavyweight

scarce

heavyweight

Diminishing returns

Low level

Failure recovery hard

Threadsafe?

locks?

Ordering of locks?

Page 12: Designing for concurrency and performance

12

executor

Mapped to cpuconfigurable

Higher level abstraction

Maintain thread ratio

heavyweight

blocking

Error handling

Easy closure overstate

Failure recovery hard

Call back hell?

Low reusability?

Sync or async

Less jmm headache

Higher level abstraction

Page 13: Designing for concurrency and performance

13

stm

Mapped to cputypesafe

transactional

Non blocking

heavyweight

contention

size

Reruns while in contention

Side effect in retries?

Failure handling?

Unpredictableperformance

composable Debugging is hard

Page 14: Designing for concurrency and performance

14

futures

Mapped to cputypesafe

configurable

Non blocking

heavyweight

Can close overMutable state

Error handling to callee

Ordering of callbacks

Callback hell

Recover with lock

composable

freely sharable

Page 15: Designing for concurrency and performance

15

concurrency is hard!

Page 16: Designing for concurrency and performance

16

is performance any simpler?

Page 17: Designing for concurrency and performance

17

today's systems

Scalable

Failure resistant

Quick response

React to events

Page 18: Designing for concurrency and performance

18

they need to be REACTIVE!

Page 19: Designing for concurrency and performance

19

Page 20: Designing for concurrency and performance

20

understand the tradeoffs

Performance Scalability

Throughput Latency

Availability Consistency

Page 21: Designing for concurrency and performance

21

things to remember

Page 22: Designing for concurrency and performance

22

event driven

Page 23: Designing for concurrency and performance

23

indeterministic need locks

threads and shared mutable state

Page 24: Designing for concurrency and performance

24

locks

break encapsulation

never sure of the right amount

deadlocks

error recovery is hard

Page 25: Designing for concurrency and performance

25

never block

kills scalability and performance

wastes resources

use non blocking IO

lock free concurrency

Page 26: Designing for concurrency and performance

26

go parallel

Page 27: Designing for concurrency and performance

27

percentage of code in parallel

Page 28: Designing for concurrency and performance

28

react to load

scalability

Page 29: Designing for concurrency and performance

29

location transparency

Page 30: Designing for concurrency and performance

30

go event driven

Page 31: Designing for concurrency and performance

31

how to go event driven?

Shared nothing

Lightweight

Async message passing

Non-blocking

Location transparent

Mailbox

Page 32: Designing for concurrency and performance

32

resilience

Page 33: Designing for concurrency and performance

33

fault tolerance

Isolate

Compartmentalize

Local resolution

Avoid cascades

Page 34: Designing for concurrency and performance

34

fault tolerance

Errors handled by Supervisor

In async mode

Supervisor can kill / start /Manage/ resume

Page 35: Designing for concurrency and performance

35

responsive

Page 36: Designing for concurrency and performance

36

responsive

throughput

latency

Page 37: Designing for concurrency and performance

37

Page 38: Designing for concurrency and performance

38

Page 39: Designing for concurrency and performance

39

batch em

Page 40: Designing for concurrency and performance

40

Page 41: Designing for concurrency and performance

41

Page 42: Designing for concurrency and performance

42

Page 43: Designing for concurrency and performance

43

Page 44: Designing for concurrency and performance

44

Page 45: Designing for concurrency and performance

45

how?

Page 46: Designing for concurrency and performance

46

Page 47: Designing for concurrency and performance

47

Page 48: Designing for concurrency and performance

48

Page 49: Designing for concurrency and performance

49

actor

Embodies

ProcessingStorage

Communication

Page 50: Designing for concurrency and performance

50

actors

Mapped to cpuencapsulation

configurable

Fault tolerant

heavyweight

Lifecycle management

untyped Easy to violateencapsulation

Location trasparency

Models real world

Page 51: Designing for concurrency and performance

51

distributable by design

Location Transparent

Scale up and down

Fault tolerant

Adaptive load balancing

Extremely looselycoupled

Page 52: Designing for concurrency and performance

52

fault tolerant

Page 53: Designing for concurrency and performance

53

Page 54: Designing for concurrency and performance

54

Page 55: Designing for concurrency and performance

55

Page 56: Designing for concurrency and performance

56

Page 57: Designing for concurrency and performance

57

Page 58: Designing for concurrency and performance

58

Page 59: Designing for concurrency and performance

59

Page 60: Designing for concurrency and performance

60

[email protected]

@vhazrati

Www.knoldus.com

@knolspeak