Saturday, 23 May 2015

Spark (Hadoop Engine)

Apache Spark is at present a standout amongst the most dynamic ventures in Hadoop ecosystem, and there’s been a lot of buildup about it in the past few months. In the most recent webinar from the Data Science Central webinar series, titled “Let Spark Fly: Advantages and Use Cases for Spark on Hadoop,” practical benefits for having full set of Spark Technologies available to your disposal are revealed.
Apache Spark is an execution platform that enables growth of computing workloads which Hadoop can deal with, while additionally tuning the performance of the big data framework.Apache Spark has various preferences over Hadoop’s MapReduce execution engine, in both pace with which it carries out batch processing jobs and the amount of computing workloads it can handle. Apache Spark also has the ability to execute batch processing between 10 to 100 times speedier than the MapReduce engine as indicated by Cloudera, primarily by decreasing the amount of writers and reads to disc.

apache-spark
What Spark really does really well is this idea of a Resilient Distributed Dataset (RDD), which permits you to transparently store data on memory and continue it to plate in the event that it’s required.The utilization of memory makes the framework and the execution engine truly quick.In a true test of Spark’s execution in cluster, Cloudera says, a vast Silicon Valley web organization saw a three times speed increases in the execution of porting a solitary MapReduce job implementing feature in a model training pipeline.
As the level of “memory to handling” rapidly develops, many individuals inside Hadoop gathering are coasting towards Apache Spark for quick, in-memory data transformation. In addition with YARN, they use Spark for machine learning and data science utilize the cases incorporated with distinctive workloads in the meantime.
Apache Spark
Apache Spark licenses information researchers to suitably and essentially actualize iterative figuring’scutting edge analytical operations, for e.g. clustering and preparations of datasets.
It is in the blink of an eye a top level Apache venture and is creating as a charming option to run some cautious information science workloads.
It gives three key value points to developers that make Spark the best decision for data analysis methods. It gives the alternative of in-memory computation for immense measure of diversified workloads. It likewise comes with the tool of disentangled programming model in Scala and machine learning libraries that tremendously simplifies programming and programming needs.
Apache Spark
At its middle, Spark gives a general programming model that enables planners to create application by framing self-assertive administrators, for e.g., mappers, reducers, joins, groupings and channels. This structure makes it easy to express a wide group of calculations, including iterative machine learning, streaming, complex inquiries, and bunch.
Furthermore, Spark stays informed concerning the information that each of the administrators delivers, and empowers applications to dependably store this information in memory. This is the way to Spark’s execution, as it permits applications to keep away from immoderate circle of information transformation.

Hadoop Instalation & Single Node Cluster

For Hadoop to be installed there are some certain pre-requisites such as Supportive platforms like GNU/Linux or Win32 and softwares like Jawed and SSH must be installed and enabled; a proper environment is needed for the system to be installed. If your cluster does not come with all the requisites then you will have to download and install them by yourself which is not that difficult. You can download the latest Jaw version compatible with Hadoopfrom this link http://stackoverflow.com/questions/10268583/how-to-automate-download-and-installation-of-java-jdk-on-linux
Further Configuration of SSH access is needed to enable master/principal and secondary node to get access to the system and take over the slave nodes and handle local users and machines. Generate an SSH key, log in and run the command of key generation. The last step of this process is to check whether machine/machines are connected and working with the main user enabling the local host to permanently combine with other known hosts.
Then to install Hadoop you will need a Hadoop distribution which is available on Apache Download Mirrors (http://www.apache.org/dyn/closer.cgi/hadoop/common/). To make things lot easier you can install softwares like Ubunto-64 bit or MVPlayer
In Ubuntu you have an option of Downloading Hadoop by its latest release, choose to download a stable release, unpack the download and extract it.Hadoop
This will start the installation process and the next step of the installation will be configuration of your Jaw path. The step is simple as you just have to edit the pre defined perimeter of the path in the system and change it according to your user defined path.Hadoop
Edit the built in changeable location address according to your own Jaw address and save it.
Next step would be to add dedicated Hadoop system user to make the system operational. This step isn’t that much important but it will help keeping Hadoop segregated from other applications, user IDs and softwares.Hadoop
Now disabble IPv6 as it is necessary to unbind Hadoopbut if you are connected to a IPv6 network then there is no need to disable it.
The last step is to format and edit the nodes of Hadoop file system, which is only necessary if the system is not already in use. The process is performed by a simple command
Hadoop namenode-format
Now You can make sure whether the software is fully operational or not by giving a task to the system, hopefully this will work and you will have a smile on your face.
Hadoop can be stopped instantly by commands given below;
  • Stop-dfs.sh
  • Stop-yarn.sh
Hadoop has many web interfaces which are very much user firendly, available at these addresses;
  • http://localhost50070
  • http://localhost50090
This ends the whole process and now you can enjoy the ease of handling your big data conveniently and effectively, but no doubt you will have take Hadoop training which will improve your expertise and skill. I hope the whole process was easy to understand and helpful to the readers. With an ending note, I must add that Big data technologies are very imparitive to use and very heplful in managing data. Now online courses are provided, initiated by the need of data managing technolgies. Companies like Yahoo and Google(which is also the founder of Hadoop system) are among the big usres of the system and it is forecasted that in times to come around 80% of the world data will be managed by either Hadoop or other data manging softwares.

What is Bigdata (Hadoop ) and Why ?

Bigdata  is buzzword these days and every industry ranging from small scale to enterprise level is looking at it and trying to solve their problems and derive hidden insights from the data. More sophisticated algorithms, platforms, advanced tools from numerous vendors are getting released into the market and everyone is trying to solve problems in different way. Complete picture of Bigdata problem solving will go through the below mentioned phases.
big data
Input Sources: Logs data, Streaming real time data, Sensor data, existing databases (MySql, Oracle etc.)
ETL Tools: Oracle BI Tools, Talend, Pentaho, Clover etc.
Destination Storage: HDFS, HBase, Cassandra, DynamoDB, AWS S3, GreenPlum, MongoDB etc.
Analytical Engine: R engine, Machine Learning engine etc.
Visualization: Tableau, Google charts, Leaflet, Highcharts etc.
In the above picture, it says that the data has to get moved from source to destination, destination to analytical engines, engines to visualization tools.
If all the above steps are performed using a single platform so that data will not get moved into different location is the desired platform in this current world. This saves valuable resources like network, bandwidth, time and latencies. Databricks is the product that is getting emerged these days to solve this issue.
Features of Databricks product:
  • Interactively analyze, visualize, and curate your data – big or small. Leverage Python, SQL, or Scala and seamlessly weave together advanced analytics, streaming data and interactive queries. Collaborate with colleagues in real-time to discover insights.
  • Build live dashboards that capture insights from your data exploration. Allow colleagues to interact with and customize visualizations. Automatically update dashboards and underlying queries in response to changing data.
  • Scale the insights you’ve discovered by building data products that deliver value to your business and customers. Schedule execution of notebooks you’ve built or standard Spark jobs – either periodically or based on changes in the underlying data.
  • Dynamically provision and scale managed clusters. Seamlessly import data – from S3, local uploads, and a variety of other sources. Fault tolerance, security, and resource isolation provided out of the box. Advanced management and monitoring tools to understand usage.
Databricks is powered by the 100% open source Apache Spark – the most active project in the Big Data ecosystem. Spark lets you explore your data in SQL, Python, Java, or Scala, and integrates machine learning, graph computation, streaming analytics, and interactive queries. The Databricks platform is the best place to develop and deploy Spark applications. Databricks is 100% compatible with the Apache Spark API. This allows users to leverage applications from the rapidly growing Spark ecosystem, and developers to easily develop Spark applications and deploy them on any Certified Spark distribution – in the cloud or on-premise.
The survey results indicate that 13% are already using Spark in production environments with 20% of the respondents with plans to deploy Spark in production environments in 2015, and 31% are currently in the process of evaluating it. In total, the survey covers over 500 enterprises that are using or planning to use Spark in production environments ranging from on-premise Hadoop clusters to public clouds, with data sources including key-value stores, relational databases, streaming data and file systems. Applications range from batch workloads to SQL queries, stream processing and machine learning, highlighting Spark’s unique capability as a simple, unified platform for data processing.
So there is lot of scope for spark with scala combo and its necessary to make everyone hands dirty in spark environment for a better future.

Wednesday, 13 May 2015

Hadoop Daemons Generated Logs

Apache Hadoop’s jobtracker, namenode, secondary namenode, datanode, and tasktracker all generate logs. That includes logs from each of the daemons under normal operation, as well as configuration logs, statistics, standard error, standard out, and internal diagnostic information. Many  users aren’t entirely sure what the differences are among these logs, how to analyze them, or even how to handle simple administrative tasks like log rotation.  This blog post describes each category of log, and then details where they can be found for each Hadoop component.
The log categories are:
·         Hadoop Daemon Logs
These logs are created by the Hadoop daemons, and exist on all machines running at least one Hadoop daemon. Some of the files end with .log, and others end with .out. The .out files are only written to when daemons are starting. After daemons have started successfully, the .out files are truncated. By contrasts, all log messages can be found in the .log files, including the daemon start-up messages that are sent to the .out files. There is a .log and .out file for each daemon running on a machine. When the namenode, jobtracker, and secondary namenode are running on the same machine, then there are six daemon log files: a .log and .out for the each of the three daemons.
The .log and .out file names are constructed as follows:
hadoop-<user-running-hadoop>-<daemon>-<hostname>.log
where <user-running-hadoop> is the user running the Hadoop daemons (this is always ‘hadoop’ with Cloudera’s distribution), <daemon> is the daemon these logs are associated (for example, namenode or jobtracker), and <hostname> is the hostname of the machine on which the daemons are running.
For example:
hadoop-hadoop-datanode-ip-10-251-30-53.log
By default, the .log files are rotated daily by log4j. This is configurable with /etc/hadoop/conf/log4j.properties. Administrators of a Hadoop cluster should review these logs regularly to look for cluster-specific errors and warnings that might have to do with daemons running incorrectly.  Note that the namenode and secondarynamenode logs should not be deleted more frequently than fs.checkpoint.period, so in the event of a secondarynamenode edits log compaction failure, logs from the namenode and secondarynamenode will be available for diagnostics.
These logs grow slowly when the cluster is idle. When jobs are running, they grow very rapidly. Some problems create considerably more log entries, but some problems only create a few infrequent messages. For example, if the jobtracker can’t connect to the namenode, the jobtracker daemon logs explode with the same error (something like “Retrying connecting to namenode [..]“). Lots of log entries here does not necessarily mean that there is a problem: you have to search through these logs to look for a problem.
·         Job Configuration XML
The job configuration XML logs are created by the jobtracker. The jobtracker creates a .xml file for every job that runs on the cluster. These logs are stored in two places:/var/log/hadoop and /var/log/hadoop/history. The XML file describes the job configuration.
The /hadoop file names are constructed as follows:
job_<job_ID>_conf.xml
For example:
job_200908190029_0001_conf.xml
The /hadoop/history file names are constructed as follows:
<hostname>_<epoch-of-jobtracker-start>_<job-id>_conf.xml
where <hostname> is the hostname of the machine on which the jobtracker is running, <epoch-of-jobtracker-start> is the number of milliseconds that had elapsed since Unix Epoch when the jobtracker daemon was started, and <job-id> is the job ID. For example:
ec2-72-44-61-184.compute-1.amazonaws.com_1250641772616_job_200908190029_0001_conf.xml
These logs are not rotated. These files may be more interesting to developers than system administrators, because their contents are job-specific. You can clear these logs periodically without affecting Hadoop. However, consider archiving the logs if they are of interest in the job-development process. Make sure you do not move or delete a file that is currently being written to by a running job.
Individual job configuration logs are created for each job that is submitted to the cluster. Each log file will be more or less the same size for each job.
·         Job Statistics
These logs are created by the jobtracker. The jobtracker runtime statistics from jobs to these files. Those statistics include task attempts, time spent shuffling, input splits given to task attempts, start times of tasks attempts and other information.
The statistics files are named:
<hostname>_<epoch-of-jobtracker-start>_<job-id>_<job-name>
where <hostname> is the hostname of the machine creating these logs, <epoch-of-jobtracker-start> is the number of milliseconds that had elapsed since Unix Epoch when the jobtracker daemon was started, <job-id> is the job ID, and <job-name> is the name of the job.
For example:
ec2-72-44-61-184.compute-1.amazonaws.com_1250641772616_job_200908190029_0002_hadoop_test-mini-mr
These logs are not rotated.  You can clear these logs periodically without affecting Hadoop. However, consider archiving the logs if they are of interest in the job development process. Make sure you do not move or delete a file that is being written to by a running job.
Individual statistics logs are created for each job that is submitted to the cluster. The size of each log file varies. Jobs with more tasks produce larger files.
·         Standard Error for a particular task attempt
These logs are created by each tasktracker. They contain information written to standard error (stderr) captured when a task attempt is run. These logs can be used for debugging.  For example, a developer can include System.err.println(“some useful information”) calls in the job code. The output will appear in the standard error files.
The parent directory name for these logs is constructed as follows:
/var/log/hadoop/userlogs/attempt_<job-id>_<map-or-reduce>_<attempt-id>
where <job-id> is the ID of the job that this attempt is doing work for, <map-or-reduce> is either “m” if the task attempt was a mapper, or “r” if the task attempt was a reducer, and <attempt-id> is the ID of the task attempt.
For example:
/var/log/hadoop/userlogs/attempt_200908190029_0001_m_000001_0
These logs are rotated according to the mapred.userlog.retain.hours property. You can clear these logs periodically without affecting Hadoop. However, consider archiving the logs if they are of interest in the job development process. Make sure you do not move or delete a file that is being written to by a running job.
The size of these log files depends on the amount of stderr calls used in the job code.
·         Standard Out for a particular task attempt
These logs are very similar to the standard error logs, except they capture stdout instead of stderr. File size depends entirely on how much data the task writes to stdout.
·         log4j informational messages from within the task process
These logs contains anything that log4j writes from within the task process. This includes some Hadoop internal diagnostic info. If the job’s mapper or reducer implementations include call such as LOG.info(), then that output also get written here. Messages can include information about the task, such as how big its record buffer was or how many reduce tasks there are. The size of these log files depends on the number of log4j calls used in the job code.
These logs are rotated according to the mapred.userlog.retain.hours property. You can clear these logs periodically without affecting Hadoop. However, consider archiving the logs if they are of interest in the job development process. Make sure you do not move or delete a file that is being written to by a running job.
The Hadoop components produce the following logs when installing Hadoop from CDH RPM or DEB packages:
·         On the jobtracker:
1
2
3
4
5
6
/var/log/hadoop
              /hadoop-* =&gt; daemon logs
              /job_*.xml =&gt; job configuration XML logs
              /history
                     /*_conf.xml =&gt; job configuration logs
                     &lt; everything else &gt; =&gt; job statistics logs
·         On the namenode:
1
2
/var/log/hadoop
              /hadoop-* =&gt; daemon logs
·         On the secondary namenode:
1
2
/var/log/hadoop
              /hadoop-* =&gt; daemon logs
·         On the datanode:
1
2
/var/log/hadoop
              /hadoop-* =&gt; daemon logs
·         On the tasktracker:
1
2
3
4
5
6
7
/var/log/hadoop
              /hadoop-* =&gt; daemon logs
              /userlogs
                      /attempt_*
                               /stderr =&gt; standard error logs
                               /stdout =&gt; standard out logs
                               /syslog =&gt; log4j logs

It’s probably clear now that Hadoop generates plenty of logs, each with a different purpose and audience.  I hope this post will help you debug your MapReduce jobs and Hadoop cluster.

WordCountProgram with Counters


import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class WordCountWithCounter {

        static enum WordsNature { STARTS_WITH_DIGIT, STARTS_WITH_LETTER, ALL }
        /**
         * The map class of WordCount.
         */
        public static class TokenCounterMapper
        extends Mapper<Object, Text, Text, IntWritable> {

               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);
                       }
               }
        }
        /**
         * The reducer class of WordCount
         */
        public static class TokenCounterReducer
        extends Reducer<Text, IntWritable, Text, IntWritable> {
               public void reduce(Text key, Iterable<IntWritable> values, Context context)
               throws IOException, InterruptedException {
                       int sum = 0;
                      
                       String token = key.toString();
                       if( StringUtils.startsWithDigit(token) ){
                               context.getCounter(WordsNature.STARTS_WITH_DIGIT).increment(1);
                       }
                       else if( StringUtils.startsWithLetter(token) ){
                               context.getCounter(WordsNature.STARTS_WITH_LETTER).increment(1);
                       }
                       context.getCounter(WordsNature.ALL).increment(1);
                      
                       for (IntWritable value : values) {
                               sum += value.get();
                       }
                       context.write(key, new IntWritable(sum));
               }
        }
        /**
         * The main entry point.
         */
        public static void main(String[] args) throws Exception {
               Configuration conf = new Configuration();
               Job job = new Job(conf, "Example Hadoop 0.20.1 WordCount");
               job.setJarByClass(WordCountOld.class);
               job.setMapperClass(TokenCounterMapper.class);
               job.setReducerClass(TokenCounterReducer.class);
               job.setOutputKeyClass(Text.class);
               job.setOutputValueClass(IntWritable.class);
               FileInputFormat.addInputPath(job, new Path(args[0]));
               FileOutputFormat.setOutputPath(job, new Path(args[1]));
               System.exit(job.waitForCompletion(true) ? 0 : 1);
        }