Download presentation
Presentation is loading. Please wait.
1
Frontiers of Software Engineering
Cloud Computing and Hadoop Prof. Harold Liu October 2016
2
Content Cloud Computing Hadoop HDFS MapReduce HBase Pig and Hive
Zookeeper 2
24
An Ecosystem for Cloud Computing
24
25
Problem Batch (offline) processing of huge data set using commodity hardware is not enough for real-time applications Strong desire for linear scalability 25
26
Explosive Data! – Storage
New York Stock Exchange: 1 TB data per day Facebook: 100 billion photos, 1 PB (1000 TB) Internet Archive: 2 PB data, growing by 20 TB per month Can’t put data on a SINGLE node Strong needs for distributed file systems
27
27 Java/Python/C interfaces 需要处理Petabyte级别的数据集 为每个应用程序的建立可靠的平台代价较大
每天都有节点坏掉 – 节点坏掉是可以预料到的 – 集群中节点的数量不是稳定的 只需要普通的基础设施 –高效、可信、开源 Java/Python/C interfaces 27
28
Naming it Hadoop The name Hadoop is not an acronym; it’s a made-up name. The project’s creator, Doug Cutting, explains how the name came about: The name my kid gave a stuffed yellow elephant. Short, relatively easy to spell and pronounce, meaningless, and not used elsewhere: those are my naming criteria. Kids are good at generating such. Googol is a kid’s term.
29
Who is (was) Using Hadoop?
29
30
Commercial Hardware Two-tier architecture – commodity servers (cheap)
– servers/Rack 30
31
Example: Facebook Hadoop Cluster
Product Cluster 4800 core, 600 servers, each 16GB RAM — April 2009 8000个 core, 1000 servers, each 32GB RAM — July 2009 Each has four 1TB SATA disk Two layer architecture Each rack has 40 servers In total 2PB storage Testing Cluster 800 core, each 16GB RAM 31
32
A Distributed File System
33
Single-Node Architecture
CPU Machine Learning, Statistics Memory “Classical” Data Mining Disk Even with Lucene, we had to tweak parameters to get proper performance for XML Index and Search because of its usage of disk for B-Trees implementation for DBLP dataset (337 MB) 33 33
34
Cluster Architecture 2-10 Gbps backbone between racks 1 Gbps between
any pair of nodes in a rack Switch Switch Switch Mem Disk CPU Mem Disk CPU Mem Disk CPU Mem Disk CPU … … Each rack contains nodes 34 34
35
Stable Storage with Fault Tolerance
If nodes can fail, how can we store data persistently? Answer: Distributed File System Provides global file namespace Google GFS Hadoop HDFS Kosmix KFS DFS: provides a unified view of the file system and hides the details of replication and consistency management 35 35
36
36
37
37
38
38
39
Namenode and Datanodes
Master/slave architecture 1 Namenode, a master server that manages the file system namespace and regulates access to files by clients. many DataNodes usually one per node in a cluster. manage storage serves read, write requests, performs block creation, deletion, and replication upon instruction from Namenode. HDFS exposes a file system namespace and allows user data to be stored in files. A file is split into one or more blocks and set of blocks are stored in DataNodes. 2018/1/28 39
40
Namespace Hierarchical file system with directories and files
Create, remove, move, rename etc. Namenode maintains the file system Any meta information changes to the file system recorded by Namenode. An application can specify the number of replicas of the file needed: replication factor of the file. This information is stored in the Namenode. 1/28/2018 40
41
Data Replication Store very large files across machines in a large cluster. Each file is a sequence of blocks of same size. Blocks are replicated 2-3 times. Block size and replicas are configurable per file. Namenode receives a Heartbeat and a BlockReport from each DataNode in the cluster. BlockReport contains all the blocks on a Datanode. 1/28/2018 41
42
Replica Placement Rack-aware:
Goal: improve reliability, availability and network bandwidth utilization Research topic Namenode determines the rack id for each DataNode. Replicas are placed: 1 in a local rack, 1 on a different node in the local rack and 1 on a node in a different rack. 1/3 of the replica on a node, 2/3 on a rack and 1/3 distributed evenly across remaining racks. 1/28/2018 42
43
Datanode Distance 43
44
Replication Pipelining
When the client receives response from Namenode It flushes its block in small pieces (4K) to the first replica that in turn copies it to the next replica and so on. Thus data is pipelined from Datanode to the next. 1/28/2018 44
45
Replica Selection Replica selection for READ operation: HDFS tries to minimize the bandwidth consumption and latency. If there is a replica on the Reader node then that is preferred. HDFS cluster may span multiple data centers: replica in the local data center is preferred over the remote one. 1/28/2018 45
46
Datanode A Datanode stores data in files in its local file system.
Datanode has no knowledge about HDFS filesystem It stores each block of HDFS data in a separate file. Datanode does not create all files in the same directory. It uses heuristics to determine optimal number of files per directory and creates directories appropriately: Research issue? When the filesystem starts up it generates a list of all HDFS blocks and send this report to Namenode: Blockreport. 1/28/2018 46
47
HDFS: File Read 47
48
HDFS: File Write 48
49
Communication Protocol
All protocols are layered on top of the TCP/IP protocol A client establishes a connection to a configurable TCP port on the Namenode machine. It talks ClientProtocol with the Namenode. Datanodes talk to the Namenode using Datanode protocol. RPC abstraction wraps both ClientProtocol and Datanode protocol. Namenode is simply a server and never initiates a request; it only responds to RPC requests issued by DataNodes or clients. 1/28/2018 49
50
DataNode Failure and Heartbeat
Datanodes lose connectivity with Namenode. Namenode detects this condition by the absence of a Heartbeat message. Namenode marks Datanodes without Hearbeat and does not send any IO requests to them. Any data registered to the failed Datanode is not available to the HDFS. 1/28/2018 50
51
Cluster Rebalancing HDFS architecture is compatible with data rebalancing schemes. A scheme might move data from one Datanode to another if the free space on a Datanode falls below a certain threshold. In the event of a sudden high demand for a particular file, a scheme might dynamically create additional replicas and rebalance other data in the cluster. These types of data rebalancing are not yet implemented: research issue. 1/28/2018 51
52
APIs HDFS provides Java API for application to use.
Python access is also used in many applications. A C language wrapper for Java API is also available. A HTTP browser can be used to browse the files of a HDFS instance. 1/28/2018 52
53
A Distributed Computation Framework for Large Data Set
54
What is Map/Reduce? A Programming Model
Decompose a processing job into Map and Reduce stages Developer need to provide code for Map and Reduce functions configure the job let Hadoop handle the rest 54
55
MapReduce Model 55
56
Architecture Overview
Master Node user Job tracker Slave node 1 Slave node 2 Slave node N Task tracker Task tracker Task tracker 56 Workers Workers Workers
57
Inside Hadoop 57
58
Example: Word Count We have a large file of words, one word to a line
Count the number of appearances for each distinct word Sample application: analyze web server logs to find popular URLs 58
59
MapReduce Input: a set of key/value pairs User supplies two functions:
map(k,v) list(k1,v1) reduce(k1, list(v1)) v2 (k1,v1) is an intermediate key/value pair Output is the set of (k1,v2) pairs 59
60
What is MAP? Map each data entry into a pair Examples
<key, value> Examples Map each log file entry into <URL,1> Map day stock trading record into <STOCK, Price> map类似于SQL聚集请求中的group-by子句 60
61
What is Shuffle/Merge phase?
Hadoop merges(shuffles) output of the MAP stage into <key, valulue1, value2, value3> Examples <URL, 1 ,1 ,1 ,1 ,1 1> <STOCK, Price On day 1, Price On day 2..> 61
62
What is Reduce? Reduce entries produces by Hadoop merging processing into <key, value> pair Examples Map <URL, 1,1,1> into <URL, 3> Map <Stock, 3,2,10> into <Stock, 10> 62
63
Word Count see 1 bob 1 bob 1 run 1 see bob run run 1 see 2
map(key=url, val=contents): For each word w in contents, emit (w, “1”) reduce(key=word, values=uniq_counts): Sum all “1”s in values list Emit result “(word, sum)” see 1 bob 1 run 1 see 1 spot 1 throw 1 bob 1 run 1 see 2 spot 1 throw 1 see bob run see spot throw 63 63
64
Pseudo-Code: Word Count
map(key, value): // key: document name; value: text of document for each word w in value: emit(w, 1) reduce(key, values): // key: a word; values: an iterator over counts result = 0 for each count v in values: result += v emit(key,result) map(String input_key, String input_value): // input_key: document name // input_value: document contents for each word w in input_value: EmitIntermediate(w, "1"); reduce(String output_key, Iterator intermediate_values): // output_key: a word // output_values: a list of counts int result = 0; for each v in intermediate_values: result += ParseInt(v); Emit(AsString(result)); 64
65
Distributed Execution Overview
User Program Worker Master fork assign map reduce Split 0 Split 1 Split 2 Input Data local write Output File 0 File 1 write read remote read, sort 1.MapReduce库先把user program的输入文件划分为M份(M为用户定义),每一份通常有16MB到64MB,如图左方所示分成了split0~4;然后使用fork将用户进程拷贝到集群内其它机器上。 2.user program的副本中有一个称为master,其余称为worker,master是负责调度的,为空闲worker分配作业(Map作业或者Reduce作业),worker的数量也是可以由用户指定的。 3.被分配了Map作业的worker,开始读取对应分片的输入数据,Map作业数量是由M决定的,和split一一对应;Map作业从输入数据中抽取出键值对,每一个键值对都作为参数传递给map函数,map函数产生的中间键值对被缓存在内存中。 4.缓存的中间键值对会被定期写入本地磁盘,而且被分为R个区,R的大小是由用户定义的,将来每个区会对应一个Reduce作业;这些中间键值对的位置会被通报给master,master负责将信息转发给Reduce worker。 5.master通知分配了Reduce作业的worker它负责的分区在什么位置(肯定不止一个地方,每个Map 作业产生的中间键值对都可能映射到所有R个不同分区),当Reduce worker把所有它负责的中间键值对都读过来后,先对它们进行排序,使得相同键的键值对聚集在一起。因为不同的键可能会映射到同一个分区也就是同一个 Reduce作业(谁让分区少呢),所以排序是必须的。 6.reduce worker遍历排序后的中间键值对,对于每个唯一的键,都将键与关联的值传递给reduce函数,reduce函数产生的输出会添加到这个分区的输出文件中。 7.当所有的Map和Reduce作业都完成了,master唤醒正版的user program,MapReduce函数调用返回user program的代码。 所有执行完毕后,MapReduce输出放在了R个分区的输出文件中(分别对应一个Reduce作业)。用户通常并不需要合并这R个文件,而是将其作为输入交给另一个MapReduce程序处理。整个过程中,输入数据是来自底层分布式文件系统(GFS) 的,中间数据是放在本地文件系统的,最终输出数据是写入底层分布式文件系统(GFS)的。而且我们要注意Map/Reduce作业和map/reduce 函数的区别:Map作业处理一个输入数据的分片,可能需要调用多次map函数来处理每个输入键值对;Reduce作业处理一个分区的中间键值对,期间要对 每个不同的键调用一次reduce函数,Reduce作业最终也对应一个输出文件。 65
66
Data Flow Input, final output are stored on HDFS
Scheduler tries to schedule map tasks “close” to physical storage location of input data Intermediate results are stored on local FS of map and reduce workers Output is often input to another map reduce task 66
67
Coordination Master data structures
Task status: (idle, in-progress, completed) Idle tasks get scheduled as workers become available When a map task completes, it sends the master the location and sizes of its R intermediate files, one for each reducer Master pushes this info to reducers Master pings workers periodically to detect failures 67
68
Failures Map worker failure Reduce worker failure Master failure
Map tasks completed or in-progress at worker are reset to idle Reduce workers are notified when task is rescheduled on another worker Reduce worker failure Only in-progress tasks are reset to idle Master failure MapReduce task is aborted and client is notified Why is completed map task discarded? 68 68
69
Execution View from task perspective 69 69
70
Parallel Execution View from scheduled m/c perspective 70 70
71
How Many Map and Reduce Jobs?
M map tasks, R reduce tasks Rule of thumb: M, R >> (# of nodes) in cluster One DFS chunk per map is common Improves dynamic load balancing and speeds recovery from worker failure Usually R is smaller than M, because output is spread across R files 71
72
Combiners Often a map task will produce many pairs of the form (k,v1), (k,v2), … for the same key k e.g., popular words in Word Count Can save network time by pre-aggregating at mapper combine(k1, list(v1)) v2 same as reduce function 72
73
Partition Function Inputs to map tasks are created by contiguous splits of input file For reduce, we need to ensure that records with the same intermediate key end up at the same worker System can use a default partition function e.g., hash(key) mod R Sometimes useful to override e.g., hash(hostname(URL)) mod R ensures URLs from a host end up in the same output file 73
74
Execution Summary How is this distributed?
Partition input key/value pairs into chunks, run map() tasks in parallel After all map()s are complete, consolidate all emitted values for each unique emitted key Now partition space of output map keys, and run reduce() in parallel If map() or reduce() fails, re-execute! 74 74
75
Example: Trading Data Processing
Input: Historical Stock Data Records are CSV (comma separated values) text file Each line : stock_symbol, low_price, high_price data for all stocks one record per stock per day Output: Maximum interday delta for each stock 75
76
Map Function: Part I 76
77
Map Function: Part II 77
78
Reduce Function 78
79
Running the Job : Part I 79
80
Running the Job: Part II
80
Similar presentations