Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

37
Apache Flink™ deep- dive Unified Batch and Stream Processing Robert Metzger @rmetzger_ Hadoop Summit 2015, San Jose, CA

Transcript of Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Page 1: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Apache Flink™ deep-diveUnified Batch and Stream Processing

Robert Metzger@rmetzger_

Hadoop Summit 2015,San Jose, CA

Page 2: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Flink’s Recent History

April 2014 April 2015Dec 2014

Top Level Project Graduation

0.70.60.5 0.90.9-m1

Page 3: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

What is Flink

3

Gelly

Table

ML

SA

MO

A

DataSet (Java/Scala) DataStream

Hadoop M

/R

Local Remote YARN Tez Embedded

Data

flow

Data

flow

(W

iP)

MR

QL

Table

Casc

adin

g

(WiP

)

Streaming dataflow runtime

Zep

pelin

Page 4: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Program compilation

4

case class Path (from: Long, to: Long)val tc = edges.iterate(10) { paths: DataSet[Path] => val next = paths .join(edges) .where("to") .equalTo("from") { (path, edge) => Path(path.from, edge.to) } .union(paths) .distinct() next }

Optimizer

Type extraction

stack

Task schedulin

g

Dataflow metadata

Pre-flight (Client)

MasterWorkers

Data Sourceorders.tbl

Filter

Map DataSourcelineitem.tbl

JoinHybrid Hash

buildHT probe

hash-part [0] hash-part [0]

GroupRed

sort

forward

Program

Dataflow GraphIndependent of batch or streaming job

deployoperators

trackintermediate

results

Layered Architecture allows plugging of components

Page 5: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Native workload support

5

Flink

Streaming topologies

Long batchpipelines

Machine Learning at scale

How can an engine natively support all these workloads?And what does "native" mean?

Graph Analysis

Low latency

resource utilization iterative algorithms

Mutable state

Page 6: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

E.g.: Non-native iterations

6

Step Step Step Step Step

Client

for (int i = 0; i < maxIterations; i++) {// Execute MapReduce job

}

Teaching an old elephant new tricks Treat system as a black box

Page 7: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

E.g.: Non-native streaming

7

streamdiscretizer

Job Job Job Job

while (true) { // get next few records // issue batch job}

Data Stream

Simulate stream processor with batch system

Page 8: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Native workload support

8

Flink

Streaming topologies

Long batchpipelines

Machine Learning at scale

How can an engine natively support all these workloads?And what does "native" mean?

Graph Analysis

Low latency

resource utilization iterative algorithms

Mutable state

Page 9: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Ingredients for “native” support

1. Execute everything as streamsPipelined execution, push model

2. Special code paths for batchAutomatic job optimization, fault tolerance

3. Allow some iterative (cyclic) dataflows4. Allow some mutable state5. Operate on managed memory

Make data processing on the JVM robust

9

Page 10: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Flink by Use Case

10

Page 11: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Stream data processingstreaming dataflows

11

Full talk tomorrow:3:10PM, Grand Ballroom 220AStream processing with Flink

Page 12: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Pipelined stream processor

12

StreamingShuffle!

Low latency Operators push data

forward

Page 13: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

13

Expressive APIscase class Word (word: String, frequency: Int)

val lines: DataStream[String] = env.fromSocketStream(...)

lines.flatMap {line => line.split(" ").map(word => Word(word,1))} .window(Time.of(5,SECONDS)).every(Time.of(1,SECONDS)) .groupBy("word").sum("frequency") .print()

val lines: DataSet[String] = env.readTextFile(...)

lines.flatMap {line => line.split(" ").map(word => Word(word,1))} .groupBy("word").sum("frequency") .print()

DataSet API (batch):

DataStream API (streaming):

Page 14: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Checkpointing / Recovery

14

Chandy-Lamport Algorithm for consistent asynchronous distributed snapshots

Pushes checkpoint barriersthrough the data flow

Data Stream

barrier

Before barrier =part of the snapshot

After barrier =Not in snapshot

(backup till next snapshot)

Guarantees exactly-once processing

Page 15: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Batch processingBatch on Streaming

15

Page 16: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

16

Batch on an streaming engine

File in HDFS

Filter Map Result 1

Map Result 2

Batch program, completely pipelined Data is never materialized anywhere (in this example)

Page 17: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

17

Batch on an streaming engine

MapOperator

MapOperator

MapOperator

Data Source (small)

Stream

Stream

Stream

Data Sink

Data Sink

Data Sink

JoinOperator

Stream build side

in parallel

Data Source (large)

Data Sink

in parallel (once build side finished)

Map

Stream probe side

Page 18: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Batch processing requirements

Get the data processed as fast as possible• Automatic job optimizer• Efficient memory management

Robust processing• provide fault-tolerance• again, memory management

18

Page 19: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Optimizer Cost-based optimizer Select data shipping strategy (forward, partition, broadcast) Local execution (sort merge join/hash join) Caching of loop invariant data (iterations)

19

case class Path (from: Long, to: Long)val tc = edges.iterate(10) { paths: DataSet[Path] => val next = paths .join(edges) .where("to") .equalTo("from") { (path, edge) => Path(path.from, edge.to) } .union(paths) .distinct() next }

Optimizer

Type extraction

stack

Pre-flight (Client)Data

Sourceorders.tbl

Filter

MapDataSour

celineitem.tbl

JoinHybrid Hash

buildHT

probe

hash-part [0] hash-part [0]

GroupRed

sort

forward

Program

DataflowGraph

Page 20: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

20

Two execution plans

DataSourceorders.tbl

Filter

Map DataSourcelineitem.tbl

JoinHybrid Hash

buildHT probe

broadcast forward

Combine

GroupRed

sort

DataSourceorders.tbl

Filter

Map DataSourcelineitem.tbl

JoinHybrid Hash

buildHT probe

hash-part [0] hash-part [0]

hash-part [0,1]

GroupRed

sort

forwardBest plan

depends onrelative sizes of

input files

Page 21: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

21

Memory Management

Page 22: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Operators on managed memory

22

Page 23: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Smooth out-of-core performance

23More at: http://flink.apache.org/news/2015/03/13/peeking-into-Apache-Flinks-Engine-Room.html

Blue bars are in-memory, orange bars (partially) out-of-core

Page 24: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Machine Learning AlgorithmsIterative data flows

24

Page 25: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

26

Iterate in the Dataflow

API and runtime support Automatic caching of loop invariant

data

IterationState state = getInitialState(); while (!terminationCriterion()) {

state = step(state); } setFinalState(state);

Page 26: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Example: Matrix Factorization

27

Factorizing a matrix with28 billion ratings forrecommendations

More at: http://data-artisans.com/computing-recommendations-with-flink.html

Setups:• 40 medium instances ("n1-highmem-8" - 8

cores, 52 GB)• 40 large instances ("n1-highmem-16" - 16

cores, 104 GB)

Page 27: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

28

Flink ML – Machine Learning Provide a complete toolchain

• scikit-learn style pipelining• Data pre-processing

various algorithms • Recommendations: ALS• Supervised learning: Support Vector Machines• …

ML on streams: SAMOA. We are planning to add support for streaming into ML

Page 28: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Graph AnalysisStateful Iterations

29

Page 29: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Graph processing characteristics

# o

f ele

men

ts u

pd

ate

d

iteration

Page 30: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

31

Iterate natively with state/deltas Keep state in an controlled way by having a partitioned hash-

map Relax immutability assumption of batch processing

Page 31: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

32

… fast graph analysis

More at: http://data-artisans.com/data-analysis-with-flink.html

Page 32: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

33

Gelly – Graph Processing API

Transformations: map, filter, subgraph, union, reverse, undirected

Mutations: add vertex/edge, remove … Pregel style vertex centric iterations Library of algorithms Utilities: Special data types, loading, graph properties

Page 33: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Gelly and Flink ML:

Available in Flink 0.9 (so far only beta release) Still under heavy development Seamlessly integrate with DataSet abstraction

Preprocess data as neededUse results as needed

Easy entry point for new contributors

34

Page 34: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Closing

35

Page 35: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Flink Meetup Groups

SF Spark and Friends• June 16, San Francisco

Bay Area Flink Meetup• June 17, Redwood City

Chicago Flink Meetup• June 30

Stockholm, Sweden Berlin, Germany

36

Page 36: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

Flink Forward registration & call for abstracts is open now

flink.apache.org 37

• 12/13 October 2015• Meet developers and users of

Flink!• With Flink Workshops / Trainings!

Page 37: Apache Flink Deep-Dive @ Hadoop Summit 2015 in San Jose, CA

flink.apache.org@ApacheFlink