Assignment #4 - Hadoop Parallel Data Processing

Due by Wednesday, April 22.

In this assignment, you will develop an application using the Hadoop parallel data processing platform. This will allow you to gain practical experience using the MapReduce programming model and to learn to parallelize for performance when processing large-scale data.

Hadoop System Structure:

A Hadoop cluster has two parts: the Hadoop Distributed File System (HDFS) and the MapReduce framework. Each of these systems performs a distinct task, but they work together to process large amounts of data. HDFS stores files across the cluster, spreading them out so it can hold files that are larger than what any individual node could store. MapReduce takes Java programs and handles both running them near where the data is stored and scheduling tasks to not overload the nodes.

HDFS is made of a single NameNode and multiple DataNodes. The NameNode tracks the location of the files in the DataNodes and is responsible for coordinating them to ensure consistency of data. When a user wishes to read data, it asks the NameNode for which DataNodes hold the data and then contacts the DataNodes to get the data. Similarly, when writing data the user asks the NameNode where to store the data and then uploads the data directly to the DataNodes. To handle large files, HDFS splits files into blocks of uniform size. DataNodes hold blocks instead of files, and blocks from a single file may be spread across multiple DataNodes. If you are interested in more detail about the architecture of HDFS, you can read the HDFS Architecture Guide.

MapReduce is made of a single JobTracker and multiple TaskTrackers. Users write MapReduce jobs, which consist of two types of tasks: maps and reduces. The JobTracker takes a description of these tasks and schedules them across the TaskTrackers. One TaskTracker runs on each DataNode, and the JobTracker ensures that tasks run close to the nodes that have the data for them.

Hadoop Programming:

The MapReduce Tutorial provides an excellent start to understand the general structure of a MapReduce program and as a template to start with your own programs. Please consider the following as you search the web for useful examples: try to find simple algorithms that, in principle, follow the mechanism you are trying to implement for your program. For example, as you are trying to implement a matrix-vector multiplication, perhaps a matrix transpose operation (which is simpler) will serve as a good guide.

The Hadoop API is the place to check for detailed information on what function to call. Some of the more useful classes are JobConf and the InputFormat subclasses. You will have to implement subclasses of Tool, Mapper, and Reducer. Extending MapReduceBase will give you empty versions of functions not all map or reduce tasks need.

All of the official documentation can be found at the main documentation index. A wealth of examples can be found on the web, which should guide you in building your own programs. When you use online resources, please make sure that they are up-to-date; the Hadoop API has undergone a few revisions and some functionality and API references you might find can be out of date. And of course, always use said examples as you should treat work by others; if you build upon them, add appropriate references to your code and your report.

Applications:

You are asked to implement/experiment with the following applications in this assignment:
  1. Word Count
    This is the warm-up part, to get you acquainted with Hadoop. This application can be built using the MapReduce tutorial alone, so make sure to read it carefully and understand it. You should count the number of files each word appears in. Your word identification should be case-insensitive and ignore anything that isn't a letter. For correctness tests, you can find 37 text files from Project Gutenberg in the /users/input/gutenberg HDFS directory in the cluster. Some words used in all of the files are: for, one, thousand, and years. Some words used in only a single file are: academics, faints, tag, and yams. We provide another dataset in the /users/input/websters HDFS directory for performance testing.

    Possibly helpful hint: Here is the code for a mapper to get a file name for its input:
            FileSplit fileSplit = (FileSplit) reporter.getInputSplit();
            String filename = fileSplit.getPath().getName();
        
  2. Jacobi Method
    Please first read this simple Wikipedia page about the Jacobi method to solve a system of linear equations! It is an iterative solver, and in this sense it resembles in principle the mechanism employed to solve problems such as PageRank. To solve a system of linear equations "Ax = b" with the Jacobi method, we start by pre-assigning a set of values to vector x (e.g. all zeros) and update these values after running a few rounds of the method. When the values of vector x do not change between two rounds, or they don't change beyond a certain, pre-defined threshold of a few significant digits (let's call this "divergence"), the algorithm has reached a solution (has converged according to the defined threshold). The exact number of required iterations will depend on the problem (matrix A and the right-hand-side vector b), initial values of vector x, and how accurate you want the solution to be (a few significant digits). To guarantee convergence, we will be working with artificially built matrices that are guaranteed to be "strict diagonally dominant" (convergence condition). The sequential version of the algorithm can be reached from the class account, at the NFS directory /u/cs258/apps/jacobi/seq.

    The input for this program will be a text file which describes a matrix A[NxN] and a right-hand-side vector b[N]. This file contains both A and b as a single matrix Ab[N x (N+1)], where A makes the first N columns, and b makes the last column. Every row of this file contains an entry of the matrix Ab in space-separated tuples of row(int), column(int) and value(double). You will find such inputs at the HDFS directory /users/input/jacobi, marked as /users/input/jacobi/Number.dat, where Number is the value N. Use smaller values of N to test for correctness --- use the larger matrices for performance evaluation. According to our experience, Hadoop expects truly massive files to offer good performance.

    How to Use the CSUG Hadoop Cluster Setup:

    Hadoop can be used from any .csug host. (for example cycle1.csug.rochester.edu)

    Setting up the "ENVIRONMENT VARIABLES"

    With the following commands, you can setup your environmental variables for Hadoop.

    	 export JAVA_HOME=/usr/lib/jvm/java 
    	 export HADOOP_HOME=/u/hduser/hadoop 
    

    Setting up the "Working Directory"

    To use Hadoop Distributed File System (HDFS), you need to have a user working directory. This working directory is the place on the HDFS that you can use to store your files.

    (example is written for user cs258)

    Make a working directory:

    	 $HADOOP_HOME/bin/hdfs dfs -ls /users 
    	 $HADOOP_HOME/bin/hdfs dfs -mkdir /users/cs258 
    

    Please note that in above commands, after dfs, you can use any commands for distributed file system (e.g., -ls, -mkdir, -put etc.). The list of possible commands can be found here.

    All the users' directories are under /users/ where you should make your own directory. Please make sure that you set proper access permissions using the chmod command for your working directory.

    NOTE: Please make sure to remove your directory from the HDFS after you are done with the assignment.

    Cluster Courtesy:

    In order to test your code and ensure that others can test their code, you need to pay attention to what jobs are running on the cluster. You can do this by checking the cluster status page (see details below). If someone is running a job already, please wait until it is complete to start your own. Conversely, please make sure to introduce a delay between your job submissions so others have a chance to run.

    If your code has a bug in it that causes it to run indefinitely, then you can stop it with the command $HADOOP_HOME/bin/hadoop job -kill <job_ID> where job_ID is the ID given in the log at the start of your job, on the cluster status page, or in the output of the job list command above. Please note that simply killing the program running on your own computer is not enough to stop the job on the cluster. If you suspect that someone else's program is left hanging in the system, please e-mail him/her and ask him/her to kill the task, and if the problem is not resolved let the TA know.

    On csug:

    From the university network, you can check the status of the HDFS cluster at http://node01.csug.rochester.edu:50070/
    using a web browser or using the lynx tool from a terminal, which shows the status of the DataNodes and allows you to view the files in the cluster. Similarly, http://node01.csug.rochester.edu:8088/ shows the status of the TaskTrackers and the jobs that will run, are running, and have run on the MapReduce cluster. There is a link for every job, which will display the current status, number of tasks, and various statistics for the run. Alternatively, the command $HADOOP_HOME/bin/hadoop job -list will provide the same information.

    Build/Run Your Programs:

    To compile your code (e.g., WordCount.java) you should first set the environmental variable for hadoop's java class path (use setenv if using csh):
    	export HADOOP_CLASSPATH=${JAVA_HOME}/lib/tools.jar
    
    Next, you can use the following commands to compile your WordCount.java source to a jar file:
    	 $HADOOP_HOME/bin/hadoop com.sun.tools.javac.Main WordCount.java
    	 jar cf WordCount.jar WordCount*.class 
    

    You can run a class from that jar file with the following command:

          $HADOOP_HOME/bin/hadoop jar WordCount.jar <class> <arguments>
    
    Where class is the name of your main class (i.e., WordCount in this example) and the arguments are passed to your program (e.g., can be the directories for input and output). For this example we have:
    	 $HADOOP_HOME/bin/hadoop jar WordCount.jar WordCount [path to input file] [path to output file] 
    
    The hadoop program will automatically read the configuration to run your program on the cluster. It will output a log file containing any errors and a simple progress meter. At the end it will output a small pile of counters. You may find the following useful when attempting to debug your programs:
        * Map input records
        * Map output records
        * Combine input records
        * Combine output records
        * Reduce input records
        * Reduce output records
    
    MapReduce tasks generally expect their input and output to be in the HDFS cluster. You need to create your home directories in the HDFS cluster and they should be named as /users/, where is your csug login. You can upload a file from csug machines to HDFS with the command $HADOOP_HOME/bin/hdfs dfs -put <localfile /users/username/.> , which will upload localfile into your home directory on the HDFS cluster. Since the input files for your program are read-only, you don't have to copy them to your HDFS home directories --- you can just instruct your applications to get input from the /users/input/ HDFS directory. Similarly, files can be downloaded via $HADOOP_HOME/bin/hdfs dfs -get <file> ., which will download the file from HDFS to your current directory. You will be provided with useful help info when you try to use a utility without parameters; for example, $HADOOP_HOME/bin/hdfs dfs will give you a set of commands that you can apply to HDFS.

    Each MapReduce task must have an output path that must not exist before running the program; it will be created as a directory in HDFS. That directory will contain logs of your program. The output from the reduce tasks will be saved as part-00000 (large outputs will create part-00001 and so on, but that is unlikely to happen for this assignment). If your output is a text file, you can read it without downloading it with the command $HADOOP_HOME/bin/hdfs dfs -cat <output_directory>/part-00000 (where output_directory is the path set by your program). If you used a SequenceFileOutputFormat, you can get a text version with $HADOOP_HOME/bin/hdfs dfs -text <output_directory>/part-00000.

    Measuring Perfomance:

    In order to measure the performance of your code, you need to test it with varying levels of parallelism. You can control the number of map tasks run by your code by varying the number of blocks in your input data or suggesting min/max split sizes for your InputFormat in your Hadoop job driver (main program).

    You can check the log of your program for a "Launched map tasks" counter, which will tell you how many tasks were run at once to handle your data.

    Turn-in:

    You are asked to turn in your source files and a README file. The README file should be in pdf format. It should contain a description of your design, what is and what is not realized in your implementation. If your program requires any special compilation flag to build, you need to specify the full build command in the README file. The README file should also include any additional information needed to run your code.

    You should electronically turn in the required files. Instructions for electronic turn-in can be found on the course Web site.

    Grading guideline:

    • 30%: correct implementation of WordCount.
    • 30%: correct implementation of Jacobi Method.
    • 30%: performance of your solution. This is equally split across the two applications.
    • 10%: a clear README file, clarity of your source code and completeness of your comments.

    Reference:

    This assignment is adapted from one created by Prof. Kai Shen.