How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a...

51
How to use Akka to make a PERFECT Streaming system 钟翔@Intel

Transcript of How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a...

Page 1: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

How to use Akka to make a PERFECT

Streaming system钟翔@Intel

Page 2: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

What kind of streaming system we are talking?

2

A B C D

E

Processor

Processor Processor Processor

ProcessorDAG

Shuffle

Page 3: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

What is a perfect streaming system?

Page 4: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

It should be…

Page 5: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

High Throughput to Saturate network

Page 6: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Low latency to ms or us

Page 7: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Scale up to all CPU

Page 8: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Scale out to all machines

Page 9: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

No message loss

Page 10: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

No duplication

Page 11: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

No single point of failure

Page 12: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

No down time

Failure or

Upgrade

For

Page 13: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Flexible for different message source

• Any time

• Any where

• Any size

• Interconnect with other system

Page 14: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

• Exactly-once

• At-least once

• At most once

Flexible for different message guarantee

Page 15: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Flexible for different business

• Internet company

• Telecom

• Finance

• IT Service

• Education

• Medical care

• Public sector

Page 16: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Easy to study

Page 17: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Easy to troubleshoot

Page 18: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Easy to monitor

Page 19: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

One technologycan

meet all thesewith

Simplicity

Do you believe?

Page 20: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Akka make these unbelievable Simple

Page 21: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

It is like our human society, driven by messageWhich can scale to 7 billion population!

What is Akka?

• Micro-service(Actor) oriented.

Page 22: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

It is a NEW philosophy compare with OO

• Break your application into Micro services instead of object.

• Throw away locks

• Use Immutable Async message to exchange information instead of shared object.

Page 23: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Each micro-service only do ONE simple thing

and do it WELL

Then we can make a PERFECT

Big Data Streaming systemGearpump

Page 24: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

What is Gearpump

• Akka based lightweight Real time data processing platform.• Apache License http://gearpump.io

• Akka: • Communication, concurrency, Isolation, and fault-tolerant

Simple and Powerful

Message level streamingLong running daemons

24

Page 25: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Have doubts for Akka?

Page 26: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Will Akka impact Performance?

SOL Shuffle test32 tasks->32 tasks4 nodes 10GbE32 core E52680

Akka is efficient in sending message!

• In single JVM, It can process 50 million message per second.

• In a distributed environment, with simple extension to Akka, Gearpump can process 11 million message/second

Page 27: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

TaskTaskTask

Stable streaming with Flow Control

Pass back-pressure level-by-level

No need to worry OOM

27

TaskTaskTask TaskTaskTask TaskTaskTask

Back-pressure

Sliding window

Another option(not used): big-loop-feedback flow control

Page 28: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Will Akka introduce large latency?

• We implement a streaming system with

2ms Latency

Page 29: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

• Test run on 100 nodes and 3000 tasks

• Gearpump performance scales out:

29

100 nodes

How it scale up and scale out?

• To scale up, I can start 1000 tasks on my laptop

Page 30: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

What about HA?

Page 31: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Gearpump is born with HA

Use Actor Supervision tree for ONE application.Different application is isolated.

Master ClusterHA Design

Client

Hook in and query state

31

As general service

YARN

Page 32: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

WorkerWorkerWorker

Master

standbyMaster

StandbyMaster

State

Gossip

Master HA – no SPOF

• Akka Cluster for a centerless HA system• Akka Distributed Data to share global state

CRDT Data type example:

Decentralized: No central meta server

leader

32

Page 33: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Recover from failure instantly

Failure scenarios Recovery time [*]

comment

Cluster Master node Down

0 s Master HA take effect

Message loss ~ 300 ms Still optimizingTarget will be less than10ms

Application AppMaster down ~ 10 seconds timeout detection take a log time

Test environment: 91 worker nodes, 1000 tasks (We use 7 machines to simulate 91 worker nodes)[*]: Recovery time is the time interval between: a) failure happen b) all tasks in topology resume processing data.33

91 worker nodes, 1000 tasks

Page 34: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

What about handling message loss?

Page 35: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Use Application Clock to TrackMessage Loss

State

Minclock lowatermarkservice

Replayable Source DAG

Message withApplication Clock

35

Page 36: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Exactly-once with Checkpoint storems latency! No batching!

State

Minclock lowatermarkservice

Replayable Source DAG

Message withApplication Clock

36

Checkpoint Store

Exactly-once means error will NOTpropagate to future

Page 37: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Exactly-once support window operation

• Support Window based statistics

• Support Monoid, support application like:

– HyperLogLog: Unique visitor.

– Count-Min Sketch: page view

Page 38: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

How flexible can this streaming system be?

• Location transparent, Compute Anywhere, from Any source with Backpressure.

log

Data Center

dag on device side

Connect with Akka-stream is in plan

Page 39: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

How Flexible can this be?Scale out dynamically

• Change Parallelism dynamically in runtime

Page 40: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

How Flexible can this be?Dynamic DAG

Delete

• Dynamic Attach • Dynamic RemoveAdd Sub Graph

Dynamic Replace

B

Each node can has its own jar, with zero interference with each other

Page 41: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Is this streaming system easy?

Page 42: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

YES!

Page 43: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Three step to use it

1. Download binary from http://gearpump.io

2. Submit jar by UI

3. Monitor Status

Page 44: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

DAG Graph API Example - WordCountval context = new ClientContext()

val split = Processor[Split](splitParallism)

val sum = Processor[Sum](sumParallism)

val app = StreamApplication("wordCount", Graph(split ~> sum), UserConfig.empty)

val appId = context.submit(app)

context.close()

class Split(taskContext : TaskContext, conf: UserConfig) extends Task(taskContext, conf) {

override def onNext(msg : Message) : Unit = { /* split the line */ }

}

class Sum (taskContext : TaskContext, conf: UserConfig) extends Task(taskContext, conf) {

override def onNext(msg : Message) : Unit = {/* do aggregation on word*/}

}

44

Page 45: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

DSL API Example - WordCount

val context = ClientContext()

val app = new StreamApp("dsl", context)

val data = "This is a good start, bingo!! bingo!!"

app.fromCollection(data.lines)

// word => (word, count = 1)

.flatMap(line => line.split("[\\s]+")).map((_, 1))

// (word, count1), (word, count2) => (word, count1 + count2)

.groupByKey().sum.log

val appId = context.submit(app)

context.close()

45

Page 46: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

DAG Page

DAG Visualization

Track global min-Clock of all message DAG:

• Node size reflect throughput• Edge width represents flow rate• Red node means something goes wrong

46

Page 47: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

DAG VisualizationProcessor Page

Skew analysis Task throughput and latency

Executor JVM deployment

47

Page 48: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Easy to trouble-shooting

• Supervision chain

• All errors are handled as normal message

• When An error happen, we know

– When

– Where

– Why

Master

AppMaster

Executor

Task

Failure

Failure

Failure

Page 49: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Demo

Page 50: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Summary

All Akka technology

Simple, total 25 K line of code.

Easy to use, easy to trouble-shooting

Super flexible

Powerful dashboard.

Web site: http://gearpump.io

Source code: http://github.com/gearpump

Page 51: How to use Akka to make a - files.meetup.comfiles.meetup.com/18743046/How to use Akka to make a perfect intel... · Will Akka impact Performance? SOL Shuffle test 32 tasks->32 tasks

Team: 张天伦,王华峰,姜伟华,钟翔,徐骞

About US