Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to Map-Reduce Feb 21, 2014. map-reduce? A programming model or abstraction. A novel way of thinking about designing a solution to certain problems…

Similar presentations


Presentation on theme: "Intro to Map-Reduce Feb 21, 2014. map-reduce? A programming model or abstraction. A novel way of thinking about designing a solution to certain problems…"— Presentation transcript:

1 Intro to Map-Reduce Feb 21, 2014

2 map-reduce? A programming model or abstraction. A novel way of thinking about designing a solution to certain problems… Feb 21, 2014CS512 | Spring 2014

3 Why? We have access to huge volumes of data. Facebook posts and photos, twitter streams, … Feb 21, 2014CS512 | Spring 2014

4 Easy… Computational resources are cheap. Amazon EC2, Microsoft Azure, … Feb 21, 2014CS512 | Spring 2014

5 Not really! Code running on one CPU is simple, two is a headache, four is a nightmare, … You get the picture. Feb 21, 2014CS512 | Spring 2014

6 Pipe Dream Forget multiple machines. Just write code imagining one CPU. Someone else takes care of running the code on thousands of machine. Free the programmer from the unnecessary details. Feb 21, 2014CS512 | Spring 2014

7 Map-Reduce map-reduce programming model to the rescue Feb 21, 2014CS512 | Spring 2014

8 Long long ago… LISP, 1958 A programming language that introduced several innovative ideas Feb 21, 2014CS512 | Spring 2014 Recursive Functions of Symbolic Expression and Their Computation by Machine, Part I John McCarthy, MIT, April 1960

9 LISP Introduced map and reduce. Feb 21, 2014CS512 | Spring 2014

10 Map map(m f, [a 1, a 2, …a n ]) -> [b 1, b 2, …, b n ] Accepts two arguments: a function and a list of values. Generates output by repeatedly applying the function on the list of values. Feb 21, 2014CS512 | Spring 2014

11 Reduce reduce(r f, [b 1, b 2, …b n ]) -> c Accepts two arguments: a function and a list of values. Generates output by reducing the list of input values using the function. Feb 21, 2014CS512 | Spring 2014

12 Simple composition Map’s output is a list of values, which reduce can accept as one of its argument. Feb 21, 2014CS512 | Spring 2014

13 Analogy  Break large problem into small pieces  Code m f to solve one piece  Run map to apply m f on the small pieces and generate nuggets of solutions  Code r f to combine the nuggets  Run reduce to apply r f on the nuggets to output the complete solution Feb 21, 2014CS512 | Spring 2014

14 Example 1TB file split into 100,000 chunks Count number of lines in each chunk Add counts together to output final line count Feb 21, 2014CS512 | Spring 2014

15 A slightly different map-reduce Map Copies a function on a number of machines and applies each copy on different pieces of the input Reduce Combine the map outputs from different machines into a final solution Feb 21, 2014CS512 | Spring 2014

16 Map-reduce reintroduced… Google created the awareness Hadoop made it into a sensation Hadoop is an open-source map-reduce implementation based on Google’s paper. Feb 21, 2014CS512 | Spring 2014 MapReduce: Simplified Data Processing on Large Clusters Jeffrey Dean and Sanjay Ghemawat OSDI'04: Sixth Symposium on Operating System Design and Implementation. December, 2004.

17 Hadoop Feb 21, 2014CS512 | Spring 2014

18 Example Feb 21, 2014CS512 | Spring 2014

19 Terminology Mapper Instance of the map function Reducer Instance of the reduce function Feb 21, 2014CS512 | Spring 2014

20 Job User’s implementation of map and reduce functions Feb 21, 2014CS512 | Spring 2014

21 Splitting the input  User submits job and specifies the input files.  Input files are split into chunks.  Chunks are fed to the mappers typically over a distributed file system like HDFS. Feb 21, 2014CS512 | Spring 2014

22 Copying the job JobTracker  Hadoop service that copies the map and reduce code to available machines.  Feeds the input to the mappers and connects their outputs to reducers. Feb 21, 2014CS512 | Spring 2014

23 Maps in parallel  Maps run in parallel.  Each maps operates on a set of chunks assigned to it by the job tracker.  Maps write to local disk. Feb 21, 2014CS512 | Spring 2014

24 What if maps fail? Re-run failed maps. No need to re-run succeeded maps. Why does this work? Maps typically are idempotent. Feb 21, 2014CS512 | Spring 2014

25 Input to reducers #reducers (n) known a priori. #partitions equals #reducers. Hash on the keys of mapper outputs. partition = hash(key) mod n Load balancing by randomization. Feb 21, 2014CS512 | Spring 2014

26 Wait before reducing… Cannot start reducers before mappers complete. Synchronization barrier between map and reduce phases. Why? Feb 21, 2014CS512 | Spring 2014

27 Embarrassing Parallelism Feb 21, 2014CS512 | Spring 2014

28 Not a panacea! If your workload exhibits embarrassing parallelism, Hadoop might be the ideal framework. If not, look for other parallel programming paradigms. Feb 21, 2014CS512 | Spring 2014

29 Example Feb 21, 2014CS512 | Spring 2014

30 WordCount Feb 21, 2014CS512 | Spring 2014 https://developer.yahoo.com/hadoop/tutorial/module4.html

31 Mapper public static class MyMapper implements Mapper { private final static IntWritable one = new IntWritable(1); private Text word = new Text(); public void map(LongWritable key, Text value, OutputCollector output, Reporter reporter) throws IOException { // Split the given line (in value) into words and emit for each word the tuple String line = value.toString(); StringTokenizer itr = new StringTokenizer(line); while (itr.hasMoreTokens()) { word.set(itr.nextToken()); output.collect(word, one); } Feb 21, 2014CS512 | Spring 2014 https://developer.yahoo.com/hadoop/tutorial/module4.html

32 Reducer public static class MyReducer implements Reducer { public void reduce(Text key, Iterator values, OutputCollector output, Reporter reporter) throws IOException { int sum = 0; while (values.hasNext()) { sum += values.next().get(); } output.collect(key, new IntWritable(sum)); } Feb 21, 2014CS512 | Spring 2014 https://developer.yahoo.com/hadoop/tutorial/module4.html


Download ppt "Intro to Map-Reduce Feb 21, 2014. map-reduce? A programming model or abstraction. A novel way of thinking about designing a solution to certain problems…"

Similar presentations


Ads by Google