Introduction to Hadoop 趨勢科技研發實驗室
Copyright Trend Micro Inc. Outline Introduction to Hadoop project HDFS (Hadoop Distributed File System) overview MapReduce overview Reference Classification
Copyright Trend Micro Inc. What is Hadoop? Hadoop is a cloud computing platform for processing and keeping vast amount of data. Apache top-level project Open Source Hadoop Core includes –Hadoop Distributed File System (HDFS) –MapReduce framework Hadoop subprojects –HBase, Zookeeper,… Written in Java. Client interfaces come in C++/Java/Shell Scripting Runs on –Linux, Mac OS/X, Windows, and Solaris –Commodity hardware A Cluster of Machines Hadoop Distributed File System (HDFS) Hadoop Distributed File System (HDFS) MapReduce HBase Cloud Applications
Copyright Trend Micro Inc. A Brief History of Hadoop –First MapReduce library written at Google –Google File System paper published –Google MapReduce paper published –Doug Cutting reports that Nutch now use new MapReduce implementation –Hadoop code moves out of Nutch into new Lucene sub-project –Google Bigtable paper published
Copyright Trend Micro Inc. A Brief History of Hadoop (continue) –First HBase code drop from Mike Cafarella –Yahoo! Running Hadoop on 1000-node cluster –Hadoop made an Apache Top Level Project Classification
Copyright Trend Micro Inc. Who use Hadoop? Yahoo! –More than 100,000 CPUs in ~20,000 computers running Hadoop Google –University Initiative to Address Internet-Scale Computing Challenges Amazon –Amazon builds product search indices using the streaming API and pre- existing C++, Perl, and Python tools. –Process millions of sessions daily for analytics IBM –Blue Cloud Computing Clusters Trend Micro – Threat solution research More… – Classification
Copyright Trend Micro Inc. Hadoop Distributed File System Overview
Copyright Trend Micro Inc. HDFS Design Single Namespace for entire cluster Very Large Distributed File System –10K nodes, 100 million files, 10 PB Data Coherency –Write-once-read-many access model –A file once created, written and closed need not be changed. –Appending write to existing files (in the future) Files are broken up into blocks –Typically 128 MB block size –Each block replicated on multiple DataNodes
Copyright Trend Micro Inc. HDFS Design Moving computation is cheaper than moving data –Data locations exposed so that computations can move to where data resides File replication –Default is 3 copies. –Configurable by clients Assumes Commodity Hardware – Files are replicated to handle hardware failure – Detect failures and recovers from them Streaming Data Access –High throughput of data access rather than low latency of data access –Optimized for Batch Processing Classification
Copyright Trend Micro Inc.
NameNode Manages File System Namespace –Maps a file name to a set of blocks –Maps a block to the DataNodes where it resides Cluster Configuration Management Replication Engine for Blocks
Copyright Trend Micro Inc. NameNode Metadata Meta-data in Memory –The entire metadata is in main memory –No demand paging of meta-data Types of Metadata –List of files –List of Blocks for each file –List of DataNodes for each block –File attributes, e.g creation time, replication factor
Copyright Trend Micro Inc. NameNode Metadata (cont.) A Transaction Log (called EditLog) –Records file creations, file deletions. Etc FsImage –The entire namespace, mapping of blocks to files and file system properties are stored in a file called FsImage. –NameNode can be configured to maintain multiple copies of FsImage and EditLog. Checkpoint –Occur when NameNode startup –Read FsImange and EditLog from disk and apply all transactions from the EditLog to the in-memory representation of the FsImange –Then flushes out the new version into new FsImage Classification
Copyright Trend Micro Inc. Secondary NameNode Copies FsImage and EditLog from NameNode to a temporary directory Merges FSImage and EditLog into a new FSImage in temporary directory. Uploads new FSImage to the NameNode –Transaction Log on NameNode is purged FsImage EditLog FsImage (new)
Copyright Trend Micro Inc. NameNode Failure A single point of failure Transaction Log stored in multiple directories –A directory on the local file system –A directory on a remote file system (NFS/CIFS) Need to develop a real HA solution SPOF!!
Copyright Trend Micro Inc. DataNode A Block Server –Stores data in the local file system (e.g. ext3) –Stores meta-data of a block (e.g. CRC) –Serves data and meta-data to Clients Block Report –Periodically sends a report of all existing blocks to the NameNode Facilitates Pipelining of Data – Forwards data to other specified DataNodes
Copyright Trend Micro Inc. HDFS - Replication Default is 3x replication. The block size and replication factor are configured per file. Block placement algorithm is rack-aware
Copyright Trend Micro Inc. User Interface API –Java API –C language wrapper (libhdfs) for the Java API is also avaiable POSIX like command –hadoop dfs -mkdir /foodir –hadoop dfs -cat /foodir/myfile.txt –hadoop dfs -rm /foodir myfile.txt HDFS Admin –bin/hadoop dfsadmin –safemode –bin/hadoop dfsadmin –report –bin/hadoop dfsadmin -refreshNodes Web Interface –Ex:
Copyright Trend Micro Inc. Web Interface ( )
Copyright Trend Micro Inc. Web Interface ( ) Browse the file system Classification
Copyright Trend Micro Inc. POSIX Like command
Copyright Trend Micro Inc. Latest API – Java API
Copyright Trend Micro Inc. Classification MapReduce Overview
Copyright Trend Micro Inc. Brief history of MapReduce A demand for large scale data processing in Google The folks at Google discovered certain common themes for processing those large input sizes Many machines are needed Two basic operations on the input data: Map and Reduce Google’s idea is inspired by map and reduce functions commonly used in functional programming. Functional programming: MapReduce –Map [1,2,3,4] – (*2) [2,3,6,8] –Reduce [1,2,3,4] – (sum) 10 –Divide and Conquer paradigm
Copyright Trend Micro Inc. MapReduce MapReduce is a software framework introduced by Google to support distributed computing on large data sets on clusters of computers. Users specify –a map function that processes a key/value pair to generate a set of intermediate key/value pairs –a reduce function that merges all intermediate values associated with the same intermediate key 。 And MapReduce framework handles details of execution. Classification
Copyright Trend Micro Inc. Application Area MapReduce framework is for computing certain kinds of distributable problems using a large number of computers (nodes), collectively referred to as a cluster. Examples –Large data processing such as search, indexing and sorting –Data mining and machine learning in large data set –Huge access logs analysis in large portals More applications Classification
Copyright Trend Micro Inc. MapReduce Programming Model User define two functions map (K1, V1) list(K2, V2) –takes an input pair and produces a set of intermediate key/value reduce (K2, list(V2)) list(K3, V3) –accepts an intermediate key I and a set of values for that key. It merges together these values to form a possibly smaller set of values MapReduce Logical Flow shuffle / sorting
Copyright Trend Micro Inc. MapReduce Execution Flow Classification 7 shuffle / sorting Shuffle (by key) Sorting (by key)
Copyright Trend Micro Inc. Word Count Example Word count problem : –Consider the problem of counting the number of occurrences of each word in a large collection of documents. Input: –A collection of (document name, document content) Expected output –A collection of (word, count) User define: –Map: (offset, line) ➝ [(word1, 1), (word2, 1),... ] –Reduce: (word, [1, 1,...]) ➝ [(word, count)]
Copyright Trend Micro Inc. Word Count Execution Flow
Copyright Trend Micro Inc. Monitoring the execution from web console Classification
Copyright Trend Micro Inc. Reference Classification Hadoop project official site – Google File System Paper – Google MapReduce paper – Google: MapReduce in a Week – Google: Cluster Computing and MapReduce – minilecture/listing.htmlhttp://code.google.com/edu/submissions/mapreduce- minilecture/listing.html