Distributed Computing with Spark Reza Zadeh Thanks to Matei - - PowerPoint PPT Presentation

distributed computing with spark
SMART_READER_LITE
LIVE PREVIEW

Distributed Computing with Spark Reza Zadeh Thanks to Matei - - PowerPoint PPT Presentation

Distributed Computing with Spark Reza Zadeh Thanks to Matei Zaharia Outline Data flow vs. traditional network programming Limitations of MapReduce Spark computing engine Numerical computing on Spark Ongoing work Problem Data


slide-1
SLIDE 1

Reza Zadeh

Distributed Computing with Spark

Thanks ¡to ¡Matei ¡Zaharia ¡

slide-2
SLIDE 2

Outline

Data flow vs. traditional network programming Limitations of MapReduce Spark computing engine Numerical computing on Spark Ongoing work

slide-3
SLIDE 3

Problem

Data growing faster than processing speeds Only solution is to parallelize on large clusters

» Wide use in both enterprises and web industry

How do we program these things?

slide-4
SLIDE 4

Traditional Network Programming

Message-passing between nodes (e.g. MPI) Very difficult ery difficult to do at scale:

» How to split problem across nodes?

  • Must consider network & data locality

» How to deal with failures? (inevitable at scale) » Even worse: stragglers (node not failed, but slow) » Ethernet networking not fast

Rarely used in commodity datacenters

slide-5
SLIDE 5

Data Flow Models

Restrict the programming interface so that the system can do more automatically Express jobs as graphs of high-level operators

» System picks how to split each operator into tasks and where to run each task » Run parts twice fault recovery

Biggest example: MapReduce

Map Map Map Reduce Reduce

slide-6
SLIDE 6

MapReduce Numerical Algorithms

Matrix-vector multiplication Power iteration (e.g. PageRank) Gradient descent methods Stochastic SVD Tall skinny QR Many others!

slide-7
SLIDE 7

Why Use a Data Flow Engine?

Ease of programming

» High-level functions instead of message passing

Wide deployment

» More common than MPI, especially “near” data

Scalability to very largest clusters

» Even HPC world is now concerned about resilience

Examples: Pig, Hive, Scalding, Storm

slide-8
SLIDE 8

Outline

Data flow vs. traditional network programming Limitations of MapReduce Spark computing engine Numerical computing on Spark Ongoing work

slide-9
SLIDE 9

Limitations of MapReduce

MapReduce is great at one-pass computation, but inefficient for multi-pass algorithms No efficient primitives for data sharing

» State between steps goes to distributed file system » Slow due to replication & disk storage

slide-10
SLIDE 10
  • iter. 1
  • iter. 2

. . . . . .

Input

file system read file system write file system read file system write

Input query 1 query 2 query 3 result 1 result 2 result 3

. . . . . .

file system read

Commonly spend 90% of time doing I/O

Example: Iterative Apps

slide-11
SLIDE 11

Example: PageRank

Repeatedly multiply sparse matrix and vector Requires repeatedly hashing together page adjacency lists and rank vector

Neighbors (id, edges) Ranks (id, rank)

Same file grouped

  • ver and over

iteration 1 iteration 2 iteration 3

slide-12
SLIDE 12

Result

While MapReduce is simple, it can require asymptotically more communication or I/O

slide-13
SLIDE 13

Outline

Data flow vs. traditional network programming Limitations of MapReduce Spark computing engine Numerical computing on Spark Ongoing work

slide-14
SLIDE 14

Spark Computing Engine

Extends MapReduce model with primitives for efficient data sharing

» “Resilient distributed datasets”

Open source at Apache

» Most active community in big data, with 50+ companies contributing

Clean APIs in Java, Scala, Python

slide-15
SLIDE 15

Resilient Distributed Datasets (RDDs)

Collections of objects stored across a cluster User-controlled partitioning & storage (memory, disk, …) Automatically rebuilt on failure

urls ¡= ¡spark.textFile(“hdfs://...”) ¡ records ¡= ¡urls.map(lambda ¡s: ¡(s, ¡1)) ¡ counts ¡= ¡records.reduceByKey(lambda ¡a, ¡b: ¡a ¡+ ¡b) ¡ bigCounts ¡= ¡counts.filter(lambda ¡(url, ¡cnt): ¡cnt ¡> ¡10) ¡ ¡ Input file map reduce filter

Known to be hash-partitioned Also known

bigCounts.cache() ¡ bigCounts.filter( ¡ ¡ ¡lambda ¡(k,v): ¡“news” ¡in ¡k).count() ¡ bigCounts.join(otherPartitionedRDD) ¡

slide-16
SLIDE 16

Key Idea

Resilient Distributed Datasets (RDDs)

» Collections of objects across a cluster with user controlled partitioning & storage (memory, disk, ...) » Built via parallel transformations (map, filter, …) » Automatically rebuilt on failure

slide-17
SLIDE 17

Example: Log Mining

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

lines ¡= ¡spark.textFile(“hdfs://...”) ¡ errors ¡= ¡lines.filter(lambda ¡s: ¡s.startswith(“ERROR”)) ¡ messages ¡= ¡errors.map(lambda ¡s: ¡s.split(“\t”)[2]) ¡ messages.cache() ¡ Block ¡1 ¡ Block ¡2 ¡ Block ¡3 ¡

Worker Worker Worker Driver

messages.filter(lambda ¡s: ¡“foo” ¡in ¡s).count() ¡ messages.filter(lambda ¡s: ¡“bar” ¡in ¡s).count() ¡ . ¡. ¡. ¡

tasks ¡ results ¡

Cache 1 Cache 2 Cache 3

Transformed RDD Action

Result: Result: full-text search of Wikipedia in 0.5 sec (vs 20 s for on-disk data)

slide-18
SLIDE 18

Fault Tolerance

file.map(lambda ¡rec: ¡(rec.type, ¡1)) ¡ ¡ ¡ ¡ ¡.reduceByKey(lambda ¡x, ¡y: ¡x ¡+ ¡y) ¡ ¡ ¡ ¡ ¡.filter(lambda ¡(type, ¡count): ¡count ¡> ¡10) ¡

filter reduce map Input file

RDDs track lineage info to rebuild lost data

slide-19
SLIDE 19

filter reduce map Input file

Fault Tolerance

file.map(lambda ¡rec: ¡(rec.type, ¡1)) ¡ ¡ ¡ ¡ ¡.reduceByKey(lambda ¡x, ¡y: ¡x ¡+ ¡y) ¡ ¡ ¡ ¡ ¡.filter(lambda ¡(type, ¡count): ¡count ¡> ¡10) ¡

RDDs track lineage info to rebuild lost data

slide-20
SLIDE 20

Partitioning

file.map(lambda ¡rec: ¡(rec.type, ¡1)) ¡ ¡ ¡ ¡ ¡.reduceByKey(lambda ¡x, ¡y: ¡x ¡+ ¡y) ¡ ¡ ¡ ¡ ¡.filter(lambda ¡(type, ¡count): ¡count ¡> ¡10) ¡

filter reduce map Input file

RDDs know their partitioning functions

Known to be hash-partitioned Also known

slide-21
SLIDE 21

Outline

Data flow vs. traditional network programming Limitations of MapReduce Spark computing engine Numerical computing on Spark Ongoing work

slide-22
SLIDE 22

Logistic Regression

data ¡= ¡spark.textFile(...).map(readPoint).cache() ¡ ¡ w ¡= ¡numpy.random.rand(D) ¡ ¡ for ¡i ¡in ¡range(iterations): ¡ ¡ ¡ ¡ ¡gradient ¡= ¡data.map(lambda ¡p: ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡(1 ¡/ ¡(1 ¡+ ¡exp(-­‑p.y ¡* ¡w.dot(p.x)))) ¡* ¡p.y ¡* ¡p.x ¡ ¡ ¡ ¡ ¡).reduce(lambda ¡a, ¡b: ¡a ¡+ ¡b) ¡ ¡ ¡ ¡ ¡w ¡-­‑= ¡gradient ¡ ¡ print ¡“Final ¡w: ¡%s” ¡% ¡w ¡

slide-23
SLIDE 23

Logistic Regression Results

500 1000 1500 2000 2500 3000 3500 4000 1 5 10 20 30 Running T Running Time (s) ime (s) Number of Iterations Number of Iterations Hadoop Spark

110 s / iteration first iteration 80 s further iterations 1 s

slide-24
SLIDE 24

Neighbors (id, edges) Ranks (id, rank)

PageRank

Using cache(), keep neighbor lists in RAM Using partitioning, avoid repeated hashing

join join join

partitionBy

slide-25
SLIDE 25

PageRank

Using cache(), keep neighbor lists in RAM Using partitioning, avoid repeated hashing

Neighbors (id, edges) Ranks (id, rank)

join join join

same node

partitionBy

slide-26
SLIDE 26

PageRank

Using cache(), keep neighbor lists in RAM Using partitioning, avoid repeated hashing

Neighbors (id, edges) Ranks (id, rank)

join partitionBy join join

slide-27
SLIDE 27

PageRank Code

# ¡RDD ¡of ¡(id, ¡neighbors) ¡pairs ¡ links ¡= ¡spark.textFile(...).map(parsePage) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡.partitionBy(128).cache() ¡ ¡ ranks ¡= ¡links.mapValues(lambda ¡v: ¡1.0) ¡ ¡# ¡RDD ¡of ¡(id, ¡rank) ¡ ¡ for ¡i ¡in ¡range(ITERATIONS): ¡ ¡ ¡ ¡ ¡ranks ¡= ¡links.join(ranks).flatMap( ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡lambda ¡(id, ¡(links, ¡rank)): ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡[(d, ¡rank/links.size) ¡for ¡d ¡in ¡links] ¡ ¡ ¡ ¡ ¡).reduceByKey(lambda ¡a, ¡b: ¡a ¡+ ¡b) ¡

slide-28
SLIDE 28

PageRank Results

171 72 23 50 100 150 200 Time per iteration (s) ime per iteration (s) Hadoop Basic Spark Spark + Controlled Partitioning

slide-29
SLIDE 29

Alternating Least Squares

  • 1. Start with random A1, B1
  • 2. Solve for A2 to minimize ||R – A2B1

T||

  • 3. Solve for B2 to minimize ||R – A2B2

T||

  • 4. Repeat until convergence

R A

=

BT

slide-30
SLIDE 30

ALS on Spark

Cache 2 copies of R in memory, one partitioned by rows and one by columns Keep A & B partitioned in corresponding way Operate on blocks to lower communication R A

=

BT

slide-31
SLIDE 31

ALS Results

4208 481 297 1000 2000 3000 4000 5000 Total T

  • tal Time (s)

ime (s) Mahout / Hadoop Spark (Scala) GraphLab (C++)

slide-32
SLIDE 32

Benefit for Users

Same engine Same engine performs data extraction, model training and interactive queries

… DFS read DFS write parse DFS read DFS write train DFS read DFS write query DFS DFS read parse train query

Separate engines Spark

slide-33
SLIDE 33

Outline

Data flow vs. traditional network programming Limitations of MapReduce Spark computing engine Numerical computing on Spark Ongoing work

slide-34
SLIDE 34

Most active open source community in big data 200+ 200+ developers, 50+ 50+ companies contributing

Spark Community

Giraph Storm 50 100 150

Contributors in past year

slide-35
SLIDE 35

Built-in ML Library: MLlib

classification: classification: logistic regression, linear SVM, naïve Bayes, classification tree regr egression: ession: generalized linear models (GLMs), regression tree collaborative filtering: collaborative filtering: alternating least squares (ALS), non-negative matrix factorization (NMF) clustering: clustering: k-means|| decomposition: decomposition: tall-skinny SVD, PCA

  • ptimization:
  • ptimization: stochastic gradient descent, L-BFGS
slide-36
SLIDE 36

Ongoing Work in MLlib

multiclass decision trees stats library (e.g. stratified sampling, ScaRSR) ADMM LDA 40 contributors since project started Sept ‘13

slide-37
SLIDE 37

SVD via ARPACK

Very mature Fortran77 package for computing eigenvalue decompositions JNI interface available via netlib-java Distributed using Spark distributed matrix- vector multiplies!

slide-38
SLIDE 38

Convex Optimization

Distribute ¡CVX ¡by ¡ backing ¡CVXPY ¡with ¡ PySpark ¡ ¡ Easy-­‑to-­‑express ¡ distributable ¡convex ¡ programs ¡ ¡ Need ¡to ¡know ¡less ¡ math ¡to ¡optimize ¡ complicated ¡

  • bjectives ¡
slide-39
SLIDE 39

Research Projects

GraphX: GraphX: graph computation via data flow SparkR SparkR: R interface to Spark, and distributed matrix operations ML pipelines: ML pipelines: high-level machine learning APIs Applications: Applications: neuroscience, traffic, genomics, general convex optimization

slide-40
SLIDE 40

Spark and Research

Spark has all its roots in research, so we hope to keep incorporating new ideas!

slide-41
SLIDE 41

Conclusion

Data flow engines are becoming an important platform for numerical algorithms While early models like MapReduce were inefficient, new ones like Spark close this gap More info: spark.apache.org

slide-42
SLIDE 42

Behavior with Less RAM

68.8 58.1 40.7 29.7 11.5 20 40 60 80 100 0% 25% 50% 75% 100% Iteration time (s) Iteration time (s) % of working set in memory % of working set in memory

slide-43
SLIDE 43

Spark in Scala and Java

// Scala: val val lines = sc.textFile(...) lines.filter(x => x.contains(“ERROR”)).count() // Java: JavaRDD<String> lines = sc.textFile(...); lines.filter(new new Function<String, Boolean>() { Boolean call(String s) { return return s.contains(“error”); } }).count();