• No results found

Spark: Making Big Data Interactive & Real-Time

N/A
N/A
Protected

Academic year: 2021

Share "Spark: Making Big Data Interactive & Real-Time"

Copied!
52
0
0

Loading.... (view fulltext now)

Full text

(1)

Matei Zaharia

UC Berkeley / MIT

www.spark-project.org

Spark: Making Big Data

Interactive & Real-Time

(2)

What is Spark?

Fast and expressive cluster computing system compatible with Apache Hadoop

Improves efficiency through:

»General execution graphs

»In-memory storage

Improves usability through:

»Rich APIs in Scala, Java, Python

»Interactive shell

Up to 10× faster on disk, 100× in memory

2-5× less code

(3)

Project History

Spark started in 2009, open sourced 2010 In use at Yahoo!, Intel, Adobe, Quantifind, Conviva, Ooyala, Bizo and others

24 companies now contributing code spark.incubator.apache.org

(4)

A Growing Stack

Part of the Berkeley Data Analytics Stack (BDAS) project to build an open source next-gen analytics system

Spark Spark

Streaming

real-time

Shark

SQL GraphX

graph

MLbase

machine learning

(5)

This Talk

Spark introduction & use cases Shark: SQL on Spark

Spark Streaming

The power of unification

(6)

Why a New Programming Model?

MapReduce greatly simplified big data analysis But as soon as it got popular, users wanted more:

»More complex, multi-pass analytics (e.g. ML, graph)

»More interactive ad-hoc queries

»More real-time stream processing

All 3 need faster data sharing across parallel jobs

(7)

Data Sharing in MapReduce

iter. 1 iter. 2 . . .

Input

HDFS

read HDFS

write HDFS

read HDFS write

Input

query 1 query 2 query 3

result 1

result 2

result 3 . . .

HDFS read

Slow due to replication, serialization, and disk IO

(8)

iter. 1 iter. 2 . . . Input

Data Sharing in Spark

Distributed memory Input

query 1 query 2

query 3 . . .

one-time processing

10-100× faster than network and disk

(9)

Spark Programming Model

Key idea: resilient distributed datasets (RDDs)

»Distributed collections of objects that can be cached in memory across cluster

»Manipulated through parallel operators

»Automatically recomputed on failure

Programming interface

»Functional APIs in Scala, Java, Python

»Interactive use from Scala & Python shells

(10)

Example: Log Mining

Load error messages from a log into memory, then interactively search for various patterns

lines = spark.textFile(“hdfs://...”)

errors = lines.filter(_.startsWith(“ERROR”)) messages = errors.map(_.split(‘\t’)(2))

messages.cache()

Block 1

Block 2 Block 3

Worker

Worker

Worker Driver

messages.filter(_.contains(“foo”)).count messages.filter(_.contains(“bar”)).count . . .

tasks results

Cache 1

Cache 2 Cache 3

Base RDD Transformed RDD

Action

Result: full-text search of Wikipedia in <1 sec (vs 20 sec for on-disk data) Result: scaled to 1 TB data in 5-7 sec

(vs 170 sec for on-disk data)

(11)

Fault Tolerance

file.map(rec => (rec.type, 1)) .reduceByKey(_ + _)

.filter((type, count) => count > 10)

filter reduce

map

Input file

RDDs track lineage information to rebuild on failure

(12)

filter reduce

map

Input file

Fault Tolerance

file.map(rec => (rec.type, 1)) .reduceByKey(_ + _)

.filter((type, count) => count > 10)

RDDs track lineage information to rebuild on failure

(13)

Example: Logistic Regression

Goal: find best line separating two sets of points

target

random initial line

(14)

Example: Logistic Regression

val data = spark.textFile(...).map(readPoint).cache()

var w = Vector.random(D)

for (i <- 1 to ITERATIONS) { val gradient = data.map(p =>

(1 / (1 + exp(-p.y*(w dot p.x))) - 1) * p.y * p.x ).reduce(_ + _)

w -= gradient }

println("Final w: " + w)

(15)

Logistic Regression Performance

0 500 1000 1500 2000 2500 3000 3500 4000

1 5 10 20 30

Running Time (s)

Number of Iterations

Hadoop Spark

110 s / iteration

first iteration 80 s further iterations 1 s

(16)

Supported Operators

map

filter groupBy sort

union join

leftOuterJoin rightOuterJoin

reduce count fold

reduceByKey groupByKey cogroup

cross zip

sample take first

partitionBy mapWith

pipe save ...

(17)

Spark in Python and Java

// Python:

lines = sc.textFile(...)

lines.filter(lambda x: “ERROR” in x).count()

// Java:

JavaRDD<String> lines = sc.textFile(...);

lines.filter(new Function<String, Boolean>() { Boolean call(String s) {

return s.contains(“error”);

}

}).count();

(18)

1000+ meetup members 80+ contributors

24 companies contributing

User Community

(19)

Generality of RDDs

RDD model was general enough to let us implement several previous models:

»MapReduce, Dryad

»Pregel [200 LOC]

»Iterative MapReduce [200 LOC]

»GraphLab [600 LOC]

»SQL (Shark) [6000 LOC]

Allows apps to intermix these models

(20)

This Talk

Spark introduction & use cases Shark: SQL over Spark

Spark Streaming

The power of unification

(21)

Conventional Wisdom

MPP databases 10-100x faster than MapReduce

(22)

Why Databases Were Faster

Data representation

»Schema-aware, column-oriented, etc

»Compare with MapReduce’s “record” model

Indexing

Lack of mid-query fault tolerance

»MR’s “pull” model costly compared to “push”

(23)

Shark

Provides fast SQL queries on a MapReduce-like engine (Spark), and retains full fault tolerance

1.7 TB data 100 nodes

10-100x faster than Hive

Within 2-3x of Amazon Redshift

(24)

But What About…

Data representation?

»Can do it inside MapReduce records

»In Shark, a “record” is a set of rows

»Implemented columnar storage within these

Indexing?

»Can still read indices in MR

Mid-query fault tolerance?

»We have it, but we still perform OK

»Also enables elasticity, straggler mitigation

(25)

Implementation

Port of Apache Hive

»Supports unmodified Hive data and warehouses

Efficient mixing with Spark code (e.g. machine learning functions) in the same system

(26)

This Talk

Spark introduction & use cases Shark: SQL over Spark

Spark Streaming

The power of unification

(27)

Many important apps must process large data streams at second-scale latencies

»Site statistics, intrusion detection, online ML

To scale these apps to 100s of nodes, require:

»Fault-tolerance: both for crashes and stragglers

»Efficiency: low cost beyond base processing

Current steaming systems don’t meet both goals

Motivation

(28)

Traditional Streaming Systems

Continuous operator model

»Each node has mutable state

»For each record, update state & send new records

mutable state

node 1

node 3

input records push

node 2 input records

(29)

Traditional Streaming Systems

Fault tolerance via replication or upstream backup:

node 1

node 3 node 2

node 1’

node 3’

node 2’

synchronization

node 1

node 3 node 2

standby input

input

input

input

(30)

Traditional Streaming Systems

Fault tolerance via replication or upstream backup:

node 1

node 3 node 2

node 1’

node 3’

node 2’

synchronization

node 1

node 3 node 2

standby input

input

input

input

Fast recovery, but 2x hardware cost

Only need 1 standby, but slow to recover

(31)

Traditional Streaming Systems

Fault tolerance via replication or upstream backup:

node 1

node 3 node 2

node 1’

node 3’

node 2’

synchronization

node 1

node 3 node 2

standby input

input

input

input

Neither approach can handle stragglers

(32)

Observation

Batch processing models, like MapReduce, provide fault tolerance efficiently

»Divide job into deterministic tasks

»Rerun failed/slow tasks in parallel on other nodes

Idea: run streaming computations as a series of small, deterministic batch jobs

»Same recovery schemes at much smaller timescale

»To make latency low, store state in RDDs

(33)

Discretized Stream Processing

t = 1:

t = 2:

stream 1 stream 2

batch operation pull

input

input

immutable dataset (stored reliably)

immutable dataset (output or state);

stored in memory as RDD

(34)

Parallel Fault Recovery

Checkpoint state RDDs periodically

If a node fails or straggles, rebuild lost dataset partitions in parallel on other nodes

map

input dataset

Faster recovery than upstream backup, without the cost of replication

output dataset

(35)

How Fast Can It Go?

Can process over 60M records/s (6 GB/s) on 100 nodes at sub-second latency

Maximum throughput for latency under 1 sec

0 20 40 60 80

0 50 100

Records/s (millions)

Nodes in Cluster

Grep

0 10 20 30

0 50 100

Records/s (millions)

Nodes in Cluster

Top K Words

(36)

Comparison with Storm

Storm limited to 100K records/s/node

Commercial systems report O(500K) total

0 10 20 30

100 1000

MB/s per node

Record Size (bytes)

Top K Words

Spark Storm

0 20 40 60 80

100 1000

MB/s per node

Record Size (bytes)

Grep

Spark Storm

(37)

How Fast Can It Recover?

Recovers from faults/stragglers within 1 second

Sliding WordCount on 20 nodes with 10s checkpoint interval

0 0,5 1 1,5

0 5 10 15 20 25

Interval Processing Time (s)

Time (s) Fault happens

(38)

Programming Interface

Simple functional API

views = readStream("http:...", "1s") ones = views.map(ev => (ev.url, 1)) counts = ones.runningReduce(_ + _)

Interoperates with RDDs

// Join stream with static RDD

counts.join(historicCounts).map(...)

// Ad-hoc queries on stream state counts.slice(“21:00”,“21:05”).topK(10)

t = 1:

t = 2:

views ones counts

map reduce

. . .

= RDD = partition

(39)

This Talk

Spark introduction & use cases Shark: SQL over Spark

Spark Streaming

The power of unification

(40)

The Power of Unification

One of the things that makes Spark unique is unification of multiple programming models

»SQL, graphs, streaming, etc on the same engine

This had powerful benefits:

»For the engine

»For users

Spark

Streaming GraphX

Shark MLbase

(41)

Engine Perspective

Let’s compare Spark with leading frameworks in

»Code size

»Performance

(42)

Code Size

0 20000 40000 60000 80000 100000 120000 140000

Hadoop MapReduce

Impala (SQL)

Storm (Streaming)

Giraph (Graph)

Spark non-test, non-example source lines

(43)

Code Size

0 20000 40000 60000 80000 100000 120000 140000

Hadoop MapReduce

Impala (SQL)

Storm (Streaming)

Giraph (Graph)

Spark non-test, non-example source lines

Shark

(44)

Code Size

0 20000 40000 60000 80000 100000 120000 140000

Hadoop MapReduce

Impala (SQL)

Storm (Streaming)

Giraph (Graph)

Spark non-test, non-example source lines

Shark

Streamin

(45)

Code Size

0 20000 40000 60000 80000 100000 120000 140000

Hadoop MapReduce

Impala (SQL)

Storm (Streaming)

Giraph (Graph)

Spark non-test, non-example source lines

Shark GraphX Streamin

(46)

Performance

Impala (disk) Impala (mem) Redshift Shark (disk) Shark (mem)

0 5 10 15 20 25

Response Time (s)

SQL

Storm Spark

0 5 10 15 20 25 30 35

Throughput (MB/s/node)

Streaming

Hadoop Giraph GraphX

0 5 10 15 20 25 30

Response Time (min)

Graph

(47)

User Perspective

Unified engine means that:

1. Apps can easily compose models (e.g. run a SQL query then PageRank on the result)

2. Composition is fast (no writing to disk)

3. All models get Spark shell for free (e.g. use it to inspect your streams’ state, or your graph)

(48)

Long-Term Direction

As big data apps grow in complexity, combining processing models is essential

»E.g. run SQL query then machine learning on result

Data sharing between models is often slower than the computations themselves

»E.g. HDFS write versus in-memory iteration

Thus, unified engines increasingly important

(49)

Getting Started

Visit spark-project.org for videos, tutorials, and hands-on exercises

Easy to run in local mode, private clusters, EC2 Compatible with any Hadoop storage system Online training camp:

ampcamp.berkeley.edu

(50)

Conclusion

Big data analytics is evolving to include:

»More complex analytics (e.g. machine learning)

»More interactive ad-hoc queries

»More real-time stream processing

Spark is a platform that unifies these models, enabling sophisticated apps

More info: spark-project.org

(51)

Backup Slides

(52)

Behavior with Not Enough RAM

68,8 58,1 40,7 29,7 11,5

0 20 40 60 80 100

Cache disabled

25% 50% 75% Fully

cached

Iteration time (s)

% of working set in memory

References

Related documents

Individuals or groups may alternatively wish to place a memorial plaque on existing park or street furniture or other object, as either a donation to the community, or as a memorial

Machine Learning Mahout Spark ML Lib Real time lookups NoSQL (Hbase,. Cassandra ..etc) No

traditional network programming Limitations of MapReduce?. Spark

• Received data automatically persisted to HDFS Write Ahead Log to prevent data loss. • set spark.streaming.receiver.writeAheadLog.enable=true in

Spark Streaming is an extension of Spark that allows processing data stream using micro-batches of data... Discretized

Python API for Spark Streaming Spark SQL pluggable data sources. &gt;  Hive, JSON, Parquet, Cassandra,

Using an integration platform in the cloud that seamlessly connects solution operators to support partners to automate multi-party service collaboration. • Win business

I wish to test the hypothesis that the dominant regulatory philosophy within the EMU confined to neoclassical tenets – belief in self-correcting markets, rational