Hadoop

Apache Hadoop is a software framework that supports data-intensive distributed applications under a free license. "Hadoop is a framework for running applications on large clusters of commodity hardware. The Hadoop framework transparently provides applications both reliability and data motion. Hadoop implements a computational paradigm named map/reduce, where the application is divided into many small fragments of work, each of which may be executed or re-executed on any node in the cluster. In addition, it provides a distributed file system that stores data on the compute nodes, providing very high aggregate bandwidth across the cluster. Both map/reduce and the distributed file system are designed so that node failures are automatically handled by the framework." Hadoop Overview It enables applications to work with thousands of nodes and petabytes of data. Hadoop was inspired by Googles's MapReduce and Google File System (GFS) papers.

The MapReduce model is documented in this paper from Google labs.

This page does not describe how to use MapReduce or Hadoop. It focuses on two sentences toward the end of the MapReduce paper. Specifically the statement:

The MapReduce implementation relies on an in-house cluster management system that is responsible for dis- tributing and running user tasks on a large collection of shared machines. Though not the focus of this paper, the cluster management system is similar in spirit to other systems such as Condor [16].

Using the SGE cluster management solution on Cheaha to run Hadoop is the focus of this document.

Requirements
Running Hadoop on Cheaha has two dependencies.
 * 1) you must download and unpack hadoop into your home directory
 * 2) you must reserve a mini-cluster in which to run your hadoop cluster as described in the mini-cluster example

Additionally, you may want to set up a VNC session to interact with your hadoop cluster via a web browser, especially when first exploring hadoop.

Background
Before approaching Hadoop to do solve problems, you need become familiar with the Map Reduce model for solving problems. This is a model common to functional programming (Lisp) so an understanding of that domain helps has well.

A simplified description of map reduce is to think in terms of lists of data (eg. arrays). The map functions iterate over the list (eg. recurse) and identify elements of interest. The reduce step works on the identified elements and further processes them. For example, it could add the terms selected by the map operation and produce a final sum, if you are work on lists of numbers. Or, more simply, the reduce operation could just print the terms selected by the map operation. (Note: DBA's may recognize this as the pattern "SELECT function(x) WHERE ... GROUP BY x")

More MapReduce examples are described in this paper from Google labs.

There are much better ways to learn the MapReduce model than the Hadoop framework. Working with Hadoop means you will write code in Java and have to deal with framework designed to handle a wide range of problems at scale. This means there's some complexity to understanding the framework before you can use it effectively.

A simple example provided by Dr. Jonas Almeida is to start with a simple list of numbers [1,2,3,4,5] and create a map operation, say "times 2", that selects elements and maps the (multiplies them by 2) into a new result list. The reduce operation then adds the mapped numbers together producing the result 30. You can try out this simple example in any browser, or if your JavaScript is rusty, you can go to the CoffeScript->Try CoffeScript tab and enter the following example

y=[1,2,3,4,5] z=x.map((x)->2*x).reduce((a,b)->a+b) alert(y)

It will translate this into JavaScript for you and when you press the "Run" button produce an answer. If you liked that, try same the thing straight in javascript in the console of your browser:

[1,2,3,4,5].map(function(x){return 2*x}).reduce(function(a,b){return a+b})

The MapReduce pattern makes this basic construct much more generic and powerful by having the map function emitt a key with each value such that each unique key can be associated with its own reduce function. Complex workflows can be distributed using this pattern, as elegantly illustrated in mapreduce-js.googlecode.com

This should give you a sense of the logic behind MapReduce. A large class of problems can be broken down into Map and Reduce operations which frameworks like Hadoop can then easily distribute to large pools of computers, hence the popularity of Hadoop. The Map-Reduce model makes it much easier to describe a solution that can then be easily distributed.

Hadoop Single Process mode
The first step to getting hadoop running on the cluster for testing is to set up a job for single node mode.

The following hadoop.qsub will get you started after downloading hadoop
 * 1) !/bin/bash
 * 2) $ -S /bin/bash
 * 3) $ -cwd
 * 4) $ -N hadoop-single
 * 5) $ -pe smp 1
 * 6) $ -l h_rt=00:10:00,s_rt=0:08:00,vf=1G
 * 7) $ -j y
 * 8) $ -M jpr@uab.edu
 * 9) $ -m eas
 * 10) Load the appropriate module files
 * 11) $ -V
 * 1) $ -m eas
 * 2) Load the appropriate module files
 * 3) $ -V
 * 1) $ -V


 * 1) env | sort

cd hadoop-current rm -rf input/ output/ cd ..
 * 1) cat $TMPDIR/machines
 * 2) reset environment
 * 1) reset environment

echo "configure hadoop:" echo localhost > hadoop-current/conf/masters echo localhost > hadoop-current/conf/slaves cp hadoop-current/conf/core-site.xml-template-single hadoop-current/conf/core-site.xml cp hadoop-current/conf/hdfs-site.xml-template-single hadoop-current/conf/hdfs-site.xml cp hadoop-current/conf/mapred-site.xml-template-single hadoop-current/conf/mapred-site.xml
 * 1) sets up the hadoop nodes based on the assigned host slots
 * 2) - one node is selected as the the master for namenode and jobtracker
 * 3) - the rest of the nodes serve as slave nodes for task and data nodes
 * 1) - the rest of the nodes serve as slave nodes for task and data nodes

cd hadoop-current

mkdir input cp conf/*.xml input bin/hadoop jar hadoop-examples-*.jar grep input output 'dfs[a-z.]+' cat output/*

exit

bin/hadoop namenode -format
 * 1) Format a new distributed-filesystem:

bin/start-all.sh
 * 1) Start the hadoop daemons:


 * 1) The hadoop daemon log output is written to the ${HADOOP_LOG_DIR} directory (defaults to ${HADOOP_HOME}/logs).
 * 2) Browse the web interface for the NameNode and the JobTracker; by default they are available at:
 * 3)    NameNode - http://localhost:50070/
 * 4)    JobTracker - http://localhost:50030/
 * 1)    NameNode - http://localhost:50070/
 * 2)    JobTracker - http://localhost:50030/

bin/hadoop fs -put conf input
 * 1) Copy the input files into the distributed filesystem:

bin/hadoop jar hadoop-examples-*.jar grep input output 'dfs[a-z.]+'
 * 1) Run some of the examples provided:


 * 1) Examine the output files:

bin/hadoop fs -get output output cat output/*
 * 1) Copy the output files from the distributed filesystem to the local filesytem and examine them:


 * or

bin/hadoop fs -cat output/*
 * 1) View the output files on the distributed filesystem:

sleep 520

bin/stop-all.sh
 * 1) When you're done, stop the daemons with: