Running Hadoop. Hadoop Platforms Platforms: Unix and on Windows. – Linux: the only supported production platform. – Other variants of Unix, like Mac OS.

Slides:



Advertisements
Similar presentations
How to Build Big Data Pipelines for Hadoop
Advertisements

IT0483-PRINCIPLES OF CLOUD COMPUTING ,N.ARIVAZHAGAN
Hadoop Programming. Overview MapReduce Types Input Formats Output Formats Serialization Job g/apache/hadoop/mapreduce/package-
Platforms: Unix and on Windows. Linux: the only supported production platform. Other variants of Unix, like Mac OS X: run Hadoop for development. Windows.
Distributed and Parallel Processing Technology Chapter2. MapReduce
Beyond Mapper and Reducer
The map and reduce functions in MapReduce are easy to test in isolation, which is a consequence of their functional style. For known inputs, they produce.
Introduction to cloud computing Jiaheng Lu Department of Computer Science Renmin University of China
Intro to Map-Reduce Feb 21, map-reduce? A programming model or abstraction. A novel way of thinking about designing a solution to certain problems…
Beyond map/reduce functions partitioner, combiner and parameter configuration Gang Luo Sept. 9, 2010.
Mapreduce and Hadoop Introduce Mapreduce and Hadoop
Stephen Tak-Lon Wu Indiana University Some material adapted from slides by Christophe Bisciglia, Aaron Kimball, & Sierra Michels- Slettvet, Google Distributed.
YSmart: Yet Another SQL-to-MapReduce Translator
MapReduce in Action Team 306 Led by Chen Lin College of Information Science and Technology.
Hadoop Technical Review Peng Bo School of EECS, Peking University 7/3/2008 Refer to Aaron Kimball’s slides.
Google MapReduce Framework A Summary of: MapReduce & Hadoop API Slides prepared by Peter Erickson
O’Reilly – Hadoop: The Definitive Guide Ch.5 Developing a MapReduce Application 2 July 2010 Taewhi Lee.
Lecture 11 – Hadoop Technical Introduction. Terminology Google calls it:Hadoop equivalent: MapReduceHadoop GFSHDFS BigtableHBase ChubbyZookeeper.
Hadoop: The Definitive Guide Chap. 2 MapReduce
CS246 TA Session: Hadoop Tutorial Peyman kazemian 1/11/2011.
Hadoop: Nuts and Bolts Data-Intensive Information Processing Applications ― Session #2 Jimmy Lin University of Maryland Tuesday, February 2, 2010 This.
Lecture 3 – Hadoop Technical Introduction CSE 490H.
Poly Hadoop CSC 550 May 22, 2007 Scott Griffin Daniel Jackson Alexander Sideropoulos Anton Snisarenko.
Hadoop Technical Workshop Module II: Hadoop Technical Review.
Hadoop Setup. Prerequisite: System: Mac OS / Linux / Cygwin on Windows Notice: 1. only works in Ubuntu will be supported by TA. You may try other environments.
Introduction to Google MapReduce WING Group Meeting 13 Oct 2006 Hendra Setiawan.
Take An Internal Look at Hadoop Hairong Kuang Grid Team, Yahoo! Inc
Hadoop, Hadoop, Hadoop!!! Jerome Mitchell Indiana University.
Hadoop: The Definitive Guide Chap. 8 MapReduce Features
大规模数据处理 / 云计算 Lecture 3 – Hadoop Environment 彭波 北京大学信息科学技术学院 4/23/2011 This work is licensed under a Creative Commons.
Inter-process Communication in Hadoop
MapReduce Programming Yue-Shan Chang. split 0 split 1 split 2 split 3 split 4 worker Master User Program output file 0 output file 1 (1) fork (2) assign.
Making Apache Hadoop Secure Devaraj Das Yahoo’s Hadoop Team.
Distributed and Parallel Processing Technology Chapter6
Introduction to Hadoop Prabhaker Mateti. ACK Thanks to all the authors who left their slides on the Web. I own the errors of course.
© Spinnaker Labs, Inc. Google Cluster Computing Faculty Training Workshop Module V: Hadoop Technical Review.
Distributed and Parallel Processing Technology Chapter7. MAPREDUCE TYPES AND FORMATS NamSoo Kim 1.
Overview Hadoop is a framework for running applications on large clusters built of commodity hardware. The Hadoop framework transparently provides applications.
CC P ROCESAMIENTO M ASIVO DE D ATOS O TOÑO 2014 Aidan Hogan Lecture VI: 2014/04/14.
HAMS Technologies 1
IBM Research ® © 2007 IBM Corporation INTRODUCTION TO HADOOP & MAP- REDUCE.
大规模数据处理 / 云计算 Lecture 5 – Hadoop Runtime 彭波 北京大学信息科学技术学院 7/23/2013 This work is licensed under a Creative Commons.
Hadoop Introduction Wang Xiaobo Outline Install hadoop HDFS MapReduce WordCount Analyzing Compile image data TeleNav Confidential.
Writing a MapReduce Program 1. Agenda  How to use the Hadoop API to write a MapReduce program in Java  How to use the Streaming API to write Mappers.
Tutorial: Big Data Algorithms and Applications Under Hadoop KUNPENG ZHANG SIDDHARTHA BHATTACHARYYA
O’Reilly – Hadoop: The Definitive Guide Ch.7 MapReduce Types and Formats 29 July 2010 Taikyoung Kim.
Lectures 10 & 11: MapReduce & Hadoop. Placing MapReduce in the course context Programming environments:  Threads On what type of architecture? What are.
Lecture 5 Books: “Hadoop in Action” by Chuck Lam,
Team3: Xiaokui Shu, Ron Cohen CS5604 at Virginia Tech December 6, 2010.
Big Data Infrastructure Week 2: MapReduce Algorithm Design (1/2) This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0.
Cloud Computing Mapreduce (2) Keke Chen. Outline  Hadoop streaming example  Hadoop java API Framework important APIs  Mini-project.
Data-Intensive Computing with MapReduce Jimmy Lin University of Maryland Thursday, January 31, 2013 Session 2: Hadoop Nuts and Bolts This work is licensed.
Airlinecount CSCE 587 Spring Preliminary steps in the VM First: log in to vm Ex: ssh vm-hadoop-XX.cse.sc.edu -p222 Where: XX is the vm number assigned.
Unit 2 Hadoop and big data
Introduction to Google MapReduce
Hadoop Architecture Mr. Sriram
How to download, configure and run a mapReduce program In a cloudera VM Presented By: Mehakdeep Singh Amrit Singh Chaggar Ranjodh Singh.
Map-Reduce framework.
Ch 8 and Ch 9: MapReduce Types, Formats and Features
MapReduce Types, Formats and Features
Google Cluster Computing Faculty Training Workshop
Lecture 17 (Hadoop: Getting Started)
Overview of Hadoop MapReduce MapReduce is a soft work framework for easily writing applications which process vast amounts of.
Lecture 11 – Hadoop Technical Introduction
Hadoop MapReduce Types
Lecture 18 (Hadoop: Programming Examples)
Data processing with Hadoop
Lecture 3 – Hadoop Technical Introduction
MAPREDUCE TYPES, FORMATS AND FEATURES
Map Reduce, Types, Formats and Features
Presentation transcript:

Running Hadoop

Hadoop Platforms Platforms: Unix and on Windows. – Linux: the only supported production platform. – Other variants of Unix, like Mac OS X: run Hadoop for development. – Windows + Cygwin: development platform (openssh) Java 6 – Java 1.6.x (aka 6.0.x aka 6) is recommended for running Hadoop.

Hadoop Installation Download a stable version of Hadoop: – Untar the hadoop file: – tar xvfz hadoop tar.gz JAVA_HOME at hadoop/conf/hadoop-env.sh: – Mac OS: /System/Library/Frameworks/JavaVM.framework/Versions /1.6.0/Home (/Library/Java/Home) – Linux: which java Environment Variables: – export PATH=$PATH:$HADOOP_HOME/bin

Hadoop Modes Standalone (or local) mode – There are no daemons running and everything runs in a single JVM. Standalone mode is suitable for running MapReduce programs during development, since it is easy to test and debug them. Pseudo-distributed mode – The Hadoop daemons run on the local machine, thus simulating a cluster on a small scale. Fully distributed mode – The Hadoop daemons run on a cluster of machines.

Pseudo Distributed Mode Create an RSA key to be used by hadoop when ssh’ing to Localhost: – ssh-keygen -t rsa -P "" – cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys – ssh localhost Configuration Files – Core-site.xml – Mapredu-site.xml – Hdfs-site.xml – Masters/Slaves: localhost

fs.default.name hdfs://localhost/ dfs.replication 1 mapred.job.tracker localhost:8021

Start Hadoop hadoop namenode –format bin/star-all.sh (start-dfs.sh/start-mapred.sh) jps bin/stop-all.sh Web-based UI – (Namenode report) – (Jobtracker)

Basic File Command in HDFS hadoop fs –cmd – hadoop dfs URI: //authority/path – authority: hdfs://localhost:9000 Adding files – hadoop fs –mkdir – hadoop fs -put Retrieving files – hadoop fs -get Deleting files – hadoop fs –rm hadoop fs –help ls

Run WordCount Create an input directory in HDFS Run wordcount example – hadoop jar hadoop-examples jar wordcount /user/jin/input /user/jin/ouput Check output directory – hadoop fs lsr /user/jin/ouput –

References 0.2/quickstart.html 0.2/quickstart.html programming/excerpts/hadoop-tdg/installing- apache-hadoop.html programming/excerpts/hadoop-tdg/installing- apache-hadoop.html noll.com/tutorials/running-hadoop-on- ubuntu-linux-single-node-cluster/ noll.com/tutorials/running-hadoop-on- ubuntu-linux-single-node-cluster/ /hw_files/hadoop_install.pdf /hw_files/hadoop_install.pdf

Hadoop and HFDS Programming

import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; public class PutMerge { public static void main(String[] args) throws IOException { if(args.length != 2) { System.out.println("Usage PutMerge "); System.exit(1); } Configuration conf = new Configuration(); FileSystem hdfs = FileSystem.get(conf); FileSystem local = FileSystem.getLocal(conf); int filesProcessed = 0; Path inputDir = new Path(args[0]); Path hdfsFile = new Path(args[1]); try { FileStatus[] inputFiles = local.listStatus(inputDir); FSDataOutputStream out = hdfs.create(hdfsFile); for(int i = 0; i < inputFiles.length; i++) { if(!inputFiles[i].isDir()) { System.out.println("\tnow processing "); FSDataInputStream in = local.open(inputFiles[i].getPath()); byte buffer[] = new byte[256]; int bytesRead = 0; while ((bytesRead = in.read(buffer)) > 0) { out.write(buffer, 0, bytesRead); } filesProcessed++; in.close(); } out.close(); System.out.println("\nSuccessfully merged " + filesProcessed + " local files and written to in HDFS."); } catch (IOException ioe) { ioe.printStackTrace(); }

import java.io.IOException; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapred.FileInputFormat; import org.apache.hadoop.mapred.FileOutputFormat; import org.apache.hadoop.mapred.JobClient; import org.apache.hadoop.mapred.JobConf; public class MaxTemperature { public static void main(String[] args) throws IOException { if (args.length != 2) { System.err.println("Usage: MaxTemperature "); System.exit(-1); } JobConf conf = new JobConf(MaxTemperature.class); conf.setJobName("Max temperature"); FileInputFormat.addInputPath(conf, new Path(args[0])); FileOutputFormat.setOutputPath(conf, new Path(args[1])); conf.setMapperClass(MaxTemperatureMapper.class); conf.setReducerClass(MaxTemperatureReducer.class); conf.setOutputKeyClass(Text.class); conf.setOutputValueClass(IntWritable.class); JobClient.runJob(conf); }

JobClient.runJob(conf) The client, which submits the MapReduce job. The jobtracker, which coordinates the job run. The jobtracker is a Java application whose main class is JobTracker. The tasktrackers, which run the tasks that the job has been split into. Tasktrackers are Java applications whose main class is TaskTracker. The distributed filesystem, which is used for sharing job files between the other entities.

Job Launch: Client Client program creates a JobConf – Identify classes implementing Mapper and Reducer interfaces setMapperClass(), setReducerClass() – Specify inputs, outputs setInputPath(), setOutputPath() – Optionally, other options too: setNumReduceTasks(), setOutputFormat()…

Job Launch: JobClient Pass JobConf to – JobClient.runJob() // blocks – JobClient.submitJob() // does not block JobClient: – Determines proper division of input into InputSplits – Sends job data to master JobTracker server

Job Launch: JobTracker JobTracker: – Inserts jar and JobConf (serialized to XML) in shared location – Posts a JobInProgress to its run queue

Job Launch: TaskTracker TaskTrackers running on slave nodes periodically query JobTracker for work Retrieve job-specific jar and config Launch task in separate instance of Java – main() is provided by Hadoop

Job Launch: Task TaskTracker.Child.main(): – Sets up the child TaskInProgress attempt – Reads XML configuration – Connects back to necessary MapReduce components via RPC – Uses TaskRunner to launch user process

Job Launch: TaskRunner TaskRunner, MapTaskRunner, MapRunner work in a daisy-chain to launch Mapper – Task knows ahead of time which InputSplits it should be mapping – Calls Mapper once for each record retrieved from the InputSplit Running the Reducer is much the same

public class MaxTemperature { public static void main(String[] args) throws IOException { if (args.length != 2) { System.err.println("Usage: MaxTemperature "); System.exit(-1); } JobConf conf = new JobConf(MaxTemperature.class); conf.setJobName("Max temperature"); FileInputFormat.addInputPath(conf, new Path(args[0])); FileOutputFormat.setOutputPath(conf, new Path(args[1])); conf.setMapperClass(MaxTemperatureMapper.class); conf.setReducerClass(MaxTemperatureReducer.class); conf.setOutputKeyClass(Text.class); conf.setOutputValueClass(IntWritable.class); JobClient.runJob(conf); }

public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length != 2) { System.err.println("Usage: wordcount "); System.exit(2); } Job job = new Job(conf, "word count"); job.setJarByClass(WordCount.class); job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(IntSumReducer.class); job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path(otherArgs[0])); FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); System.exit(job.waitForCompletion(true) ? 0 : 1); }

Creating the Mapper Your instance of Mapper should extend MapReduceBase One instance of your Mapper is initialized by the MapTaskRunner for a TaskInProgress – Exists in separate process from all other instances of Mapper – no data sharing!

Mapper void map ( WritableComparable key, Writable value, OutputCollector output, Reporter reporter ) void map ( WritableComparable key, Writable value, Context context, )

public static class TokenizerMapper extends Mapper { private final static IntWritable one = new IntWritable(1); private Text word = new Text(); public void map(Object key, Text value, Context context ) throws IOException, InterruptedException { StringTokenizer itr = new StringTokenizer(value.toString()); while (itr.hasMoreTokens()) { word.set(itr.nextToken()); context.write(word, one); }

What is Writable? Hadoop defines its own “ box ” classes for strings (Text), integers (IntWritable), etc. All values are instances of Writable All keys are instances of WritableComparable

public class MyWritableComparable implements WritableComparable { // Some data private int counter; private long timestamp; public void write(DataOutput out) throws IOException { out.writeInt(counter); out.writeLong(timestamp); } public void readFields(DataInput in) throws IOException { counter = in.readInt(); timestamp = in.readLong(); } public int compareTo(MyWritableComparable w) { int thisValue = this.value; int thatValue = ((IntWritable)o).value; return (thisValue < thatValue ? -1 : (thisValue==thatValue ? 0 : 1)); }

Getting Data To The Mapper

public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length != 2) { System.err.println("Usage: wordcount "); System.exit(2); } Job job = new Job(conf, "word count"); job.setJarByClass(WordCount.class); job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(IntSumReducer.class); job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path(otherArgs[0])); FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); System.exit(job.waitForCompletion(true) ? 0 : 1); }

Reading Data Data sets are specified by InputFormats – Defines input data (e.g., a directory) – Identifies partitions of the data that form an InputSplit – Factory for RecordReader objects to extract (k, v) records from the input source

FileInputFormat and Friends TextInputFormat – Treats each ‘ \n ’ -terminated line of a file as a value KeyValueTextInputFormat – Maps ‘ \n ’ - terminated text lines of “ k SEP v ” SequenceFileInputFormat – Binary file of (k, v) pairs (passing data between the output of one MapReduce job to the input of some other MapReduce job) SequenceFileAsTextInputFormat – Same, but maps (k.toString(), v.toString())

Filtering File Inputs FileInputFormat will read all files out of a specified directory and send them to the mapper Delegates filtering this file list to a method subclasses may override – e.g., Create your own “ xyzFileInputFormat ” to read *.xyz from directory list

Record Readers Each InputFormat provides its own RecordReader implementation – Provides (unused?) capability multiplexing LineRecordReader – Reads a line from a text file KeyValueRecordReader – Used by KeyValueTextInputFormat

Input Split Size FileInputFormat will divide large files into chunks – Exact size controlled by mapred.min.split.size RecordReaders receive file, offset, and length of chunk Custom InputFormat implementations may override split size – e.g., “ NeverChunkFile ”

public class ObjectPositionInputFormat extends FileInputFormat { public RecordReader getRecordReader( InputSplit input, JobConf job, Reporter reporter) throws IOException { reporter.setStatus(input.toString()); return new ObjPosRecordReader(job, (FileSplit)input); } InputSplit[] getSplits(JobConf job, int numSplits) throuw IOException; }

class ObjPosRecordReader implements RecordReader { public ObjPosRecordReader(JobConf job, FileSplit split) throws IOException {} public boolean next(Text key, Point3D value) throws IOException { // get the next line} public Text createKey() { } public Point3D createValue() { } public long getPos() throws IOException { } public void close() throws IOException { } public float getProgress() throws IOException {} }

Sending Data To Reducers Map function receives OutputCollector object – OutputCollector.collect() takes (k, v) elements Any (WritableComparable, Writable) can be used

WritableComparator Compares WritableComparable data – Will call WritableComparable.compare() – Can provide fast path for serialized data JobConf.setOutputValueGroupingComparator()

Sending Data To The Client Reporter object sent to Mapper allows simple asynchronous feedback – incrCounter(Enum key, long amount) – setStatus(String msg) Allows self-identification of input – InputSplit getInputSplit()

Partition And Shuffle

Partitioner int getPartition(key, val, numPartitions) – Outputs the partition number for a given key – One partition == values sent to one Reduce task HashPartitioner used by default – Uses key.hashCode() to return partition num JobConf sets Partitioner implementation

public class MyPartitioner implements Partitioner public int getPartition(IntWritable key, Text value, int numPartitions) { /* Pretty ugly hard coded partitioning function. Don't do that in practice, it is just for the sake of understanding. */ int nbOccurences = key.get(); if( nbOccurences < 3 ) return 0; else return 1; public void configure(JobConf arg0) { } conf.setPartitionerClass(MyPartitioner.class);

Reduction reduce( WritableComparable key, Iterator values, OutputCollector output, Reporter reporter) Keys & values sent to one partition all go to the same reduce task Calls are sorted by key – “ earlier ” keys are reduced and output before “ later ” keys

public static class IntSumReducer extends Reducer { private IntWritable result = new IntWritable(); public void reduce(Text key, Iterable values, Context context ) throws IOException, InterruptedException { int sum = 0; for (IntWritable val : values) { sum += val.get(); } result.set(sum); context.write(key, result); }

Finally: Writing The Output

OutputFormat Analogous to InputFormat TextOutputFormat – Writes “ key val\n ” strings to output file SequenceFileOutputFormat – Uses a binary format to pack (k, v) pairs NullOutputFormat – Discards output

public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length != 2) { System.err.println("Usage: wordcount "); System.exit(2); } Job job = new Job(conf, "word count"); job.setJarByClass(WordCount.class); job.setMapperClass(TokenizerMapper.class); job.setCombinerClass(IntSumReducer.class); job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path(otherArgs[0])); FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); System.exit(job.waitForCompletion(true) ? 0 : 1); }