Big Data Analytics. C. Distributed Computing Environments / C.2. Resilient Distributed Datasets: Apache Spark. Lars Schmidt-Thieme

Similar documents
Beyond MapReduce: Apache Spark Antonino Virgillito

2/4/2019 Week 3- A Sangmi Lee Pallickara

L6: Introduction to Spark Spark

Distributed Systems. Distributed computation with Spark. Abraham Bernstein, Ph.D.

Analytic Cloud with. Shelly Garion. IBM Research -- Haifa IBM Corporation

2/26/2017. RDDs. RDDs are the primary abstraction in Spark RDDs are distributed collections of objects spread across the nodes of a clusters

RDDs are the primary abstraction in Spark RDDs are distributed collections of objects spread across the nodes of a clusters

CSE 444: Database Internals. Lecture 23 Spark

Chapter 4: Apache Spark

Apache Spark is a fast and general-purpose engine for large-scale data processing Spark aims at achieving the following goals in the Big data context

Big Data Infrastructures & Technologies

CS435 Introduction to Big Data FALL 2018 Colorado State University. 10/22/2018 Week 10-A Sangmi Lee Pallickara. FAQs.

Big Data Analytics with Apache Spark. Nastaran Fatemi

Resilient Distributed Datasets

Processing of big data with Apache Spark

Data processing in Apache Spark

CS455: Introduction to Distributed Systems [Spring 2018] Dept. Of Computer Science, Colorado State University

Fast, Interactive, Language-Integrated Cluster Computing

Cloud, Big Data & Linear Algebra

Spark. In- Memory Cluster Computing for Iterative and Interactive Applications

Spark Overview. Professor Sasu Tarkoma.

RESILIENT DISTRIBUTED DATASETS: A FAULT-TOLERANT ABSTRACTION FOR IN-MEMORY CLUSTER COMPUTING

Data processing in Apache Spark

CSC 261/461 Database Systems Lecture 24. Spring 2017 MW 3:25 pm 4:40 pm January 18 May 3 Dewey 1101

2/26/2017. Originally developed at the University of California - Berkeley's AMPLab

An Introduction to Big Data Analysis using Spark

Dell In-Memory Appliance for Cloudera Enterprise

Spark, Shark and Spark Streaming Introduction

Analytics in Spark. Yanlei Diao Tim Hunter. Slides Courtesy of Ion Stoica, Matei Zaharia and Brooke Wenig

Data processing in Apache Spark

Spark: A Brief History.

An Introduction to Apache Spark

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

An Introduction to Apache Spark

Distributed Computing with Spark and MapReduce

Overview. Prerequisites. Course Outline. Course Outline :: Apache Spark Development::

Introduction to Apache Spark

Spark. In- Memory Cluster Computing for Iterative and Interactive Applications

Introduction to Apache Spark. Patrick Wendell - Databricks

Spark. Cluster Computing with Working Sets. Matei Zaharia, Mosharaf Chowdhury, Michael Franklin, Scott Shenker, Ion Stoica.

COSC 6339 Big Data Analytics. Introduction to Spark. Edgar Gabriel Fall What is SPARK?

Apache Spark Internals

Dept. Of Computer Science, Colorado State University

Distributed Computing with Spark

08/04/2018. RDDs. RDDs are the primary abstraction in Spark RDDs are distributed collections of objects spread across the nodes of a clusters

Data-intensive computing systems

Introduction to Apache Spark

DATA SCIENCE USING SPARK: AN INTRODUCTION

2/26/2017. Spark MLlib is the Spark component providing the machine learning/data mining algorithms. MLlib APIs are divided into two packages:

L3: Spark & RDD. CDS Department of Computational and Data Sciences. Department of Computational and Data Sciences

15.1 Data flow vs. traditional network programming

Big Data Infrastructures & Technologies Hadoop Streaming Revisit.

MapReduce, Hadoop and Spark. Bompotas Agorakis

Specialist ICT Learning

a Spark in the cloud iterative and interactive cluster computing

Integration of Machine Learning Library in Apache Apex

Apache Spark. CS240A T Yang. Some of them are based on P. Wendell s Spark slides

CS455: Introduction to Distributed Systems [Spring 2018] Dept. Of Computer Science, Colorado State University

Apache Spark: Hands-on Session A.A. 2016/17

An Overview of Apache Spark

Apache Spark: Hands-on Session A.A. 2017/18

Lambda Architecture with Apache Spark

Lecture 11 Hadoop & Spark

CS435 Introduction to Big Data FALL 2018 Colorado State University. 10/24/2018 Week 10-B Sangmi Lee Pallickara

Machine Learning With Spark

Today s content. Resilient Distributed Datasets(RDDs) Spark and its data model

Big data systems 12/8/17

Spark and Spark SQL. Amir H. Payberah. SICS Swedish ICT. Amir H. Payberah (SICS) Spark and Spark SQL June 29, / 71

Agenda. Spark Platform Spark Core Spark Extensions Using Apache Spark

CS Spark. Slides from Matei Zaharia and Databricks

THE CONTRACTOR IS ACTING UNDER A FRAMEWORK CONTRACT CONCLUDED WITH THE COMMISSION

A very short introduction

Distributed Machine Learning" on Spark

Applied Spark. From Concepts to Bitcoin Analytics. Andrew F.

Turning Relational Database Tables into Spark Data Sources

Spark Streaming: Hands-on Session A.A. 2017/18

Certified Big Data Hadoop and Spark Scala Course Curriculum

Announcements. Reading Material. Map Reduce. The Map-Reduce Framework 10/3/17. Big Data. CompSci 516: Database Systems

Twitter data Analytics using Distributed Computing

Data Platforms and Pattern Mining

빅데이터기술개요 2016/8/20 ~ 9/3. 윤형기

Hadoop Development Introduction

CompSci 516: Database Systems

Survey on Incremental MapReduce for Data Mining

Reactive App using Actor model & Apache Spark. Rahul Kumar Software

Lecture 09. Spark for batch and streaming processing FREDERICK AYALA-GÓMEZ. CS-E4610 Modern Database Systems

An Introduction to Apache Spark Big Data Madison: 29 July William Red Hat, Inc.

Big Data Analytics using Apache Hadoop and Spark with Scala

Summary of Big Data Frameworks Course 2015 Professor Sasu Tarkoma

Big Data Hadoop Developer Course Content. Big Data Hadoop Developer - The Complete Course Course Duration: 45 Hours

The Datacenter Needs an Operating System

Corpus methods in linguistics and NLP Lecture 7: Programming for large-scale data processing

Batch Processing Basic architecture

Big Data Architect.

Distributed Computation Models

EPL660: Information Retrieval and Search Engines Lab 11

We consider the general additive objective function that we saw in previous lectures: n F (w; x i, y i ) i=1

Hadoop 2.x Core: YARN, Tez, and Spark. Hortonworks Inc All Rights Reserved

MapReduce Spark. Some slides are adapted from those of Jeff Dean and Matei Zaharia

Lambda Architecture for Batch and Real- Time Processing on AWS with Spark Streaming and Spark SQL. May 2015

Transcription:

Big Data Analytics C. Distributed Computing Environments / C.2. Resilient Distributed Datasets: Apache Spark Lars Schmidt-Thieme Information Systems and Machine Learning Lab (ISMLL) Institute of Computer Science University of Hildesheim, Germany 1 / 35

Syllabus Tue. 4.4. (1) 0. Introduction A. Parallel Computing Tue. 11.4. (2) A.1 Threads Tue. 18.4. (3) A.2 Message Passing Interface (MPI) B. Distributed Storage Tue. 25.4. (4) B.1 Distributed File Systems Tue. 2.5. (5) B.2 Partioning of Relational Databases Tue. 9.5. (6) B.3 NoSQL Databases Tue. 16.5. (7) A.3 Graphical Processing Units (GPUs) C. Distributed Computing Environments Tue. 23.5. (8) C.1 Map-Reduce Tue. 30.5. (9) C.2 Resilient Distributed Datasets (Spark) Tue. 6.6. Pentecoste Break D. Distributed Machine Learning Algorithms Tue. 13.6. (10) D.1 Distributed Stochastic Gradient Descent Tue. 20.6. (11) D.2 Distributed Matrix Factorization Tue. 27.6. (12) D.3 Alternating Direction Method of Multipliers (ADMM) Tue. 4.7. (13) Questions and Answers 1 / 35

Outline 1. Introduction 2. Apache Spark 4. MLLib: Machine Learning with Spark 1 / 35

1. Introduction Outline 1. Introduction 2. Apache Spark 4. MLLib: Machine Learning with Spark 1 / 35

1. Introduction Core Idea To implement fault-tolerance for primary/original data: replication: partition large data into parts store each part several times on different servers if one server crashes, the data is still available on the others To implement fault-tolerance for secondary/derived data: replication 1 / 35

1. Introduction Core Idea To implement fault-tolerance for primary/original data: replication: partition large data into parts store each part several times on different servers if one server crashes, the data is still available on the others To implement fault-tolerance for secondary/derived data: replication or resilience: partition large data into parts for each part, store how it was derived (lineage) from which parts of its input data by which operations if a server crashes, recreate its data on the others 1 / 35

1. Introduction How to store data derivation? journal sequence of elementary operations set an element to a value remove a value/index from a list insert a value at an index of a list... generic: supports all types of operations but too large often same size as data itself 2 / 35

1. Introduction How to store data derivation? journal sequence of elementary operations set an element to a value remove a value/index from a list insert a value at an index of a list... generic: supports all types of operations but too large often same size as data itself coarse-grained transformations just store the executable code of the transformations and the input either primary data or itself an RDD 2 / 35

1. Introduction Resilient Distributed Datasets (RDD) Represented by 5 components: 1. partition: a list of parts 2. dependencies: a list of parent RDDs 3. transformation: a function to compute the dataset from its parents 4. partitioner: how elements are assigned to parts 5. preferred locations: which hosts store which parts 3 / 35

1. Introduction Resilient Distributed Datasets (RDD) Represented by 5 components: 1. partition: a list of parts 2. dependencies: a list of parent RDDs 3. transformation: a function to compute the dataset from its parents 4. partitioner: how elements are assigned to parts 5. preferred locations: which hosts store which parts distinction into two types of dependencies: narrow depenencies: each parent part is used to derive at most one part of the dataset wide dependencies: some parent part is used to derive several parts of the dataset 3 / 35

1. Introduction How to cope with expensive operations? checkpointing: traditionally, a long process is broken into several steps A, B, C etc. after each step, the state of the process is saved to disk if the process crashes within step B, it does not have to be run from the very beginning but can be restarted at the beginning of step B reading its state at the end of step A. 4 / 35

1. Introduction How to cope with expensive operations? checkpointing: traditionally, a long process is broken into several steps A, B, C etc. after each step, the state of the process is saved to disk if the process crashes within step B, it does not have to be run from the very beginning but can be restarted at the beginning of step B reading its state at the end of step A. in a distributed scenario, saving to disk is not fault-tolerant replicate the data instead (distributed checkpointing) 4 / 35

1. Introduction Caching RDDs are marketed as technology for in memory cluster computing derived RDDs are not saved to disks, but kept in (distributed) memory derived RDDs are saved to disks on request (checkpointing) allows faster operations 5 / 35

1. Introduction Limitations RDDs are read-only as updating would invalidate them as input for possible derived RDDs transformations have to be deterministic otherwise lost parts cannot be recreated the very same way for stochastic transformations: store random seed For more conceptual details see the original paper Zaharia, M., Chowdhury, M., Das, T., Dave, A., Ma, J., McCauley, M., Franklin, M.J., Shenker, S. and Stoica, I. 2012. Resilient distributed datasets: A fault-tolerant abstraction for in-memory cluster computing. Proceedings of the 9th USENIX Conference on Networked Systems Design and Implementation (2012). 6 / 35

2. Apache Spark Outline 1. Introduction 2. Apache Spark 4. MLLib: Machine Learning with Spark 7 / 35

2. Apache Spark Apache Spark Overview an open source framework for large scale data processing and analysis. Main Ideas: Processing occurs where the data resides Avoid moving data over the network Works with the data in memory 7 / 35

2. Apache Spark Apache Spark Overview an open source framework for large scale data processing and analysis. Main Ideas: Processing occurs where the data resides Avoid moving data over the network Works with the data in memory Technical details: Written in Scala Works seamlessly with Java, Python and R Developed at UC Berkeley 7 / 35

2. Apache Spark Apache Spark Stack Data platform: Distributed file system /data base Ex: HDFS, HBase, Cassandra Execution Environment: single machine or a cluster Standalone, EC2, YARN, Mesos Spark Core: Spark API Spark Ecosystem: libraries of common algorithms MLLib, GraphX, Streaming 8 / 35

2. Apache Spark Apache Spark Ecosystem 9 / 35

2. Apache Spark How to use Spark Spark can be used through: The Spark Shell Available in Python and Scala Useful for learning the framework Spark Applications Available in Python, Java and Scala For serious large scale processing 10 / 35

Outline 1. Introduction 2. Apache Spark 4. MLLib: Machine Learning with Spark 11 / 35

Working with Spark Working with Spark requires accessing a Spark Context: Main entry point to the Spark API Already preconfigured in the shell Most of the work in Spark is a set of operations on Resilient Distributed Datasets (RDDs): Main data abstraction The data used and generated by the application is stored as RDDs 11 / 35

Spark Java Application 1 import org.apache.spark.api.java.*; 2 import org.apache.spark.sparkconf; 3 import org.apache.spark.api.java.function.function; 4 5 public class HelloWorld { 6 public static void main(string[] args) { 7 String logfile = "/home/lst/system/spark/readme.md"; 8 SparkConf conf = new SparkConf().setAppName("Simple Application"); 9 JavaSparkContext sc = new JavaSparkContext(conf); 0 JavaRDD<String> logdata = sc.textfile(logfile).cache(); 1 2 long numas = logdata.filter(new Function<String, Boolean>() { 3 public Boolean call(string s) { return s.contains("a"); } 4 }).count(); 5 6 long numbs = logdata.filter(new Function<String, Boolean>() { 7 public Boolean call(string s) { return s.contains("b"); } 8 }).count(); 9 0 System.out.println("Lines with a: " + numas + ", lines with b: " + numbs); 1 } 2 } 12 / 35

Compile and Run 0. install spark (here in ~/system/spark) 1. compile: 1 javac -cp ~/system/spark/lib/spark-assembly-1.6.1-hadoop2.6.0.jar HelloWorld.java 2. create jar archive: 1 jar cf HelloWorld.jar HelloWorld*.class 3. run: 1 ~/system/spark/bin/spark-submit --master local --class HelloWorld HelloWorld.jar 13 / 35

Spark Interactive Shell (Python) 1 >./bin/pyspark 2 Welcome to 3 4 / / / / 5 _\ \/ _ \/ _ / / _/ 6 / /. /\_,_/_/ /_/\_\ version 1.3.1 7 /_/ 8 9 Using Python version 2.7.6 ( default, Jun 22 2015 17:58:13) 0 SparkContext available as sc, SQLContext available as sqlcontext. 1 >>> 14 / 35

Spark Context The Spark Context is the main entry point for the Spark functionality. It represents the connection to a Spark cluster Allows to create RDDs Allows to broadcast variables on the cluster Allows to create Accumulators 15 / 35

Resilient Distributed Datasets (RDDs) A Spark application stores data as RDDs Resilient: if data in memory is lost it can be recreated (fault tolerance) Distributed: stored in memory across different machines Dataset: data coming from a file or generated by the application A Spark program is about operations on RDDs RDDs are immutable: operations on RDDs may create new RDDs but never change them 16 / 35

Resilient Distributed Datasets (RDDs) RDD data RDD Element data data data RDD elements can be stored in different machines transparent to the developer data can have various data types 17 / 35

RDD Data types An element of an RDD can be of any type as long as it is serializable Examples: Primitive data types: integers, characters, strings, floats,... Sequences: lists, arrays, tuples... Pair RDDs: key-value pairs Serializable Scala/Java objects A single RDD may contain elements of different types Some specific element types have additional functionality 18 / 35

Example: Text file to RDD File: mydiary.txt I had breakfast this morning. The coffee was really good. I didn't like the bread though. But I had cheese. Oh I love cheese. RDD: mydata I had breakfast this morning. The coffee was really good. I didn't like the bread though. But I had cheese. Oh I love cheese. 19 / 35

RDD Operations / Actions There are two types of RDD operations: 1. Actions: return a value based on the RDD. Examples: count: returns the number of elements in the RDD first(): returns the first element in the RDD take(n): returns an array with the first n elements in the RDD RDD data data data data Action Value 20 / 35

RDD Operations / Transformations 2. Transformations: create a new RDD based on the current one. Examples: filter: returns the elements of an RDD which match a given criterion map: applies a particular function to each RDD element reduce: aggregates the elements of a specific RDD BaseRDD data data data data Transformation NewRDD data data data data RDD transformations are lazy they are only executed once an action requires a result to be computed 21 / 35

Action Examples File: mydiary.txt I had breakfast this morning. The coffee was really good. I didn't like the bread though. But I had cheese. Oh I love cheese. RDD: mydata I had breakfast this morning. The coffee was really good. I didn't like the bread though. But I had cheese. Oh I love cheese. 1 >>> mydata = sc.textfile("mydiary.txt") 2 >>> mydata.count() 3 5 4 >>> mydata.first() 5 u I had breakfast this morning. 6 >>> mydata.take(2) 7 [u I had breakfast this morning., u The coffee was really good. ] 22 / 35

Transformation Examples RDD: mydata I had breakfast this morning. The coffee was really good. I didn't like the bread though. But I had cheese. Oh I love cheese. RDD: filtered I had breakfast this morning. I didn't like the bread though. filter But I had cheese. Oh I love cheese. filter(lambda line: "I " in line) RDD: filtered I had breakfast this morning. RDD: filtermap I HAD BREAKFAST THIS MORNING. I didn't like the bread though. But I had cheese. Oh I love cheese. map I DIDN'T LIKE THE BREAD THOUGH. BUT I HAD CHEESE. OH I LOVE CHEESE. map(lambda line: line.upper()) 23 / 35

Transformation Examples 1 >>> filtered = mydata.filter(lambda line: "I " in line ) 2 >>> filtered.count() 3 4 4 >>> filtered.take(4) 5 [u I had breakfast this morning., 6 u"i didn t like the bread though.", 7 u But I had cheese., 8 u Oh I love cheese. ] 9 >>> filtermap = filtered.map(lambda line: line.upper()) 0 >>> filtermap.count() 1 4 2 >>> filtermap.take(4) 3 [u I HAD BREAKFAST THIS MORNING., 4 u"i DIDN T LIKE THE BREAD THOUGH.", 5 u BUT I HAD CHEESE., 6 u OH I LOVE CHEESE. ] 24 / 35

Operations on Numbers Numeric RDDs have special operations: mean() min() max()... 1 >>> linelens = mydata.map(lambda line: len(line)) 2 >>> linelens.collect () 3 [29, 27, 31, 17, 17] 4 >>> linelens.mean() 5 24.2 6 >>> linelens.min() 7 17 8 >>> linelens.max() 9 31 0 >>> linelens.stddev() 1 6.0133185513491636 25 / 35

Operations on Key-Value Pairs Pair RDDs contain a two element tuple: (K, V ) Keys and values can be of any type Useful for implementing MapReduce algorithms Examples of operations: groupbykey reducebykey aggregatebykey sortbykey... 26 / 35

Word Count Example Map: Input: document-word list pairs Output: word-count pairs (d k, w 1,..., w m ) [(w i, c i )] Reduce: Input: word-(count list) pairs Output: word-count pairs (w i, [c i ]) (w i, c) c [c i ] 27 / 35

Word Count Example (love, 1) (stranger,1) (d1, love ain't no stranger ) (crying, 1) (d2, crying in the rain ) (rain, 1) (ain't, 1) (stranger,1) (love, 1) (love, 2) (love, 2) (crying, 1) (crying, 1) (stranger,1) (love, 5) (crying, 2) (d3, looking for love ) (love, 2) (d4, I'm crying ) (d5, the deeper the love ) (crying, 1) (looking, 1) (deeper, 1) (ain't, 1) (ain't, 2) (ain't, 1) (rain, 1) (rain, 1) (looking, 1) (d6, is this love ) (love, 2) (ain't, 1) (looking, 1) (deeper, 1) (deeper, 1) (this, 1) (d7, Ain't no love ) (this, 1) (this, 1) Mappers Reducers 28 / 35

Word Count on Spark RDD: mydata I had breakfast this morning. RDD I RDD (I,1) RDD (I,4) The coffee was really good. had (had,1) (had,2) I didn't like the bread though. flatmap breakfast map (breakfast,1) reducebykey (breakfast,1) But I had cheese. this (this,1) (this,1) Oh I love cheese. morning. (morning.,1) (morning.,1)......... 1 >>> counts = mydata.flatmap(lambda line: line.split(" ")) \ 2.map(lambda word: (word, 1)) \ 3.reduceByKey(lambda x, y: x + y) 29 / 35

ReduceByKey 1.reduceByKey(lambda x, y: x + y) ReduceByKey works somewhat different from the MapReduce reduce function: It combines two values associated with the same key. Must be commutative: reducebykey(x,y) = reducebykey(y,x) Must be associative: reducebykey(reducebykey(x,y), z) = reducebykey(x,reducebykey(y,z)) Spark does not guarantee in which order the reducebykey functions are executed. 30 / 35

Shuffle Operations operations are broken automatically into tasks each task is executed separately, each on some node e.g., for ReduceByKey: one task for each key each task needs all its input data locally on the node it is executed e.g., for ReduceByKey: all key/value pairs for a specific key if data is not already partitioned by that key, it needs to be repartitioned (shuffled) expensive operation (network, IO) 31 / 35

MapReduce in Spark and Hadoop Spark provides a much more efficient MapReduce implementation than Hadoop: Higher level API In memory storage (less I/O overhead) Chaining MapReduce operations is simplified sequence of MapReduce passes can be done in one job Spark vs. Hadoop on training a logistic regression model: Source: Apache Spark. https://spark.apache.org/ 32 / 35

4. MLLib: Machine Learning with Spark Outline 1. Introduction 2. Apache Spark 4. MLLib: Machine Learning with Spark 33 / 35

4. MLLib: Machine Learning with Spark Overview MLLib is a Spark Machine Learning library containing implementations for: Computing Basic Statistics from Datasets Classification and Regression Collaborative Filtering Clustering Feature Extraction and Dimensionality Reduction Frequent Pattern Mining Optimization Algorithms 33 / 35

4. MLLib: Machine Learning with Spark Logistic Regression with MLLib 1. Import required packages: 1 from pyspark.mllib. regression import LabeledPoint 2 from pyspark.mllib. util import MLUtils 3 from pyspark.mllib. classification import LogisticRegressionWithSGD 2. Read the data (LibSVM format): 1 dataset = MLUtils.loadLibSVMFile(sc, data/mllib/sample_libsvm_data.txt ) 3. Train the model: 1 model = LogisticRegressionWithSGD.train(dataset) 4. Evaluate the model: 1 labelsandpreds = dataset.map(lambda p: (p.label, model.predict(p.features ))) 2 trainerr = labelsandpreds. filter (lambda (v, p): v!= p).count() 3 / float (dataset.count()) 4 print ( Training Error = {}.format(trainerr)) 34 / 35

4. MLLib: Machine Learning with Spark Summary Resilient Distributed Datasets (RDDs) make large-scale distributed computations fault-tolerant RDDs keep track of dependencies: which part of a output data depends on which part of the input data which coarse-grained transformation is used if a server storing a part of a dataset fails, this part will be recomputed. RDDs are immutable, transformations have to be deterministic. so that RDDs can be recomputed always exactly the same RDDs provide in memory cluster computing derived RDDs can be saved to disk on request (checkpointing) 35 / 35

Further Readings Original Spark paper: Zaharia:2010:SCC:1863103.1863113, A broad introduction to Spark: [KKWZ15] 36 / 35

References Holden Karau, Andy Konwinski, Patrick Wendell, and Matei Zaharia. Learning Spark, Lightning-Fast Big Data Analysis. O Reilly Media, 2015. 37 / 35