• 沒有找到結果。

中 華 大 學

N/A
N/A
Protected

Academic year: 2022

Share "中 華 大 學"

Copied!
43
0
0

加載中.... (立即查看全文)

全文

(1)

中 華 大 學 碩 士 論 文

應用在 MapReduce 新型負載平衡規劃

A Novel Load Balancing Method for Programming Efficient MapReduce

Applications

系 所 別:資訊工程學系碩士班

學號姓名:E09902007 陳克豪

指導教授:許 慶 賢 博士

(2)

摘 要

雲端中的運算模型,是透過網路將龐大的運算處理程式自動分拆成無數個 較小的子程式,再由多部伺服器所組成的龐大系統搜尋、運算分析之後將處理 結果回傳給使用者。透過雲端技術,遠端的服務供應商可以在數秒之內,達成 處理數以千萬計甚至上億的資訊,達到和超級電腦同樣強大效能的網路服務。

它可以分析DNA結構、基因圖譜定序、解析癌細胞等高階運算。

雲端運算架構下,將資料拆成小塊運算後再重組回來,但要如何將拆解的 資料平均的分配至各設備;分配的過程會產生額外資源消耗,要如何平均分配 至各雲端設備,又要控制所額外使用的資源,是本篇論文要探討在分配過程的 最佳化。

本論文提出運行於雲端運算環境中,可動態分配運算量的方法,並且將其 在分配的過程,減少使用的記憶體。此設計架構針對中小型叢集[1],另一改良 的方法使得不同資料皆可使用不同的編碼,使其配置過程減少overhead;要把傳 統的單一線程排序算法設計成真正並行的排序算法,保證雲端計算各階段的並 行度更高。

使用本論文的的方法,讓雲端運算不再專屬於大型企業,讓中小型私有雲 能產生更快速,實現高運算能力。

關鍵字:MapReduce,雲端計算,Hadoop,虛擬機器,負載平衡。

(3)

ABSTRACT

The cloud computing model is that splitting huge computing program into numerous small sub-program by internet, and then that using huge systems composed by multiple servers to search, and analyze. After that, passing those result to users. By cloud computing, remote suppliers can deal with ten millions or even billions of information to the extent of super computers. It can analyze DNA structure, gene, cancer and other high-end computing.

Cloud computing architecture, it can reassemble of information split by numerous small parts. But how to distribute split information to every equipment; the process of distribution will generate extra resource depletion. How to distribute it to every cloud equipment and how to control extra used resource is this paper’s discussion.

In this paper which provides the environment of cloud computing, it can distribute computational methods dynamically and in the process of distribution, it can reduce using memory. This structure is to small cluster[1]. The other method can let different information use different codes and let configuration process reduce overhead. We need to design tradition single-thread sorting algorithm to real parallel sorting algorithm, and guaranty various stages of cloud computing higher degree of parallelism.

This paper is to let cloud computing be not only for big companies whereas mid or small companies can provide more fast computing abilities.

Keyword:MapReduce,Cloud Computing,Hadoop,Virtual Machine,Loading Balance.

(4)

致 謝

本論文得以順利完成,首先要誠摯感謝我的指導教授許慶賢博士,在研究 期間,提供了相當寶貴的建議,協助我將原本凌亂的思緒逐步的整合成一篇完 整的論文,教授總是在我遇到問題無法解法時,適時給予意見,使我在研究論 文上有更嚴謹的態度與細心的精神。與教授討論的過程,不斷的指導我要如何 使自己的論文更有組識,更有主軸及規劃,讓我受益良多。

在做論文期間,感謝世璋學長一路上給我的指導和鼓勵,讓我更有信心地 去完成我的論文研究,在很多事情不明白時,給予我最親切且耐心地述說相關 工作細節,每次都可以從他身上學到新的東西。

此外我要感謝我的同學們,同實驗室的小魏,一起上課一起出來玩的日 子,很開心,陪伴我一起完成論文的時期;接著是明倉和明財,可以跟我一起 努力以及互相打氣完成論文,提供點子讓我的方向更明確,以及感謝文齊、登 維在會議上互相陪伴。

最後我要感謝我的老婆小翠以及家人,對我碩士求學這兩年來,給予我無 限的支持與鼓勵,讓我有自信的力量,讓我知道我可以做到,能有持續前進堅 持下去的動力。謹以此碩士論文獻給我的家人和關心支持我的朋友們,謝謝教 授及大家。

(5)

目錄

摘 要... i

ABSTRACT ... ii

致 謝... iii

目錄... iv

表目錄...v

圖目錄... vi

Chapter 1 緖論... 1

1.1 研究背景... 1

1.2 研究動機與目的 ... 2

1.2.1 MapReduce 架構 ... 2

1.2.2 Hadoop Shuffle 概述 ... 4

1.3 重要性及貢獻... 5

1.4 論文架構 ... 6

Chapter 2 相關研究... 7

2.1 Hadoop 架構概述 ... 7

2.2HDFS 概述... 8

2.3HBASE 概述 ... 9

2.4 MapReduce 型態與格式 ...10

Chapter 3 Hadoop Shuffle 工作流程 ...13

3.1 HashCode 分區演算法...13

3.2 TeraSort 演算法與流程 ...14

Chapter 4 High Performance MapReduce 設計...20

4.1 XTrieTree 分區演算法...22

4.2 ETrieTree 分區演算法 ...24

Chapter 5 實驗結果與分析 ...27

5.1 實驗參數...27

5.2 實驗配置...28

5.3 實驗結果 ...28

Chapter 6 結論與未來研究方向...32

References ...33

(6)

表目錄

表 3-1: Two level trie tree array ...16

表 3-2: Two level trie tree tag ...16

表 3-3: Trie tree partition ...16

表 3-4: Build trie tree flow...18

表 4-1: HPMR partition ...21

表 4-2: XTrie Tree Partitioner...24

表 4-3: ETrieTree Re-map ...24

表 4-4: Build ETrieTree ...25

表 4-5: ETrie Tree Partitioner ...26

表 5-1: Space utilization...31

(7)

圖目錄

圖 1-1: MapReduce Flow... 4

圖 1-2: Shuffle flow ... 5

圖 3-1: HashCode partitioner ...14

圖 3-2: Trie Level ...15

圖 3-3: Two level trie tree...15

圖 3-4: TeraSort flow...18

圖 4-1: HPMR flow ...21

圖 4-2: Data distribution ...22

圖 4-3: XTrieTree flow ...23

圖 4-4: ETrieTree flow ...26

圖 5-1: Uneven degree result-one level ...29

圖 5-2: Uneven degree result-two level ...29

圖 5-3: Uneven degree result-three level ...30

圖 5-4: Uneven degree result-ETrie...30

(8)

Chapter 1 緖論

1.1 研究背景

隨著網際網路普及網路頻寬速度的急劇增加,產生許多大量的資料,這些 資料在格式上大多有其獨特的特性及分佈區間,要如何處理不同資料,變成一 個很重要的議題;隨後美國網路龍頭Google也遇到相同問題。之後在2003年提出 分散式檔案系統架構Google File System(GFS)[4]、2004年提出大規模資料處理 的模型MapReduce架構[3],以及2006年提出基於Google File System針對結構化 資料儲存的分散系統BigTable[2]。

從雲端運算(Cloud Computing)[18]名詞產生到現在,從最早由Google、

Amazon和Microsoft僅提供服務平台,自從Hadoop平台出現,漸漸打破這個局 面[25];每個團體,甚至於每個人都可以打造私有雲,其所運用的技術,本質上 來看就是分散式運算的一種[14]。Hadoop基於Google所提的雲端架構,採用完 全開放原始碼實現;Hadoop對應到Google雲端的各項目,Google File System對 應 到 Hadoop Distributed File System(HDFS)[26] , MapReduce 對 應 到 Hadoop MapReduce,BigTable對應到HBase。

雲端計算最基本的概念,就是希望能夠透過網際網路將大規模的資料量放 置在雲端,並且將龐大的單一處理程序,自動拆解成無數個較小的子程序;其 計算交給雲端叢集來處理[1],以加快處理速度,最後再將處理的結果回傳給使 用者。透過雲端的技術,企業可以在極短的時間內,處理數以千萬計的資料,

達成類似超級電腦的處理能力,但其價格不像超級電腦般的昂貴及難以維護。

如何把一般的應用程式,利用雲端計算的模型,有效的將運算量平均分配

(9)

Owen O’Malley提出所發展出來的TeraSort[24]為基礎,用來將運算量平均分配 至雲端平台。

1.2 研究動機與目的

在自然界與科學中,資料大多會有其集中在某一區間的特性。在傳統的 MapReduce模式,在分配運算量上,無法依據資料分佈特性,使其在分配運算 量的過程最佳化;後來由Yahoo團隊的Owen O’Malley提出TeraSort加以改進,使 用統計節點的方式,使其在擁有大規模雲端設備的環境,發揮強大的運算能力

。雖然Yahoo團隊提出的TeraSort非常優秀,但在中小規模雲端叢集的環境,其 統計方式,卻無法將運算量平均分配至雲端中的各平台做運算。

本論文加強了TeraSort在動態分配運算量時,所採用樣本所使用的方法;依 據各輸入資料的特性確實統計,最後將運算量平均的分散至雲端平台,達到真 正的分散及平行化。TeraSort在統計輸入資料的時候,產生額外對記憶體的消 耗,其大多數的消耗,是可以節省下來;透過本論文另一重點,重新編碼的方 法,使其所佔用的記憶體減少,並且亦不會損失太多的效益,即可達成此目標

。在使用相同記憶體的狀況下,本論文所提出之架構的確優於其他架構。

1.2.1 MapReduce 架構

雲端計算的重要關鍵技術之一是MapReduce模型[3]。利用MapReduce模式

,讓程式開發人員先分析問題,將問題切割分散成小問題,再利用平行分散至 Mapper[20]; 而 Mapper 所 處 理 完 的 結 果 , 透 過 分 配 的 規 則 , 分 散 至 對 應 的 Reducer,此規則稱為分區(Partition)[21]。Reducer將所分配到的小結果進行合 併,處理完後將結果輸出。以下為MapReduce流程(圖1-1):

(10)

1. Hadoop會將所輸入的資料,分成M等分的分割,大小預設為16MB 至64MB。

2. 執行Map任務的Mapper,在執行運算會有Map與Reduce運算要完成

,Master會挑選閒置的Worker當Mapper或Reducer。

3. 執行Map任務的Mapper,會從相對應的分割讀取資料,從中分析出

一組對應的Key/Value,再傳送給定義好的Map function做處理,處 理完的intermediate key/value會先存於記憶體中。

4. 被暫存至記憶體中的intermediate key/value,會週期性的被寫入磁碟

5. Mapper根據分區的規則,將intermediate key/value分配給reducer。

6. Reducer透過Reduce function,將結果分析出來。

7. 當Map和Reduce任務完成,master會喚起使用者程式,讓使用者程式 能繼續執行。

(11)

圖1-1.MapReduce flow

1.2.2 Hadoop Shuffle 概述

Hadoop的MapReduce模型,要經歷兩個重要的階段:Map phase和Reduce phase(圖1-2)。對於Map phase分為四個子階段:從磁碟讀取數據資料->執行map 函式->combine結果->將結果寫入本地端的磁碟[10];對於Reduce phase,同樣有 四個子階段:從各個Mapper讀取對應的資料(Shuffle)->Sort->執行Reduce函式->

將結果寫入HDFS中;在Mapper上分類相對應的資料,稱之為分區(partition)。以 下為Shuffle流程(圖1-2):

1. 當Mapper透過Map function處理後,在local端產生intermediate key/value Split0

Split1 Split2 Split3 Split4

Mapper

Mapper

Mapper

Master

Partition0 Partition1

Partition0 Partition1

Partition0 Partition1

Reducer

Reducer

Output File0

Output File1 User Submit Job

Input file

Map Phase

Intermediate file (on local disks)

Reduce Phase

Output file

(12)

2. 根據intermediate key的名稱,分配至Reducer。

圖1-2.Shuffle flow

1.3 重要性及貢獻

本篇論文主要的貢獻可歸納如下幾點:

 將運算量,平均分散到各運算平台。

 在Shuffle過程中,使用更少的記憶體。

 更能針對不同資料的特徵,動態調整分配運算量。

 使得中小叢集的雲端運算,更快速,發揮強大的效益。

Split0 Split1 Split2 Split3 Split4

Mapper

Mapper

Mapper

Partition0 Partition1

Partition0 Partition1

Partition0 Partition1

Mapper

Mapper

Output File0

Output File1

Input file

Map Phase

Intermediate file (on local disks)

Reduce Phase

Output file

Partition2

Partition2

Partition2

Mapper Output File2 Map-Shuffle phase

(13)

1.4 論文架構

本 研 究 探 討 在 MapReduce 架 構 , 解 決 運 算 量 分 配 不 平 均 的 情 況 , 以 TeraSort[24]為基礎,改良成適合中小型叢集的分配方式;分配運算量的過程,

產生額外使用的記憶體,也是本篇論文要解決的問題。

本論文章節介紹如下:第一章緒論,簡述雲端運算的研究背景及研究動機 與目的,為以後的章節打下一個基礎。第二章相關研究,介紹Hadoop平台的架 構,以及運作原理。第三章Hadoop Shuffle工作流程,探討研究Hadoop原本預 設的工作流程,及本篇研究為基礎的TeraSort的方法。第四章High Performance MapReduce設計。第五章實驗結果與分析,開始介紹關於結果參數的意義,並 且將實驗結果詳細的分析與比較。最後第六章為結論及探討未來可繼續研究的 方向與議題。在本研究論文的最後,一併附上研究過中所引用與參考的資料。

(14)

Chapter 2 相關研究

本章將分析TeraSort[24]所應用到的相關技術,以及提供雲端計算在分區的 相關知識,第一節、第二節和第三節將會詳細的說明Hadoop平台的架構,以及 組成的module,第四節探討MapReduce在各個階段所用到的型態以及格式。

2.1 Hadoop 架構概述

Hadoop雲端運算架構是由Apache所主導與開發,具備高度擴充性及可用度 的大型資料處理技術。Hadoop雲端運算技術由三個主要架構組成:分散式檔案 系統架構Hadoop Distributed File System (HDFS)[26]、分散式資料庫架構Hadoop Base (HBase)[27]及分散式資料平行運算處理架構Hadoop MapReduce。這三項 技術架構分別對映Google的分散式檔案系統GFS (Google File System)[4]、分散 式資料架構BigTable與分散式運算架構MapReduce三項雲端運算核心技術,利 用Hadoop技術可建構與Google類似的雲端運算系統。

Hadoop MapReduce是一種工作負載分散處理系統,將待處理的工作拆解 成多個執行緒(thread),各自在不同的節點平行處理[5][6]。HBase是儲存系 統,能將處理過後的大量資料分散在許多節點儲存,具備良好的擴充性[27]。

HDFS是分散式的檔案系統架構,可連結許多伺服器或電腦,形成雲端架 構中的節點;這些節點所組成的大型分散式檔案系統,可以避免因單一硬體發 生異常而影響系統整體服務,不僅變更架構規模更加容易,還能提供更高的可 靠性。

(15)

Apache基金會用Java實現了一個Hadoop開放原始碼版本,支援Fedora、

Ubuntu等Linux平台。目前Hadoop受到Yahoo的支持,有Yahoo員工長期工作在 此項目上,且Yahoo內部也開始使用Hadoop代替原本的分散式系統。Hadoop實 現了HDFS文件系統和MapReduce,使Hadoop成為了一個分散式的計算平台。

用戶只要有MapReduce基礎,提供分別實現Map和Reduce的兩個類別,並注冊 Job即可自動分散式運行[26];因此Hadoop並不僅僅是一個用於儲存的分散式文 件系統,而是設計用來在一般計算設備組成的叢集上執行分散式應用的框架。

2.2 HDFS 概述

HDFS(Hadoop Distributed File System)是根據Google發表的GFS(Google File System)檔案系統實作[26],其設計理念是在大型分散式儲存環境中,提 供單一目錄系統(Single Namespace),以有效處理大量檔案,並提供安全的 儲存環境[22]。

HDFS採用master/slave架構的分散式檔案系統,由NameNode與DataNode兩 種伺服器所組成,master是指一個NameNode,slave則是多個DataNode[17]。

HDFS可以處理1萬個節點、1億個檔案以及1萬個terabytes(TBs,1TB=1000GB

)的資料量[23]。

HDFS將檔案切割成大小相同(128MB)的區塊,DataNode則以區塊為單 位,實際儲存資料,並負責管理資料內容,每個區塊可以獨立被建立、複製或 刪除。

NameNode 負 責 管 理 檔 案 系 統 、 DataNode 資 料 配 置 ( 檔 案 位 於 哪 個 DataNode)、檔案權限、檔案動作(新增∕刪除∕開啟∕關閉…)等;換言之,

NameNode 知 道 檔 案 被 切 割 成 哪 些 區 塊 , 也 知 道 這 些 區 塊 分 別 儲 存 在 哪 些 DataNode。

(16)

1. 資料僅可讀取,無法更新修改。HDFS的存取特性是檔案被建立或寫入 後,就不允許修改。後續僅能附加於原檔案之後,不能修改現有內容,以維護 資料一致性。

2. 檔案內容分散儲存,降低風險[8]。HDFS將檔案分割為多個區塊,每個 區塊再複製副本,分散儲存於不同DataNode上,這種作業方式可以降低資料因 DataNode故障而遺失的風險[7]。

3. 檔案資訊與實體資料分離,增加擴充性。檔案本身的資訊與實體資料 分離,即使資料量大幅增加,檔案資訊不會同步大幅擴增,較易於使用與擴充

2.3 HBASE 概述

HBase(Hadoop Base)是以欄位(column)為單位的分散式資料庫系統架 構[27]。HBase會依據欄位大小分割資料,並分散到多部機器;也會壓縮資料

,節省磁碟存放空間;同時利用記憶體存取快速的優點,加速資料的讀寫動作

。HBase係針對大量資料處理最佳化,專門處理Petabyte(PB,1PB=1000TB)

等級的結構化資料,其資料模型與傳統關聯式資料庫並不相同。

建立HBase table時,只需定義column family,並以row Key為主要索引[11]

。每一row Key可對應多個欄位,每個欄位可以有任意數量的成員(值),資 料格式無任何限制。大量資料可以先切割成許多欄位,再依據row key分配到不 同的磁碟進行處理。

HBase 是 由 HMaster 與 HRegion 所 組 成 , 一 部 HMaster 管 理 多 部 HRegion Server。HRegion Server會將最近寫入的資料先存放在記憶體內,再定期的將記 憶體內的資料寫入磁碟檔案。HMaster則負責監控與管理HRegion Server系統狀

(17)

HBase的特性歸納如下:

1. 適合儲存大量資料。HBase是分散式儲存架構設計,用以儲存大量資

料。如果資料量不多,則不適合使用此架構。

2. 資料分散儲存,提高存取效率。HBase可以提供高速的資料讀取與寫

入速度。資料寫入時,會先存於節點主機的動態記憶體,每隔一段時間才寫入 HDFS檔案系統;讀取資料時,也是先讀取節點主機的動態記憶體,如果找不 到,才會搜尋HDFS。

3. HRegion Server分散配置,擴充容易並降低風險。負責管理資料讀寫 的HRegion Server採分散式配置,如需擴大規模相對容易。HRegion Server如發 生異常,會嘗試自動復原,降低風險。

2.4 MapReduce 型態與格式

MapReduce是一個簡單使用的資料處理模型,用於輸入及輸出,都是一對 Key/Value,重要的是,從簡單的文字結構到二進制結構,皆可使用這個模型

Map和Reduce function的一般形態如下:

map:(K1, V1) → list(K2, V2) reduce:(K2, list(V2) → list(K3, V3)

一般map的input Key/Value和map的output Key/Value不同型態,但Reduce output Key/Value必須和map output Key/Value是相同型態,雖然Reduce的output 型態可能與(K3和V3)不同,以下為Java interface的實現:

(18)

一個combine function的使用,它的形式及功能和reduce function類似,他 的輸出型態與intermediate Key/Value(K2 and V2)相同。Map、Reduce和Combin 的處理型態:

map:(K1, V1) → list(K2, V2) combine:(K2,V2) → list(K2,V2) reduce:(K2, list(V2) → list(K3, V3)

Partition function工作方式是根據intermediate Key/Value(K2和V2)傳回分區 索引值,實際運用中,分區是由Key名稱決定,而Value會被忽略。以下為 partition處理型態:

partition: (K2, V2) → interger Java程式碼如下:

Hadoop可以處理許多不同類型的資料格式,從一般的文字格式到資料庫,

每一個mapper處理一個split,每個split分解為record,以下為把輸入拆解的Java

public interface Partitioner<K2, V2> extends JobConfigurable { int getPartition(K2 key, V2 value, int numPartitions);

}

public interface Mapper<K1, V1, K2, V2> extends JobConfigurable, Closeable { void map(K1 key, V1 value, OutputCollect<K2, V2> output, Reporter reporter) Throws IOException;

}

public interface Reducer<K2, V2, K3, V3> extends JobConfigurable, Closeble { Void reduce(K2 key, Iterator<V2> values,

OutputCollector<K3,V3> output, Reporter reporter) throws IOException;

} }

(19)

public interface InputSplit extends Writable { long getLength() throws IOException;

String[] getLocations() throws IOException;

}

(20)

Chapter 3

Hadoop Shuffle工作流程

Shuffle是依據map輸出的intermediate key/value產生分區。系統將map處理 後的intermediate key/value轉移和排序後,輸出至reducer的過程,稱之為shuffle

。這一章,探討shuffle的流程細節和方法。

3.1 HashCode 分區演算法

MapReduce預設的分區方式為HashCode,在此說明其相關演算與流程並舉 例。以下為公式(1)用於計算HashCode的方法:

0 1 2

1

1 31 ... 31

31     

W W W

HashCode n n n n

=

TotalWord

n

n

W

n 1

31 1 (1)

如圖3-1,是一個產生三個分區給相對應的三個Reducer的例子,其演算法 如下:

1. 依公式(1),求出K2的HashCode。

2. 依 其 Reducer 數 目 , 就 做 幾 份 Partition , 該 K2 所 分 配 到 的 Partition 為 HashCode(K2)%TotalPartition。

3. 最後依照分區規則分配到Reducer進行計算。

(21)

圖3-1.HashCode partitioner

以上HashCode分區方式,雖可均勻分配運算量,但其輸出結果並未排序完 成,若要排序仍將各Reducer輸出的結果,合併再進行排序。

3.2 TeraSort 演算法與流程

TeraSort是Hadoop中的一個排序作業[24],在2008年,Hadoop在1TB排序

,獲得Sort Benchmark贏得第一名,耗時209秒,TeraSort為了達到平均分散運 算量以及加速排序,用了兩個方法,取樣以及TrieTree[13]。

TeraSort取樣為了加速取樣過程,會把所取樣的樣本,用字首的字數稱之 為階(如圖3-2),用兩階的Tree標記稱之TrieTree,如目前有取樣數據為b、abc、

abd、bcd、abcd、efg、hii、afd、rrr和mnk,將其取樣後,以兩階的Tree展開如 (圖3-2),實際上TeraSort為在加速採用以空間換取時間的作法,將所有用到的 葉子節點先行宣告,當有取樣的葉子節點時,將其標記設為True,依(表3-1)所

Input

<K1,V1>

Map

<K2,V2> Shuffle Reduce

<K2,V2> Output

to be or not to be 1

do not be evil to be 2

to be or not

to be

1

do not be evil

to be

2

evil or

be be

2 be

to

3 to

be,4

do,1

1 evil,1

not,2 or,1

to,3

to

1

not not be

do

3 2

(22)

示,為方便說明在其Array上的偏移值稱為TrieCode,其算法如公式(2),計算 結果如(表3-2)所示。

圖3-2.Trie Level

圖3-3.Two level trie tree Root

a

b f

b

c

e

f

h

i

m

n

r

r

w2

w1

e v i l

e W1

e v W1

W2

e v i W1 W2 W3

Root

e

Root

e v

Root

e v

v W3 W2 W1 W2 W1 W1

(23)

0 1 2

1

1 256 ... 256

256     

W W W

TrieCode n n n n

=

TotalWord

n

n

Wn 1

256 1 (2)

表3-1.Two level trie tree array

w2 - .. a .. a .. b .. b .. e .. h .. m .. r w1 - .. b .. f .. - .. c .. f .. i .. n .. r

flag F T T T T T T T T

表3-2.Two level trie tag

w1 - a a b b e h m r

w2 - b f - c f i n r

TrieCode 0x6162 0x6166 0x6200 0x6263 0x6566 0x6869 0x6d6e 0x7272

flag F T T T T T T T T

當取樣完成後,會建立一個TrieTree如(表3-3),TeraSort會平均的把每個節 點分至各個Reducer,要分到各Reducer的資料稱為分區。每個分區如(表3-3)所 示,此表分為三個分區:

表3-3.Trie tree partition

w1 - a a b b e h m r

w2 - b f - c f i n r

TrieCode 0x6162 0x6166 0x6200 0x6263 0x6566 0x6869 0x6d6e 0x7272

flag F T T T T T T T T

(24)

接下來探討TeraSort的流程,如圖3-3,以下為TeraSort的完整流程介紹:

1. 建立取樣樣本,由Input的K1,產生n個取樣數據,如(表3-4)。

2. 產生的取樣數據,將n個取樣數據寫入partitionFile。

3. 將partitionFile寫入DistributedCache[16]。

4. 根據n個取樣數據,建立的tree(表3-4)。w2下各有256個子節點,共有 256*256個元素共65536,前綴字元相同的key皆會使相同的葉子節點標 記為True。

5. 此範例有3個Reducer,有8個葉子節點,因此平均分配至各Reducer,每 個Reducer都分配到2個節點(表3-4)。

6. 得到2個切割點,”do”及”no”。

7. 當 key 值 的 TrieCode( 公 式 2) 小 於 等 於 ”do” 的 TrieCode , 即 分 配 至 Reducer1,小於等於”no”則分配至Reducer2,其餘分配至Reducer3(圖3- 3)。

(25)

圖3-4.TeraSort flow

表3-4.Build TrieTree flow

w1 NULL b d e n o t

w2 NULL e o v o r o

TrieCode 0x0000 0x6265 0x646f 0x6576 0x6e6f 0x6f72 0x746f Flag False True True True True True True

owner Reducer1 Reducer2 Reducer3

MapReduce預設的分區方式為HashCode,但結果(圖3-1)並未排序,因此 TeraSort,使用有順序的分區方法(圖3-3),用以加速排序及分配運算量。以節 點數平均分配,會產生有些節點的key數較多,有些節點的key數較少的情況;單

Input

<K1,V1>

Map

<K2,V2> Shuffle Reduce

<K2,V2> Output

to be or not to be 1

do not be evil to be 2

to be or not

to be

1

do not be evil

to be

2

be

1 be

2 not to

3 or to

be be

1

3 to evil

2 not do

be be

1 be

be

evil

2 not not

or

3 to to do

be,4 do,1

1

evil,1 not,2

2

or,1 to,3

3

to

(26)

純依據節點的個數做平均,仍會有運算量分配不均的問題,因此把原本僅只有 標記的方式,改良為count,稱之為XTrieTree演算法。

TeraSort目前依據2階所使用的元素大小為256*256,但若要資料更分散,

必須增加階數,但3階為256*256*256需要16777216個元素,不論是在建Tree過 程或網路資料傳輸上,都是極大的overhead,因此本篇論文改良map方式,使 得3階僅需要64*64*64為262144個元素,為原本TeraSort的1/64,大大減少空間 的浪費,並可提升至3階,使得資料更分散,此方法稱為Re-map,因此加入 count及Re-map的方法,稱之為ETrieTree。

(27)

Chapter 4

High Performance MapReduce設計

雖然Google有公開其MapReduce與GFS的設計架構,但是並未公開所開發 的MapReduce的軟體架構平台。因此本研究採用Apache基金會的Hadoop平台作 為本研究的實驗架構。而演算法是改良Owen O’Malley所帶領Yahoo團隊所發展 的TeraSort[24],其原先使用演算法為TrieTree。第一節說明如何改良TrieTree,

加 入 計 數 功 能 為 XTrieTree , 第 二 節 加 入 Re-Map 用 以 節 省 記 憶 體 稱 之 為 ETrieTree。

分區程序用來決定某一Key將對應至那一個Reducer。預設的分區方法為 HashCode , 相 同 的 key 會 被 分 配 到 相 同 的 Reducer 。 由 Sangwon seo 提 出 HPMR(High Performance MapReduce)的關鍵在於Shuffle的技術(圖4-1)[15],要 把Reducer任務排序減少,在Shuffle會增加一些overhead,但卻大大增加分散平 行的程度[19],當處理資料數量愈大的map task,執行此task時間愈來,但此 map phase結束之後,shuffle階段也需要同時完成[9]。網路節點間的頻寬也是一 個重要的因素,因此要減少shuffle的overhad,但卻不能減少運算效率。

HPMR使用的分區規則,必須保證第i個Partition的所有Key,必須永遠大於 第i-1個Partition的Key如(表4-1),如此一來每個Reducer出來的資料,已經排序 完成,其結果不需要合併後再排序。

(28)

圖4-1.HPMR flow

表4-1.HPMR partition

b d e n o t

e o v o r o

- - i - - -

Key name

- - l - - -

Partition Num 1 2 3

以上當Partition後的資料,按順序決定分區,如此一來各Reducer經由 Reduce function出來的資料,可直接合併為output file,可知HPMR的分區演算 法必須是有序,才能節省後面的合併時間,而TeraSort亦使用此類分區方法,

Key,Value|Key,Value|…

Mapper

Key…

Value...

Partition

Sort Partition

Reducer

Key,Value|Key,Value|…

Key,Value|Key,Value|…

Mapper

Key…

Value...

Partition

Sort Partition

Reducer

Key,Value|Key,Value|…

Map

Partition

Partition0 Reduce

… Partition n-1

(29)

TeraSort在平均分配資料量,使用TrieTree平均分配節點方式,但空間分配 上,每個節點所分配到的資料量,非常不平均(圖4-2),因此浪費不必要的元素 來儲存用不到的節點。

0 5000 10000 15000 20000 25000 30000

0 17 34 51 68 85 102 119 136 153 170 187 204 221 238 255 TrieCode

Count Tire1

圖4-2.Data distribution

4.1 XTrieTree 分區演算法

XTrieTree演算法繼承TrieTree,將原本設定Flag的方法,改變為計數(表4- 2),使得在分佈不平均的Key,能夠平均分配至每個Reducer。以下為XTrieTree 的流程(圖4-3):

1. 建立取樣樣本,由Input的K1,產生n個取樣數據,如(表4-2)。

2. 產生的取樣數據,將n個取樣數據寫入partitionFile。

(30)

4. 根據n個取樣數據,建立(表4-2)的tree。w2下各有256個子節點,共有 256*256個元素共65536,前綴字元相同皆會使相同的葉子節點標記為 True。

5. 此範例有3個Reducer,有6個葉子節點和12個key運算量,因此平均分 配至各Reducer,每個Reducer都分配到4個key(表4-2)。

6. 得到2個切割點,”be”及”no”。

7. 當 key 值 的 TrieCode( 公 式 2) 小 於 等 於 ”be” 的 TrieCode , 即 分 配 至 Reducer1,小於等於”no”則分配至Reducer2,其餘分配至Reducer3(圖 4-3):

圖4-3.XTrieTree flow

Input

<K1,V1>

Map

<K2,V2> Shuffle Reduce

<K2,V2> Output

to be or not to be 1

do not be evil to be 2

to be or not

to be

1

do not be evil

to be

2

be

1 be

2 not

to

3 or to

be be

1

3 to evil

2 not do

be be

1 be

be

evil not

2

not

or

3 to to do

be,4

do,1

1

evil,1 not,2

2

or,1 to,3

3

to

(31)

表4-2.XTrieTree Partitioner

W1 b d e n o t

W2 e o v o r o

TrieCode(hex) 0x6265 0x646f 0x6576 0x6e6f 0x6f72 0x746f

Count 4 1 1 2 1 3

Split Count 4 4 4

Reducer Num 1 2 3

4.2 ETrieTree 分區演算法

ETrieTree,是以TrieTree為基礎,加入count與Re-map的方法,節省記憶體

,使得切割節點更分散均勻。以下(表4-3)為ETrieTree的Re-map編碼:

表4-3.ETrieTree Re-map

char NULL 0 … 9 A … Z a … z other ETrieCode 0 1 0x0a 0x0b 0x24 0x25 0x3e 0x3f

ETrieCode演算法,繼承自TrieCode,但Re-map後,權重改變,其演算法(

公式3)如下:

ETrieCode=Wn64n1Wn164n2...W1640

TotalWord

n

n

Wn 1

64 1 (3)

ETrieTree繼承TrieTree,改良使用Re-map及Count方式,其建立ETrieTree 的過程(如下:

以ETrieCode(公式3),製作一範例如下:

ETrieCode(“ev”)=0x25641+0x36640

(32)

以下為依ETrieCode,所建立出來的ETrieTree範例(表4-4):

表4-4.Build ETrieTree

W1 - - … - … e … t ... z

W2 - a … z … v … o … z

ETrieCode 0 0x25 0x003e 0x19b6 0x0d2f 0x0fbe

Count 0 0 0 1 5 0

ETrieTree建立流程如圖(4-4),其步驟如下:

1. 建立取樣樣本,由Input的K1,產生n個取樣數據,如(表4-5)。

2. 產生的取樣數據,將n個取樣數據寫入partitionFile。

3. 將partitionFile寫入DistributedCache[16]。

4. 根據n個取樣數據,建立(表4-5)的tree。w2下各有256個子節點,共有 256*256個元素共65536,前綴字元相同皆會使相同的葉子節點標記為 True。

5. 此範例有3個Reducer,有6個葉子節點和12個key,因此平均分配至各 Reducer,每個Reducer都分配到4個key(表4-5)。

6. 得到2個切割點,”be”及”no”。

(33)

圖4-4.ETrieTree flow

表4-5.ETrie Tree partitioner

W1 b d e n o t

W2 e o v o r o

TrieCode(hex) 0x6265 0x646f 0x6576 0x6e6f 0x6f72 0x746f

Count 4 1 1 2 1 3

SplitCount 4 4 4

ReducerNum 1 2 3

Input

<K1,V1>

Map

<K2,V2> Shuffle Reduce

<K2,V2> Output

to be or not to be 1

do not be evil to be 2

to be or not

to be

1

do not be evil

to be

2

be

1 be

2 not to

3 or to

be be

1

3 to evil

2 not do

be be

1 be

be

evil not

2

not

or

3 to to do

be,4

do,1

1

evil,1 not,2

2

or,1 to,3

3

to

(34)

Chapter 5

實驗結果與分析

本實驗以100本電子書為樣本,每本書在10萬個word以上,以各演算法計 算出每個Split Point的分配均勻度以及該演算法所使用的記憶體,第一節對實 驗所出來的均勻度及空間利用率參數做說明,第二節說明實驗流程,第三節對 最後的結果做分析探討。

5.1 實驗參數

實驗一最後的結果數據,在於分析每個Reducer所分配到的運算量是否平 均,稱之為不平均度,以下為不平均度演算法:

α: Uneven Rate V: Optimal partition,

tions TotalParti

TotalKeys

Sn: Keys of partition N

△Sn: Delta optimal partition N,

S

n |

S

n

V

| V

 



n

S ...

S

Sn n-1 1

n V S

SplitNum

n n

1 (4)

實驗二最後的結果數據,在於分析Tree所需要的空間,而實際使用的空間 有多少,稱之空間利用率。以下為空間利用率演算法:

β:Space optimization rate

(35)

B:Total element

B

A

(5)

5.2 實驗配置

實驗一為比較各Reducer的不平均度,其實驗所用參數設定如下:

輸入資料:100本電子書

結果:比較5~100台電腦的不平均度(α)

實驗二為比較各演算法的空間利用率,其實驗所設置參數如下:

輸入資料:100本電子書

結果:各演算法的空間利用率(β)

5.3 實驗結果與討論

實驗一使用100本電子書,為輸入資料計算不平均度,比較各種演算法的 優劣,得到下列結果:

(36)

0 20 40 60 80 100 120 140 160 180

5 12 19 26 33 40 47 54 61 68 75 82 89 96 Number of computer

uneven rate Trie1

XTrie1 ETrie1

圖5-1.Uneven degree result-one level

0 20 40 60 80 100 120 140

5 12 19 26 33 40 47 54 61 68 75 82 89 96 Number of computer

uneven rate Trie2

XTrie2 ETrie2

圖5-2.Uneven degree result-two level

(37)

Uneven rate Comparison

0 10 20 30 40 50 60 70 80 90

5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 Number of computer

uneven rate Trie3

XTrie3 ETrie3

圖5-3.Uneven degree result-three level

0 20 40 60 80 100 120 140 160

5 12 19 26 33 40 47 54 61 68 75 82 89 96 Number of computer

uneven rate ETrie1

ETrie2 ETrie3

圖5-4.Uneven degree result-ETrie

根據實驗一結果,與改良後的架構比較,發現當階數愈大,資料愈分散,

加入count計算的XTrieTree 3階和ETrieTree 3階,各Reducer的運算量愈平均達 到分散平行的目的。

實驗二為比較各演算法的空間利用率,實驗結果(表5-1)如下:

(38)

表5-1.Space utilization

T1 T2 T3 ET1 ET2 ET3

使用節點數 77 693 3080 56 608 2903

所需空間 256 65536 16777216 64 4096 262144 空間利用率(%) 30.0781 1.0574 0.0183 87.5 14.8437 1.1074

當根據實驗二結果,與改良後的架構比較,發現當階數愈大,資料愈分散

,但相對的所需空間也愈大。

(39)

Chapter 6

結論與未來研究方向

本研究提出了一個基於Hadoop平台下的ETrieTree分配架構,其目的是希 望可以解決資料在空間或時間樣本分配不平均的狀況,能將中小型叢集的網格

,平均至各節點的計算量,進而更平行化,節省空間,使得雲端運算能夠更普 及化至一般民眾。

TeraSort是Owen O’Malley所領導的Yahoo團隊發展出來的排序作業,雖然 極為優秀,但當初設計基於輸入資料為隨機產生,且使用超大型網格,使得每 個分區僅只有一、二個node,本研究改良此架構,更能符合一般中小型私有網 格上的運算,另有Re-Map方法,使得空間不至於被浪費,達到小而巧的功能

經過一系列的實驗證明,本研究所提出ETrieTree架構的確可以在不均勻的 樣本下,比傳統的分區,更加節省記憶體及分配運算量更平均。

在未來的研究方面,此架構下可延續使用不同特微分區,研究針對不同輸 入樣本,在空間的Re-map方式,或是將此架構應用在其他需要大規模運算的領 域上,如影像辨識或是影片比對上面等等。以後可加入對於時間效率實驗的分 析,皆是未來可以研究的方向。

(40)

References

1. Kasim Selcuk Candan, Jong Wook Kim, Parth Nagarkar, Mithila Nagendra and Renwei Yu, “Scalable Multimedia Data Processing in Server Clusters,” IEEE MultiMedia, pp.3-5, 2010.

2. Fay Chang, Jeffrey Dean, Sanjay Ghemawat, Wilson C. Hsieh Deborah A.Wallach Mike Burrws, Tushar Chandra, Andrew Fikes, and Robert E.Gruber,

“ Bigtable: A Distributed Storage System for Structured Data,” 7th UENIX Symposium on Operating Systems Design and Implementation, pp.205-218, 2006.

3. Jeffrey Dean and Sanjay GhemawatDean, “MapReduce: Simplified Data Processing on Large Clusters,” Communications of the ACM, Vol. 51, No. 1 pp.107-113, 2008.

4. Sanjay Ghemawat, Howard Gobioff, and Shun-Tak Leung, “The Google File System,” 19th ACM Symposium on Operating Systems Principles(SOSP), 2003 5. Wei Jiang and Gagan Agrawal, “Ex-MATE Data Intensive Computing with

Large Reduction Objects and Its Application to Graph Mining,” IEEE/ACM International Symposium on Cluster, Cloud and Grid Computing, pp.475-484, 2011.

6. Chao Jin, Christian Vecchiola and Rajkumar Buyya, "MRPGA: An Extension of MapReduce for Parallelizing Genetic Algorithms," IEEE Fourth International Conference on eScience, pp.214-220, 2008.

7. Soila Kavulya, Jiaqi Tany, Rajeev Gandhi and Priya Narasimhan, "An Analysis of Traces from a Production MapReduce Cluster," IEEE/ACM International

(41)

8. Arun Krishnan, “GridBLAST: a Globus-based high-throughput implementation of BLAST in a Grid computing framework,”Concurrency and Computation,”

Vol.17, No. 13, pp.1607-1623, 2005.

9. Huan Liu and Dan Orban, “Cloud MapReduce: a MapReduce Implementation on top of a Cloud Operating System,” IEEE/ACM International Symposium on Cluster, Cloud and Grid Computing, pp.464-474, 2011.

10. Andréa Matsunaga, Maurício Tsugawa and José Fortes, “Combining MapReduce and Virtualization on Distributed Resources,” IEEE Fourth International Conference on eScience, pp.224-225, 2008.

11. Andréa Matsunaga, Maurício Tsugawa and José Fortes, “Programming Abstractions for Data Intensive Computing on Clouds and Grids,” IEEE Fourth International Conference on eScience, pp.489-493, 2008.

12. Chris Miceli, Michael Miceli, Shantenu Jha, Hartmut Kaiser, Andre Merzky,

“Programming Abstractions for Data Intensive Computing on Clouds and Grids,”

IEEE/ACM International Symposium on Cluster Computing and the Grid, pp.480-483, 2009.

13. Biswanath Panda, Mirek Riedewald and Daniel Fink, “The Model-Summary Problem and a Solution for Trees,” International Conference on Data Engineering, pp.452-455, 2010.

14. Spiros Papadimitriou and Jimeng Sun, “Distributed Co-clustering with Map- Reduce,” IEEE International Conference on Data Mining, pp.519, 2008.

15. Sangwon Seo, Ingook Jang,Kyungchang Woo,Inkyo Kim, Jin-Soo Kim,

“Prefetching and Pre-shuffling in Shared MapReduce Computation Environment,” IEEE international Conference on Cluster Computing and

(42)

16. Jeffrey Shafer, Scott Rixner, and Alan L. Cox, “The Hadoop distributed filesystem: Balancing portability and performance,” IEEE International Symposium on Performance Analysis of System and Software(ISPASS), pp.123, 2010.

17. Heinz Stockinger, Marco Pagni, Lorenzo Cerutti and Laurent Falquet, “Grid Approach to Embarrassingly Parallel CPU-Intensive Bioinformatics Problems,”

IEEE International Conference on e-Science and Grid Computing, 2006

18. J. Tan, X. Pan, S. Kavulya, R. Gandhi, and P. Narasimhan, “Mochi: Visual Log- Analysis Based Tools for Debugging Hadoop,” USENIX Workshop on Hot Topics in Cloud Computing (HotCloud), 2009.

19. Chao Tian, Haojie Zhou1,Yongqiang He, Li Zha1, “A Dynamic MapReduce Scheduler for Heterogeneous Workloads,” International Conference on Grid and Cooperative Computing, pp.221-225, 2009.

20. Himanshu Vashishtha, Michael Smit, Eleni Stroulia, “Moving Text Analysis Tools to the Cloud,” IEEE World Congress on Services ,pp.110-112, 2010.

21. Abhishek Verma, Xavier Llor'a, David E. Goldberg and Roy H. Campbell,

“Scaling Genetic Algorithms using MapReduce,” International Conference on Intelligent Systems Design and Applications, 2009.

22. Wei Xu, Ling Huang, Armando Fox, David Patterson, and Michael Jordan,

“Detecting large-scale system problems by mining console logs,” In Processdings of the ACM SIGOPS 22nd Symposium on Operating Systems Principles (SOSP), 2009.

(43)

23. Zacharia Fadika and Madhusudhan Govindaraju, “DELMA: Dynamic Elastic MApReduce Framework for CPU-Intensive Applications,” IEEE/ACM International Symposium on Cluster, Cloud and Grid Computing, pp.454-463, 2011.

24. Owen O’Malley, “TeraByte Sort on Apache Hadoop”,2008

25. Apache Software Foundation, “Hadoop,” 2007, http://hadoop.apache.org/core.

26. Hadoop Distributed File System (HDFS) Architecture. [Online] Available:

http://hadoop.apache.org/core/docs/current/hdfs design.html 27. HBase, http://hadoop.apache.org/hbase/.

參考文獻

相關文件

• Instead of uploading and downloading the dat a from cloud to client for computing , we shou ld directly computing on the cloud ( public syst em ) to save data transferring time.

The applications of an ERP cloud service to improve the effective management of a SCC and the related possible operational issues are then discussed1. Finally, a real case of an

and Liu, S.J., “Quantifying Benefits of Knowledge Management System: A Case Study of an Engineering Consulting Firm,” Proceedings of International Symposium on Automation and

Eclipse 需要安裝 Java Runtime。建議使用 Java 7(又稱為 Java 1.7)或 Java 6。Java 提供兩種版本,Java Runtime Environment(JRE)和 Java Development Kit(JDK) 。

Moriya-cho, Kanagawa-ku, Yokohama-shi, Kanagawa(2001), “A Human Interface Design of Multiple Collision Warning System,” Paper presented at the International Symposium on

In the result, the priority of the implementation of the clouding information systems follows the clouding transaction system with strongly influences in the routine works, the

Chen, “Adjustable gamma correction circuit for TFT LCD,” IEEE International Symposium on Circuits and Systems, vol. Kan, “Implementation of the Gamma (γ) Line System Similar

Lee, ”Effects of Build-Up Printed Circuit Board Thickness on the Solder Joint Reliability of a Wafer Level Chip Scale Package (WLCSP),” IEEE International Symposium