Wednesday, 26 September 2012

Practice on Ubuntu with JAVA

Leave a Comment

Uninstall OpenJDK (if installed)

First we’ll check which OpenJDK packages are installed.
sudo dpkg --list | grep -i jdk
Next, let’s uninstall OpenJDK related packages. Edit the list of packages below if you have additional or different OpenJDK packages installed.
sudo apt-get purge icedtea-* openjdk-*
Let’s check that all OpenJDK packages have been removed.
sudo dpkg --list | grep -i jdk
Read More...

Monday, 24 September 2012

HDFS - A Short Story

Leave a Comment

Part - 1 


Part - 2
 Part - 3
 Part - 4

Part - 5

Read More...

Saturday, 22 September 2012

Interview Questions & Answers for Hadoop MapReduce developers

Leave a Comment

    1. What is a JobTracker in Hadoop? How many instances of JobTracker run on a Hadoop Cluster?
    2. JobTracker is the daemon service for submitting and tracking MapReduce jobs in Hadoop. There is only One Job Tracker process run on any hadoop cluster. Job Tracker runs on its own JVM process. In a typical production cluster its run on a separate machine. Each slave node is configured with job tracker node location. The JobTracker is single point of failure for the Hadoop MapReduce service. If it goes down, all running jobs are halted. JobTracker in Hadoop performs following actions(from Hadoop Wiki:)
      • Client applications submit jobs to the Job tracker.
      • The JobTracker talks to the NameNode to determine the location of the data
      • The JobTracker locates TaskTracker nodes with available slots at or near the data
      • The JobTracker submits the work to the chosen TaskTracker nodes.
      • The TaskTracker nodes are monitored. If they do not submit heartbeat signals often enough, they are deemed to have failed and the work is scheduled on a different TaskTracker.
      • A TaskTracker will notify the JobTracker when a task fails. The JobTracker decides what to do then: it may resubmit the job elsewhere, it may mark that specific record as something to avoid, and it may may even blacklist the TaskTracker as unreliable.
      • When the work is completed, the JobTracker updates its status.

      • Client applications can poll the JobTracker for information.

    3. How JobTracker schedules a task?
    4. The TaskTrackers send out heartbeat messages to the JobTracker, usually every few minutes, to reassure the JobTracker that it is still alive. These message also inform the JobTracker of the number of available slots, so the JobTracker can stay up to date with where in the cluster work can be delegated. When the JobTracker tries to find somewhere to schedule a task within the MapReduce operations, it first looks for an empty slot on the same server that hosts the DataNode containing the data, and if not, it looks for an empty slot on a machine in the same rack.

    5. What is a Task Tracker in Hadoop? How many instances of TaskTracker run on a Hadoop Cluster
    6. A TaskTracker is a slave node daemon in the cluster that accepts tasks (Map, Reduce and Shuffle operations) from a JobTracker. There is only One Task Tracker process run on any hadoop slave node. Task Tracker runs on its own JVM process. Every TaskTracker is configured with a set of slots, these indicate the number of tasks that it can accept. The TaskTracker starts a separate JVM processes to do the actual work (called as Task Instance) this is to ensure that process failure does not take down the task tracker. The TaskTracker monitors these task instances, capturing the output and exit codes. When the Task instances finish, successfully or not, the task tracker notifies the JobTracker. The TaskTrackers also send out heartbeat messages to the JobTracker, usually every few minutes, to reassure the JobTracker that it is still alive. These message also inform the JobTracker of the number of available slots, so the JobTracker can stay up to date with where in the cluster work can be delegated.

    7. What is a Task instance in Hadoop? Where does it run?
    8. Task instances are the actual MapReduce jobs which are run on each slave node. The TaskTracker starts a separate JVM processes to do the actual work (called as Task Instance) this is to ensure that process failure does not take down the task tracker. Each Task Instance runs on its own JVM process. There can be multiple processes of task instance running on a slave node. This is based on the number of slots configured on task tracker. By default a new task instance JVM process is spawned for a task.

    9. How many Daemon processes run on a Hadoop system?
    10. Hadoop is comprised of five separate daemons. Each of these daemon run in its own JVM.Following 3 Daemons run on Master nodes NameNode - This daemon stores and maintains the metadata for HDFS. Secondary NameNode - Performs housekeeping functions for the NameNode. JobTracker - Manages MapReduce jobs, distributes individual tasks to machines running the Task Tracker. Following 2 Daemons run on each Slave nodes DataNode – Stores actual HDFS data blocks. TaskTracker - Responsible for instantiating and monitoring individual Map and Reduce tasks.

    11. What is configuration of a typical slave node on Hadoop cluster? How many JVMs run on a slave node?
      • Single instance of a Task Tracker is run on each Slave node. Task tracker is run as a separate JVM process.
      • Single instance of a DataNode daemon is run on each Slave node. DataNode daemon is run as a separate JVM process.
      • One or Multiple instances of Task Instance is run on each slave node. Each task instance is run as a separate JVM process. The number of Task instances can be controlled by configuration. Typically a high end machine is configured to run more task instances.

    12. How NameNode Handles data node failures?
    13. NameNode periodically receives a Heartbeat and a Blockreport from each of the DataNodes in the cluster. Receipt of a Heartbeat implies that the DataNode is functioning properly. A Blockreport contains a list of all blocks on a DataNode. When NameNode notices that it has not recieved a hearbeat message from a data node after a certain amount of time, the data node is marked as dead. Since blocks will be under replicated the system begins replicating the blocks that were stored on the dead datanode. The NameNode Orchestrates the replication of data blocks from one datanode to another. The replication data transfer happens directly between datanodes and the data never passes through the namenode.

    14. Does MapReduce programming model provide a way for reducers to communicate with each other? In a MapReduce job can a reducer communicate with another reducer?
    15. Nope, MapReduce programming model does not allow reducers to communicate with each other. Reducers run in isolation.

    16. Can I set the number of reducers to zero?
    17. Yes, Setting the number of reducers to zero is a valid configuration in Hadoop. When you set the reducers to zero no reducers will be executed, and the output of each mapper will be stored to a separate file on HDFS. [This is different from the condition when reducers are set to a number greater than zero and the Mappers output (intermediate data) is written to the Local file system(NOT HDFS) of each mappter slave node.]

    18. Where is the Mapper Output (intermediate key-value data) stored ?
    19. The mapper output (intermediate data) is stored on the Local file system (NOT HDFS) of each individual mapper nodes. This is typically a temporary directory location which can be setup in config by the hadoop administrator. The intermediate data is cleaned up after the Hadoop Job completes.

    20. What are combiners? When should I use a combiner in my MapReduce Job?
    21. Combiners are used to increase the efficiency of a MapReduce program. They are used to aggregate intermediate map output locally on individual mapper outputs. Combiners can help you reduce the amount of data that needs to be transferred across to the reducers. You can use your reducer code as a combiner if the operation performed is commutative and associative. The execution of combiner is not guaranteed, Hadoop may or may not execute a combiner. Also, if required it may execute it more then 1 times. Therefore your MapReduce jobs should not depend on the combiners execution.

    22. What is Writable & WritableComparable interface?
      • org.apache.hadoop.io.Writable is a Java interface. Any key or value type in the Hadoop Map-Reduce framework implements this interface. Implementations typically implement a static read(DataInput) method which constructs a new instance, calls readFields(DataInput) and returns the instance.
      • org.apache.hadoop.io.WritableComparable is a Java interface. Any type which is to be used as a key in the Hadoop Map-Reduce framework should implement this interface. WritableComparable objects can be compared to each other using Comparators.

    23. What is the Hadoop MapReduce API contract for a key and value Class?
      • The Key must implement the org.apache.hadoop.io.WritableComparable interface.
      • The value must implement the org.apache.hadoop.io.Writable interface.

    24. What is a IdentityMapper and IdentityReducer in MapReduce ?
      • org.apache.hadoop.mapred.lib.IdentityMapper Implements the identity function, mapping inputs directly to outputs. If MapReduce programmer do not set the Mapper Class using JobConf.setMapperClass then IdentityMapper.class is used as a default value.
      • org.apache.hadoop.mapred.lib.IdentityReducer Performs no reduction, writing all input values directly to the output. If MapReduce programmer do not set the Reducer Class using JobConf.setReducerClass then IdentityReducer.class is used as a default value.

    25. What is the meaning of speculative execution in Hadoop? Why is it important?
    26. Speculative execution is a way of coping with individual Machine performance. In large clusters where hundreds or thousands of machines are involved there may be machines which are not performing as fast as others. This may result in delays in a full job due to only one machine not performaing well. To avoid this, speculative execution in hadoop can run multiple copies of same map or reduce task on different slave nodes. The results from first node to finish are used.

    27. When the reducers are started in a MapReduce job?
    28. In a MapReduce job reducers do not start executing the reduce method until the all Map jobs have completed. Reducers start copying intermediate key-value pairs from the mappers as soon as they are available. The programmer defined reduce method is called only after all the mappers have finished.

    29. If reducers do not start before all mappers finish then why does the progress on MapReduce job shows something like Map(50%) Reduce(10%)? Why reducers progress percentage is displayed when mapper is not finished yet?
    30. Reducers start copying intermediate key-value pairs from the mappers as soon as they are available. The progress calculation also takes in account the processing of data transfer which is done by reduce process, therefore the reduce progress starts showing up as soon as any intermediate key-value pair for a mapper is available to be transferred to reducer. Though the reducer progress is updated still the programmer defined reduce method is called only after all the mappers have finished.

    31. What is HDFS ? How it is different from traditional file systems?
    32. HDFS, the Hadoop Distributed File System, is responsible for storing huge data on the cluster. This is a distributed file system designed to run on commodity hardware. It has many similarities with existing distributed file systems. However, the differences from other distributed file systems are significant.
      • HDFS is highly fault-tolerant and is designed to be deployed on low-cost hardware.
      • HDFS provides high throughput access to application data and is suitable for applications that have large data sets.
      • HDFS is designed to support very large files. Applications that are compatible with HDFS are those that deal with large data sets. These applications write their data only once but they read it one or more times and require these reads to be satisfied at streaming speeds. HDFS supports write-once-read-many semantics on files.

    33. What is HDFS Block size? How is it different from traditional file system block size?
    34. In HDFS data is split into blocks and distributed across multiple nodes in the cluster. Each block is typically 64Mb or 128Mb in size. Each block is replicated multiple times. Default is to replicate each block three times. Replicas are stored on different nodes. HDFS utilizes the local file system to store each HDFS block as a separate file. HDFS Block size can not be compared with the traditional file system block size.

    35. What is a NameNode? How many instances of NameNode run on a Hadoop Cluster?
    36. The NameNode is the centerpiece of an HDFS file system. It keeps the directory tree of all files in the file system, and tracks where across the cluster the file data is kept. It does not store the data of these files itself. There is only One NameNode process run on any hadoop cluster. NameNode runs on its own JVM process. In a typical production cluster its run on a separate machine. The NameNode is a Single Point of Failure for the HDFS Cluster. When the NameNode goes down, the file system goes offline. Client applications talk to the NameNode whenever they wish to locate a file, or when they want to add/copy/move/delete a file. The NameNode responds the successful requests by returning a list of relevant DataNode servers where the data lives.

    37. What is a DataNode? How many instances of DataNode run on a Hadoop Cluster?
    38. A DataNode stores data in the Hadoop File System HDFS. There is only One DataNode process run on any hadoop slave node. DataNode runs on its own JVM process. On startup, a DataNode connects to the NameNode. DataNode instances can talk to each other, this is mostly during replicating data.

    39. How the Client communicates with HDFS?
    40. The Client communication to HDFS happens using Hadoop HDFS API. Client applications talk to the NameNode whenever they wish to locate a file, or when they want to add/copy/move/delete a file on HDFS. The NameNode responds the successful requests by returning a list of relevant DataNode servers where the data lives. Client applications can talk directly to a DataNode, once the NameNode has provided the location of the data.

    41. How the HDFS Blocks are replicated?
    42. HDFS is designed to reliably store very large files across machines in a large cluster. It stores each file as a sequence of blocks; all blocks in a file except the last block are the same size. The blocks of a file are replicated for fault tolerance. The block size and replication factor are configurable per file. An application can specify the number of replicas of a file. The replication factor can be specified at file creation time and can be changed later. Files in HDFS are write-once and have strictly one writer at any time. The NameNode makes all decisions regarding replication of blocks. HDFS uses rack-aware replica placement policy. In default configuration there are total 3 copies of a datablock on HDFS, 2 copies are stored on datanodes on same rack and 3rd copy on a different rack.
    43. What is the purpose of the secondary name-node?
    44. The term "secondary name-node" is somewhat misleading. It is not a name-node in the sense that data-nodes cannot connect to the secondary name-node, and in no event it can replace the primary name-node in case of its failure.
      The only purpose of the secondary name-node is to perform periodic checkpoints. The secondary name-node periodically downloads current name-node image and edits log files, joins them into new image and uploads the new image back to the (primary and the only) name-node.
      So if the name-node fails and you can restart it on the same physical node then there is no need to shutdown data-nodes, just the name-node need to be restarted. If you cannot use the old node anymore you will need to copy the latest image somewhere else. The latest image can be found either on the node that used to be the primary before failure if available; or on the secondary name-node. The latter will be the latest checkpoint without subsequent edits logs, that is the most recent name space modifications may be missing there. You will also need to restart the whole cluster in this case.
    Read More...

    Friday, 21 September 2012

    Hadoop Installation

    Leave a Comment


    Steps are following:

    1.      The steps are tested on Linux Ubuntu 10.

    2.      Download Hadoop from http://hadoop.apache.org/common/releases.html . This document is done with 23 May, 2012: Release 2.0.0-alpha available

    3.      Unzip Hadoop in a directory. This will create a direcotry "hadoop-2.0.0-alpha"

    5.      Set the environment variable for Java and Hadoop and also put Hadoop in the path. For bashrc shell it lools like:
    export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/
    export HADOOP_INSTALL=/home/enlighted/hadoop-2.0.0-alpha
    export PATH=$PATH:/home/enlighted/programs/apache-maven-3.0.4/bin:$HADOOP_INSTALL/bin:$HADOOP_INSTALL/sbin

    6.      Check if hadoop is installed properly by using hadoop command
    hadoop version
    It will print something similar to
    Hadoop 2.0.0-alpha
    alph... –r1338348

    7.      Hadoop can be configured using XML configuration files which are at etc/hadoop directory inside hadoop folder. The improtant onces are:
    core-site.xml -> core porperties
    hdfs-site.xml -> hdfs properties
    yarn-site.xml -> yarn properties which is the next generation of Map Reduce.

    8.      By default hadoop is configured to run in standalone mode. The other two modes are pseudo distributed and clustered mode




    Read More...

    Hadoop Introduction

    Leave a Comment

                     Persistence is the ability for data to live beyond the lifecycle of a process. Software as part of interaction generate a lot of data which needs to live beyond them. In the beginning, the data storage systems were file oriented. However files did little to provide a good structure to the stored data. The other main issue with files was there proprietary format, which made it impossible to read them in the absence of certain programs. Also processing of data in file across versions of software was another challenge to deal with, as run time structures to hold the data do change across releases. Also in terms of scalability, files were not very good in terms of searching and doing local updates on data. To solve this, industry came up with RDBMS type of system.

                     RDBMS is a very structured way of defining the data. The rigorous structuring and ability to constrain provided the capability to keep the integrity of data also popularly known as ACID properties. For the amount of data the world was dealing with. RDBMS systems were sufficient and provided the required scalability to an extent. This was the time when to get indexed in a search engine one has to submit the web link to search engines. People managed higher scalability with concepts like sharding however at the cost of increased complexity. (Developers love to make things complex).

                      Google came and changed the world. The amount of data they start dealing with just got larger by any sane means of measurement. They inverted the concept of web indexing. Rather then people submitting links, they started crawling web, downloading pages locally and indexing them. However with this approach came the problem of large data popularly termed as "Big Data" now. There was a parallel development happening. Doug cutting was working on a search engine infrastructure project called Nutch however he ran into issues of scaling it further. A paper from Google around that time on how Google handles Big Data using GFS or Google File System. Based on the paper, Doug started working on Hadoop on the line of GFS and used the concept of Map Reduce. Around those time, Doug was employed by Yahoo and the project got he required funding and resources. Today Hadoop is a clear winner in terms of handling Big Data problems and is used in my enterprises who deal with Big Data. The core of Hadoop is the ability to push the processing logic to the data itself without moving a lot of data around. This is different from technologies like Grid computing which move both the data and processing logic. Compared to Hadoop, RDBMS systems do the opposite of pulling the data to the processing logic. Having said that it does not means that we are going to throw RDBMS and adopt Hadoop everywhere. Both tend to complement each other and have their own unique strength and weaknesses. 

    A high level comparison of Hadoop is as follows:
      

                                                       Hadoop vs RDBMS


                 Data integrity low


       Data integrity high (ACID compliant)


                Non structured data


                     Structured Data


               Linear/Horizontal scaling


              Veritcal/non linear scaling

                 good for initial insert
               and then multiple reads


              Good for multiple updates



    Read More...

    Sunday, 9 September 2012

    Apache Hadoop – Background and an Overview

    2 comments

    MapReduce – The Paradigm

    Essentially, the MapReduce model consists of a first, embarrassingly parallel, map phase where input data is split into discreet chunks to be processed. It is followed by the second and final reduce phase where the output of the map phase is aggregated to produce the desired result. The simple, and fairly restricted, nature of the programming model lends itself to very efficient and extremely large-scale implementations across thousands of cheap, commodity nodes.
    Apache Hadoop MapReduce is the most popular open-source implementation of the MapReduce model.
    In particular, when MapReduce is paired with a distributed file-system such as Apache Hadoop HDFS, which can provide very high aggregate I/O bandwidth across a large cluster, the economics of the system are extremely compelling – a key factor in the popularity of Hadoop.
    One of the keys to this is the lack of data motion i.e. move compute to data and do not move data to the compute node via the network. Specifically, the MapReduce tasks can be scheduled on the same physical nodes on which data is resident in HDFS, which exposes the underlying storage layout across the cluster. This significantly reduces the network I/O patterns and keeps most of the I/O on the local disk or within the same rack – a core advantage.

    Apache Hadoop MapReduce, circa 2011 – A Recap

    Apache Hadoop MapReduce is an open-source, Apache Software Foundation project, which is an implementation of the MapReduce programming paradigm described above. Now, as someone who has spent over six years working full-time on Apache Hadoop, I normally like to point out that the Apache Hadoop MapReduce project itself can be broken down into the following major facets:
    • The end-user MapReduce API for programming the desired MapReduce application.
    • The MapReduce framework, which is the runtime implementation of various phases such as the map phase, the sort/shuffle/merge aggregation and the reduce phase.
    • The MapReduce system, which is the backend infrastructure required to run the user’s MapReduce application, manage cluster resources, schedule thousands of concurrent jobs etc.
    This separation of concerns has significant benefits, particularly for the end-users – they can completely focus on the application via the API and allow the combination of the MapReduce Framework and the MapReduce System to deal with the ugly details such as resource management, fault-tolerance, scheduling etc.
    The current Apache Hadoop MapReduce System is composed of the JobTracker, which is the master, and the per-node slaves called TaskTrackers.
    The JobTracker is responsible for resource management (managing the worker nodes i.e. TaskTrackers), tracking resource consumption/availability and also job life-cycle management (scheduling individual tasks of the job, tracking progress, providing fault-tolerance for tasks etc).
    The TaskTracker has simple responsibilities – launch/teardown tasks on orders from the JobTracker and provide task-status information to the JobTracker periodically.
    For a while, we have understood that the Apache Hadoop MapReduce framework needed an overhaul. In particular, with regards to the JobTracker, we needed to address several aspects regarding scalability, cluster utilization, ability for customers to control upgrades to the stack i.e. customer agility and equally importantly, supporting workloads other than MapReduce itself.
    We’ve done running repairs over time, including recent support for JobTracker availability and resiliency to HDFS issues (both of which are available in Hortonworks Data Platform v1 i.e. HDP1) but lately they’ve come at an ever-increasing maintenance cost and yet, did not address core issues such as support for non-MapReduce and customer agility.
    Read More...

    Saturday, 8 September 2012

    Hadoop with HDFS and Map Reduce

    Leave a Comment

    Hadoop is an open source project for processing large datasets in parallel with the use of low level commodity machines.

    Hadoop is build on two main parts. An special file system called Hadoop Distributed File System (HDFS) and the Map Reduce Framework.
    The HDFS File System is an optimized file system for distributed processing of very large datasets on commodity hardware.
    The map reduce framework works in two main phases to process the data. Which are the Map phase and the Reduce phase.

    Read More...