reactive programming at scale

Post on 07-Jan-2017

705 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

ReactiveProgramming @ Scale

Paul Downey● Director of UI & APIs for demand advertising● Based in Dublin, Ireland● Email: paul.downey@teamaol.comJohn McClean● Systems Architect Demand Side Forecasting● Based in Dublin, Ireland.● Twitter: cyclops_aol● Medium: https://medium.com/@johnmcclean● Email: john.mcclean@teamaol.com

About Speakers

A

A

A

P

P

P

Exchange

RTB Ad Cycle

100 ms

20,000,000,000+

● Responsive

● Scale

● Resilient

● Capacity to process lots of data

System Requirements

Moore’s Law

7

Race Conditions

Deadlocks

Contention

Non-Deterministic State

Thread StarvationLivelocks

Amadahl’s Law

9

Concurrency in Practice.

Java Concurrency In Theory

11

Java Concurrency In Practice

12

Why is it like this?

13

Why is it like this?

14

Can we fix this?

15

What is Reactive?

16

What is Reactive?

17

Functional Reactive Programming?

Actor based concurrency?

Functional Reactive Programming.

Is it something new?

19

1997

Big in 1997?

20

Is it something new?

21

Well established on the front end

22

What is it?

Functional programming?

24

Functional programming

25

Less buggy code

Easier to parallelise

Easier to optimise

Reactive programming

26

Reactive pipeline manages flow

What not How

Reactive programming

27

What to do

Change each element by multiplying by 100

Remove all elements over 550

Print out each remaining element

Reactive programming

28

Composition

Change each element by multiplying by 100

Remove all elements over 550

Print out each remaining element

map(e -> e*100)

forEach(System.out::println)

filter(e->e<551)

Reactive programming

29

.map(e -> e*100)

.forEach(System.out::println)

.filter(e->e<551)

Example

ReactiveSeq.of(6,5,1,2)

A Reactive Pipeline

30

first stage second stage terminal stage

A Reactive Pipeline

31

first stage(map)

second stage(filter)

terminal stage (forEach)

A Reactive Pipeline

32

first stage(map)

second stage(filter)

terminal stage (forEach)

Data is pushed through the pipeline

500

2

1

5 600

Forecasting

Forecasting

34

Campaign Planning and Optimization

Query data across petabytes data

Accuracy & Responsiveness

Price / Volume Curve

Every Day We Process

36

Bid Request Records

Impression Records Viewability Records

20B 2B 2B

Indexing Data

37

Reactive Indexing

What we need to do

A Reactive Pipeline

40

first stage(map)

second stage(filter)

terminal stage (forEach)

Data is pushed through the pipeline

500

2

1

5 600

Scaling Up

41

first stage(map)

second stage(filter)

terminal stage (forEach)core 1

first stage(map)

second stage(filter)

terminal stage (forEach)core 2

first stage(map)

second stage(filter)

terminal stage (forEach)core 3

first stage(map)

second stage(filter)

terminal stage (forEach)core 4

Scaling Up for I/O

42

first stage(map)

second stage(filter)

terminal stage (forEach)

future 1

future 2

future 3

future 4

future 5

future 6

future 7

future 8

future 9

future 10 future

11

Performance Differences

43

What would the code look like?

Sequential Stream

45

.map(e -> e*100)

.forEach(System.out::println)

.filter(e->e<551)

Example

ReactiveSeq.of(6,5,1,2)

.futureOperations(executor)

Async I/O

46

.map(e -> e*100)

.filter(e->e<551)

Example

FutureW.of(()->loadData(6))

//non-blocking, FutureW executes asynchronously

.forEach(System.out::println)

Parallel Async Stream

47

.map(this::loadData)

.forEach(System.out::println)

.filter(e->e<551)

Example

new LazyReact(100).of(6,5,1,2)

What we need to do

Reactive Indexing Architecture

49

What have we learnt?

Conclusions

51

Conclusions

52

Conclusions

53

Thank You.

top related