Parallel Processing - MapReduce and FlumeJava. Amir H. Payberah 14/09/2018

Similar documents
MapReduce Simplified Data Processing on Large Clusters

An Introduction to Apache Spark

Large-scale Information Processing

UNIT V PROCESSING YOUR DATA WITH MAPREDUCE Syllabus

Introduction to Map/Reduce. Kostas Solomos Computer Science Department University of Crete, Greece

Clustering Documents. Case Study 2: Document Retrieval

Clustering Documents. Document Retrieval. Case Study 2: Document Retrieval

Big Data Analysis using Hadoop. Map-Reduce An Introduction. Lecture 2

ECE5610/CSC6220 Introduction to Parallel and Distribution Computing. Lecture 6: MapReduce in Parallel Computing

Parallel Computing: MapReduce Jin, Hai

Java in MapReduce. Scope

MapReduce: Simplified Data Processing on Large Clusters 유연일민철기

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

Parallel Data Processing with Hadoop/MapReduce. CS140 Tao Yang, 2014

L22: SC Report, Map Reduce

Parallel Programming Concepts

Overview. Why MapReduce? What is MapReduce? The Hadoop Distributed File System Cloudera, Inc.

Batch Processing Basic architecture

COMP4442. Service and Cloud Computing. Lab 12: MapReduce. Prof. George Baciu PQ838.

Clustering Lecture 8: MapReduce

Introduction to MapReduce

Chapter 3. Distributed Algorithms based on MapReduce

Map-Reduce Applications: Counting, Graph Shortest Paths

Map-Reduce in Various Programming Languages

Big Data Analytics. 4. Map Reduce I. Lars Schmidt-Thieme

Clustering Documents. Document Retrieval. Case Study 2: Document Retrieval

CS 470 Spring Parallel Algorithm Development. (Foster's Methodology) Mike Lam, Professor

1/30/2019 Week 2- B Sangmi Lee Pallickara

Big Data landscape Lecture #2

Topics covered in this lecture

Cloud Computing. Up until now

Map Reduce Group Meeting

Big Data Management and NoSQL Databases

Data-Intensive Computing with MapReduce

Department of Computer Science University of Cyprus EPL646 Advanced Topics in Databases. Lecture 16. Big Data Management VI (MapReduce Programming)

September 2013 Alberto Abelló & Oscar Romero 1

Parallel Programming Principle and Practice. Lecture 10 Big Data Processing with MapReduce

Map-Reduce Applications: Counting, Graph Shortest Paths

CS 345A Data Mining. MapReduce

Map Reduce. MCSN - N. Tonellotto - Distributed Enabling Platforms

Distributed Computations MapReduce. adapted from Jeff Dean s slides

Outline. What is Big Data? Hadoop HDFS MapReduce Twitter Analytics and Hadoop

Dept. Of Computer Science, Colorado State University

CSE Lecture 11: Map/Reduce 7 October Nate Nystrom UTA

BigData and MapReduce with Hadoop

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

The MapReduce Abstraction

CS427 Multicore Architecture and Parallel Computing

FAQs. Topics. This Material is Built Based on, Analytics Process Model. 8/22/2018 Week 1-B Sangmi Lee Pallickara

MapReduce and Hadoop. The reference Big Data stack

Big Data: Architectures and Data Analytics

PLATFORM AND SOFTWARE AS A SERVICE THE MAPREDUCE PROGRAMMING MODEL AND IMPLEMENTATIONS

W1.A.0 W2.A.0 1/22/2018 1/22/2018. CS435 Introduction to Big Data. FAQs. Readings

Programming Systems for Big Data

Introduction to MapReduce

Principles of Data Management. Lecture #16 (MapReduce & DFS for Big Data)

Big Data Analytics. Izabela Moise, Evangelos Pournaras, Dirk Helbing

MapReduce & HyperDex. Kathleen Durant PhD Lecture 21 CS 3200 Northeastern University

MapReduce. Kiril Valev LMU Kiril Valev (LMU) MapReduce / 35

CS MapReduce. Vitaly Shmatikov

A BigData Tour HDFS, Ceph and MapReduce

Ghislain Fourny. Big Data 6. Massive Parallel Processing (MapReduce)

Experiences with a new Hadoop cluster: deployment, teaching and research. Andre Barczak February 2018

Guidelines For Hadoop and Spark Cluster Usage

Computer Science 572 Exam Prof. Horowitz Tuesday, April 24, 2017, 8:00am 9:00am

Ghislain Fourny. Big Data Fall Massive Parallel Processing (MapReduce)

The MapReduce Framework

MapReduce-style data processing

MI-PDB, MIE-PDB: Advanced Database Systems

CS 61C: Great Ideas in Computer Architecture. MapReduce

Map Reduce. Yerevan.

MapReduce: Recap. Juliana Freire & Cláudio Silva. Some slides borrowed from Jimmy Lin, Jeff Ullman, Jerome Simeon, and Jure Leskovec

EE657 Spring 2012 HW#4 Zhou Zhao

Where We Are. Review: Parallel DBMS. Parallel DBMS. Introduction to Data Management CSE 344

Survey Paper on Traditional Hadoop and Pipelined Map Reduce

Map- reduce programming paradigm

Improving the MapReduce Big Data Processing Framework

Introduction to Map Reduce

CSE6331: Cloud Computing

PARALLEL DATA PROCESSING IN BIG DATA SYSTEMS

Big Data Infrastructure CS 489/698 Big Data Infrastructure (Winter 2017)

Introduction to Hadoop and MapReduce

Big Data Infrastructure CS 489/698 Big Data Infrastructure (Winter 2017)

2. MapReduce Programming Model

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

MapReduce: Simplified Data Processing on Large Clusters

Data Clustering on the Parallel Hadoop MapReduce Model. Dimitrios Verraros

Parallel Computing. Prof. Marco Bertini

Introduction to MapReduce

MapReduce. Stony Brook University CSE545, Fall 2016

HDFS: Hadoop Distributed File System. CIS 612 Sunnie Chung

CS435 Introduction to Big Data Spring 2018 Colorado State University. 2/5/2018 Week 4-A Sangmi Lee Pallickara. FAQs. Total Order Sorting Pattern

Recommended Literature

TI2736-B Big Data Processing. Claudia Hauff

Big Data: Architectures and Data Analytics

Introduction to Data Management CSE 344

PARLab Parallel Boot Camp

1. Introduction to MapReduce

Announcements. Optional Reading. Distributed File System (DFS) MapReduce Process. MapReduce. Database Systems CSE 414. HW5 is due tomorrow 11pm

Steps: First install hadoop (if not installed yet) by,

Transcription:

Parallel Processing - MapReduce and FlumeJava Amir H. Payberah payberah@kth.se 14/09/2018

The Course Web Page https://id2221kth.github.io 1 / 83

Where Are We? 2 / 83

What do we do when there is too much data to process? 3 / 83

Scale Up vs. Scale Out Scale up or scale vertically: adding resources to a single node in a system. Scale out or scale horizontally: adding more nodes to a system. 4 / 83

Taxonomy of Parallel Architectures DeWitt, D. and Gray, J. Parallel database systems: the future of high performance database systems. ACM Communications, 35(6), 85-98, 1992. 5 / 83

MapReduce A shared nothing architecture for processing large data sets with a parallel/distributed algorithm on clusters of commodity hardware. 6 / 83

Challenges I How to distribute computation? I How can we make it easy to write distributed programs? I Machines failure. 7 / 83

Simplicity Don t worry about parallelization, fault tolerance, data distribution, and load balancing (MapReduce takes care of these). Hide system-level details from programmers. 8 / 83

MapReduce Definition A programming model: to batch process large data sets (inspired by functional programming). An execution framework: to run parallel algorithms on clusters of commodity hardware. 9 / 83

Programming Model 10 / 83

Word Count Count the number of times each distinct word appears in the file If the file fits in memory: words(doc.txt) sort uniq -c 11 / 83

Word Count Count the number of times each distinct word appears in the file If the file fits in memory: words(doc.txt) sort uniq -c If not? 11 / 83

Data-Parallel Processing (1/2) Parallelize the data and process. 12 / 83

Data-Parallel Processing (2/2) MapReduce 13 / 83

MapReduce Stages - Map Each Map task (typically) operates on a single HDFS block. Map tasks (usually) run on the node where the block is stored. Each Map task generates a set of intermediate key/value pairs. 14 / 83

MapReduce Stages - Shuffle and Sort Sorts and consolidates intermediate data from all mappers. Happens after all Map tasks are complete and before Reduce tasks start. 15 / 83

MapReduce Stages - Reduce Each Reduce task operates on all intermediate values associated with the same intermediate key. Produces the final output. 16 / 83

MapReduce Data Flow (1/5) 17 / 83

MapReduce Data Flow (2/5) 18 / 83

MapReduce Data Flow (3/5) 19 / 83

MapReduce Data Flow (4/5) 20 / 83

MapReduce Data Flow (5/5) 21 / 83

Word Count in MapReduce Consider doing a word count of the following file using MapReduce 22 / 83

Word Count in MapReduce - Map (1/2) 23 / 83

Word Count in MapReduce - Map (2/2) 24 / 83

Word Count in MapReduce - Shuffle and Sort (1/3) 25 / 83

Word Count in MapReduce - Shuffle and Sort (2/3) 26 / 83

Word Count in MapReduce - Shuffle and Sort (3/3) 27 / 83

Word Count in MapReduce - Reduce (1/2) 28 / 83

Word Count in MapReduce - Reduce (2/2) 29 / 83

Mapper 30 / 83

The Mapper Input: (key, value) pairs Output: a list of (key, value) pairs map(in_key, in_value) -> list of (inter_key, inter_value) (in key, in value) map() (inter key1, inter value1) (inter key2, inter value2) (inter key3, inter value3) (inter key4, inter value4) 31 / 83

The Mapper Input: (key, value) pairs Output: a list of (key, value) pairs The Mapper may use or completely ignore the input key. map(in_key, in_value) -> list of (inter_key, inter_value) (in key, in value) map() (inter key1, inter value1) (inter key2, inter value2) (inter key3, inter value3) (inter key4, inter value4) 31 / 83

The Mapper Input: (key, value) pairs Output: a list of (key, value) pairs The Mapper may use or completely ignore the input key. A standard pattern is to read one line of a file at a time. Key: the byte offset Value: the content of the line map(in_key, in_value) -> list of (inter_key, inter_value) (in key, in value) map() (inter key1, inter value1) (inter key2, inter value2) (inter key3, inter value3) (inter key4, inter value4) 31 / 83

The Mapper Example (1/3) Turn input into upper case map(k, v) = emit (k.to_upper, v.to_upper) (kth, this is the course id2221) map() (KTH, THIS IS THE COURSE ID2221) 32 / 83

The Mapper Example (2/3) Count the number of characters in the input map(k, v) = emit (k, v.length) (kth, this is the course id2221) map() (kth, 26) 33 / 83

The Mapper Example (3/3) Turn each word in the input into pair of (word, 1) map(k, v) = foreach w in v emit (w, 1) (21, Hello Hadoop Goodbye Hadoop) map() (Hello, 1) (Hadoop, 1) (Goodbye, 1) (Hadoop, 1) 34 / 83

Reducer 35 / 83

Shuffle and Sort After the Map phase, all intermediate (key, value) pairs are grouped by the intermediate keys. Each (key, list of values) is passed to a Reducer. 36 / 83

The Reducer Input: (key, list of values) pairs Output: a (key, value) pair or list of (key, value) pairs The Reducer outputs zero or more final (key, value) pairs reduce(inter_key, [inter_value1, inter_value2,...]) -> (out_key, out_value) (inter k, [inter v1, inter v2, ]) reduce() (out k, out v) or (inter k, [inter v1, inter v2, ]) reduce() (out k, out v1) (out k, out v2) 37 / 83

The Reducer Example (1/3) Add up all the values associated with each intermediate key reduce(k, vals) = { sum = 0 foreach v in vals sum += v emit (k, sum) } (Hello, [1, 1, 1]) reduce() (Hello, 3) (Bye, [1]) reduce() (Bye, 1) 38 / 83

The Reducer Example (2/3) Get the maximum value of each intermediate key reduce(k, vals) = emit (k, max(vals)) (KTH, [5, 1, 12, 7]) reduce() (KTH, 12) 39 / 83

The Reducer Example (3/3) Identify reducer reduce(k, vals) = foreach v in vals emit (k, v)) (KTH, [5, 1, 12, 7]) reduce() (KTH, 5) (KTH, 1) (KTH, 12) (KTH, 7) 40 / 83

Example: Word Count - map public static class MyMap extends Mapper<...> { private final static IntWritable one = new IntWritable(1); private Text word = new Text(); public void map(longwritable key, Text value, Context context) throws IOException, InterruptedException { String line = value.tostring(); StringTokenizer tokenizer = new StringTokenizer(line); while (tokenizer.hasmoretokens()) { word.set(tokenizer.nexttoken()); context.write(word, one); } } } 41 / 83

Example: Word Count - reduce public static class MyReduce extends Reducer<...> { public void reduce(text key, Iterator<...> values, Context context) throws IOException, InterruptedException { int sum = 0; while (values.hasnext()) sum += values.next().get(); } } context.write(key, new IntWritable(sum)); 42 / 83

Example: Word Count - driver public static void main(string[] args) throws Exception { Configuration conf = new Configuration(); Job job = new Job(conf, "wordcount"); job.setoutputkeyclass(text.class); job.setoutputvalueclass(intwritable.class); job.setmapperclass(mymap.class); job.setcombinerclass(myreduce.class); job.setreducerclass(myreduce.class); job.setinputformatclass(textinputformat.class); job.setoutputformatclass(textoutputformat.class); FileInputFormat.addInputPath(job, new Path(args[0])); FileOutputFormat.setOutputPath(job, new Path(args[1])); } job.waitforcompletion(true); 43 / 83

Implementation 44 / 83

Architecture 45 / 83

MapReduce Execution (1/7) The user program divides the input files into M splits. A typical size of a split is the size of a HDFS block (64 MB). Converts them to key/value pairs. It starts up many copies of the program on a cluster of machines. 46 / 83

MapReduce Execution (2/7) One of the copies of the program is master, and the rest are workers. The master assigns works to the workers. It picks idle workers and assigns each one a map task or a reduce task. 47 / 83

MapReduce Execution (3/7) A map worker reads the contents of the corresponding input splits. It parses key/value pairs out of the input data and passes each pair to the user defined map function. The key/value pairs produced by the map function are buffered in memory. 48 / 83

MapReduce Execution (4/7) The buffered pairs are periodically written to local disk. They are partitioned into R regions (hash(key) mod R). The locations of the buffered pairs on the local disk are passed back to the master. The master forwards these locations to the reduce workers. 49 / 83

MapReduce Execution (5/7) A reduce worker reads the buffered data from the local disks of the map workers. When a reduce worker has read all intermediate data, it sorts it by the intermediate keys. 50 / 83

MapReduce Execution (6/7) The reduce worker iterates over the intermediate data. For each unique intermediate key, it passes the key and the corresponding set of intermediate values to the user defined reduce function. The output of the reduce function is appended to a final output file for this reduce partition. 51 / 83

MapReduce Execution (7/7) When all map tasks and reduce tasks have been completed, the master wakes up the user program. 52 / 83

Hadoop MapReduce and HDFS 53 / 83

Fault Tolerance - Worker Detect failure via periodic heartbeats. Re-execute in-progress map and reduce tasks. Re-execute completed map tasks: their output is stored on the local disk of the failed machine and is therefore inaccessible. Completed reduce tasks do not need to be re-executed since their output is stored in a global filesystem. 54 / 83

Fault Tolerance - Master State is periodically checkpointed: a new copy of master starts from the last checkpoint state. 55 / 83

MapReduce Algorithm Design 56 / 83

MapReduce Algorithm Design Local aggregation Joining Sorting 57 / 83

MapReduce Algorithm Design Local aggregation Joining Sorting 58 / 83

Local Aggregation - In-Map Combiner (1/2) In some cases, there is significant repeatition in the intermediate keys produced by each map task, and the reduce function is commutative and associative. 59 / 83

Local Aggregation - In-Map Combiner (2/2) Merge partially data before it is sent over the network to the reducer. Typically the same code for the combiner and the reduce function. 60 / 83

MapReduce Algorithm Design Local aggregation Joining Sorting 61 / 83

Joins Joins are relational constructs you use to combine relations together. In MapReduce joins are applicable in situations where you have two or more datasets you want to combine. 62 / 83

Joins - Two Strategies Reduce-side join Repartition join When joining two or more large datasets together Map-side join Replication join When one of the datasets is small enough to cache 63 / 83

Joins - Reduce-Side Join [M. Donald et al., MapReduce design patterns, O Reilly, 2012.] 64 / 83

Joins - Map-Side Join [M. Donald et al., MapReduce design patterns, O Reilly, 2012.] 65 / 83

MapReduce Algorithm Design Local aggregation Joining Sorting 66 / 83

Sort (1/3) Assume you want to have your job output in total sort order. Trivial with a single Reducer. Keys are passed to the Reducer in sorted order. 67 / 83

Sort (2/3) What if we have multiple Reducer? 68 / 83

Sort (3/3) For multiple Reducers we need to choose a partitioning function key1 < key2 partition(key1) partition(key2) 69 / 83

FlumeJava 70 / 83

Motivation (1/2) It is easy in MapReduce: words(doc.txt) sort uniq -c 71 / 83

Motivation (1/2) It is easy in MapReduce: words(doc.txt) sort uniq -c What about this one? words(doc.txt) grep sed sort awk perl 71 / 83

Motivation (2/2) Big jobs in MapReduce run in more than one Map-Reduce stages. Reducers of each stage write to replicated storage, e.g., HDFS. 72 / 83

FlumeJava FlumeJava is a library provided by Google to simply the creation of pipelined MapReduce tasks. 73 / 83

Core Idea Providing a couple of immutable parallel collections PCollection<T> and PTable<K, V> Providing a number of parallel operations for processing the parallel collections paralleldo, groupbykey, combinevalues and flatten 74 / 83

Core Idea Providing a couple of immutable parallel collections PCollection<T> and PTable<K, V> Providing a number of parallel operations for processing the parallel collections paralleldo, groupbykey, combinevalues and flatten Building an execution plan dataflow graph Optimizing the execution plan, and then executing it 74 / 83

FlumeJava Workflow 75 / 83

Parallel Collections A few classes that represent parallel collections and abstract away the details of how data is represented. 76 / 83

Parallel Collections A few classes that represent parallel collections and abstract away the details of how data is represented. PCollection<T>: an immutable bag of elements of type T. PTable<K, V>: an immutable multi-map with keys of type K and values of type V. 76 / 83

Parallel Collections A few classes that represent parallel collections and abstract away the details of how data is represented. PCollection<T>: an immutable bag of elements of type T. PTable<K, V>: an immutable multi-map with keys of type K and values of type V. The main way to manipulate these collections is to invoke a data-parallel operation on them. 76 / 83

Parallel Operations (1/2) paralleldo(): elementwise computation over an input PCollection<T> to produce a new output PCollection<S>. 77 / 83

Parallel Operations (1/2) paralleldo(): elementwise computation over an input PCollection<T> to produce a new output PCollection<S>. groupbykey(): converts a multi-map of type PTable<K, V> into a uni-map of type PTable<K, Collection<V>>. 77 / 83

Parallel Operations (2/2) combinevalues(): takes an input PTable<K, Collection<V>> and an associative combining function on Vs, and returns a PTable<K, V>, where each input collection of values has been combined into a single output value. 78 / 83

Parallel Operations (2/2) combinevalues(): takes an input PTable<K, Collection<V>> and an associative combining function on Vs, and returns a PTable<K, V>, where each input collection of values has been combined into a single output value. flatten(): takes a list of PCollection<T>s and returns a single PCollection<T> that contains all the elements of the input PCollections. 78 / 83

Word Count in FlumeJava public class WordCount { public static void main(string[] args) throws Exception { Pipeline pipeline = new MRPipeline(WordCount.class); PCollection<String> lines = pipeline.readtextfile(args[0]); PCollection<String> words = lines.paralleldo(new DoFn<String, String>() { public void process(string line, Emitter<String> emitter) { for (String word : line.split("\\s+")) { emitter.emit(word); } } }, Writables.strings()); PTable<String, Long> counts = Aggregate.count(words); pipeline.writetextfile(counts, args[1]); } } pipeline.done(); 79 / 83

Summary 80 / 83

Summary Scaling out: shared nothing architecture MapReduce Programming model: Map and Reduce Execution framework FlumeJava Dataflow DAG Parallel collection: PCollection and PTable Transforms: ParallelDo, GroupByKey, CombineValues, Flatten 81 / 83

References J. Dean et al., MapReduce: simplified data processing on large clusters, Communications of the ACM, 2008. C. Chambers et al., FlumeJava: easy, efficient data-parallel pipelines, ACM Sigplan Notices, 2010. J. Lin et al., Data-intensive text processing with MapReduce, Synthesis Lectures on Human Language Technologies, 2010. 82 / 83

Questions? 83 / 83