欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Giraph源碼分析(一)—啟動ZooKeeper服務(wù)-創(chuàng)新互聯(lián)

作者 | 白松

公司主營業(yè)務(wù):網(wǎng)站制作、成都網(wǎng)站設(shè)計、移動網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。創(chuàng)新互聯(lián)是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。創(chuàng)新互聯(lián)推出揭陽免費做網(wǎng)站回饋大家。

【注:本文為原創(chuàng),引用轉(zhuǎn)載需與博主聯(lián)系。】

Giraph介紹:

Apache Giraph is an iterative graph processing system built for high scalability. For example, it is currently used at Facebook to analyze the social graph formed by users and their connections. Giraph originated as the open-source counterpart to Pregel, the graph processing architecture developed at Google and described in a 2010 paper. Both systems are inspired by the Bulk Synchronous Parallelmodel of distributed computation introduced by Leslie Valiant. Giraph adds several features beyond the basic Pregel model, including master computation, sharded aggregators, edge-oriented input, out-of-core computation, and more. With a steady development cycle and a growing community of users worldwide, Giraph is a natural choice for unleashing the potential of structured datasets at a massive scale.

原理:

Giraph基于Hadoop而建,將MapReduce中Mapper進行封裝,未使用reducer。在Mapper中進行多次迭代,每次迭代等價于BSP模型中的SuperStep。一個Hadoop Job等價于一次BSP作業(yè)。基礎(chǔ)結(jié)構(gòu)如下圖所示。

每部分的功能如下:

1. ZooKeeper: responsible for computation state

–partition/worker mapping

–global state: #superstep

–checkpoint paths, aggregator values, statistics

2. Master: responsible for coordination

–assigns partitions to workers

–coordinates synchronization

–requests checkpoints

–aggregates aggregator values

–collects health statuses

3. Worker: responsible for vertices

–invokes active vertices compute() function

–sends, receives and assigns messages

–computes local aggregation values

Giraph源碼分析(一)— 啟動ZooKeeper服務(wù)

說明

(1)實驗環(huán)境

三臺服務(wù)器:test165、test62、test63。test165同時是JobTracker和TaskTracker.

測試例子:官網(wǎng)自帶的SSSP程序,數(shù)據(jù)是自己模擬生成。

運行命令:Hadoop jar giraph-examples-1.0.0-for-hadoop-0.20.203.0-jar-with-dependencies.jar org.apache.giraph.GiraphRunner org.apache.giraph.examples.SimpleShortestPathsVertex -vif org.apache.giraph.io.formats.JsonLongDoubleFloatDoubleVertexInputFormat -vip /user/giraph/SSSP -of org.apache.giraph.io.formats.IdWithValueTextOutputFormat -op /user/giraph/output-sssp-debug-7 -w 5

(2)為節(jié)約空間,下文中所有代碼均為核心代碼片段。

(3)core-site.xml中hadoop.tmp.dir的路徑設(shè)為:/home/hadoop/hadooptmp

(4)寫本文是多次調(diào)試完成的,故文中的JobID不一樣,讀者可理解為同一JobID.

(5)后續(xù)文章也遵循上述規(guī)則。

org.apache.giraph.graph.GraphMapper類

Giraph中自定義org.apache.giraph.graph.GraphMapper類來繼承Hadoop中的 org.apache.hadoop.mapreduce.Mapper<Object,Object,Object,Object>類,覆寫了setup()、map()、cleanup()和run()方法。GraphMapper類的說明如下:

“This mapper that will execute the BSP graph tasks alloted to this worker. All tasks will be performed by calling the GraphTaskManager object managed by this GraphMapper wrapper classs. Since this mapper will not be passing data by key-value pairs through the MR framework, the Mapper parameter types are irrelevant, and set to Object type.”

BSP的運算邏輯被封裝在GraphMapper類中,其擁有一GraphTaskManager對象,用來管理Job的tasks。每個GraphMapper對象都相當于BSP中的一個計算節(jié)點(compute node)。

在GraphMapper類中的setup()方法中,創(chuàng)建GraphTaskManager對象并調(diào)用其setup()方法進行一些初始化工作。如下:

Giraph源碼分析(一)— 啟動ZooKeeper服務(wù)

map()方法為空,因為所有操作都被封裝在了GraphTaskManager類中。在run()方法中調(diào)用GraphTaskManager對象的execute()方法進行BSP迭代計算。

Giraph源碼分析(一)— 啟動ZooKeeper服務(wù)

org.apache.giraph.graph.GraphMapper類

功能:The Giraph-specific business logic for a single BSP compute node in whatever underlying type of cluster our Giraph job will run on. Owning object will provide the glue into the underlying cluster framework and will call this object to perform Giraph work.

下面講述setup()方法,代碼如下:

Giraph源碼分析(一)— 啟動ZooKeeper服務(wù)

###?依次介紹每個方法的功能:

1、locateZookeeperClasspath(zkPathList)

找到ZK jar的本地副本,其路徑為:/home/hadoop/hadooptmp/mapred/local/taskTracker/root/jobcache/job_201403270456_0001/jars/job.jar ,用于啟動ZooKeeper服務(wù)。

2、startZooKeeperManager(),初始化和配置ZooKeeperManager。

定義如下:

Giraph源碼分析(一)— 啟動ZooKeeper服務(wù)

3、org.apache.giraph.zk.ZooKeeperManager 類

功能:Manages the election of ZooKeeper servers, starting/stopping the services, etc.

ZooKeeperManager類的setup()定義如下:

Giraph源碼分析(一)— 啟動ZooKeeper服務(wù)

createCandidateStamp()方法在 HDFS上 的_bsp/_defaultZkManagerDir/job_201403301409_0006/_task 目錄下為每個task創(chuàng)建一個文件,文件內(nèi)容為空。文件名為本機的Hostname+taskPartition,如下截圖:

Giraph源碼分析(一)— 啟動ZooKeeper服務(wù)
運行時指定了5個workers(-w 5),再加上一個master,所有上面有6個task。

getZooKeeperServerList()方法中,taskPartition為0的task會調(diào)用createZooKeeperServerList()方法創(chuàng)建ZooKeeper server List,也是創(chuàng)建一個空文件,通過文件名來描述Zookeeper servers。

Giraph源碼分析(一)— 啟動ZooKeeper服務(wù)

首先獲取taskDirectory(_bsp/_defaultZkManagerDir/job_201403301409_0006/_task)目錄下文件,如果當前目錄下有文件,則把文件名(Hostname+taskPartition)中的Hostname和taskPartition存入到hostNameTaskMap中。掃描taskDirectory目錄后,若hostNameTaskMap的size大于serverCount(等于GiraphConstants.java中的ZOOKEEPER_SERVER_COUNT變量,定義為1),就停止外層的循環(huán)。外層循環(huán)的目的是:因為taskDirectory下的文件每個task文件時多個task在分布式條件下創(chuàng)建的,有可能task 0在此創(chuàng)建server List時,別的task還沒有生成后task文件。Giraph默認為每個Job啟動一個ZooKeeper服務(wù),也就是說只有一個task會啟動ZooKeeper服務(wù)。

經(jīng)過多次測試,task 0總是被選為ZooKeeper Server ,因為在同一進程中,掃描taskDirectory時,只有它對應(yīng)的task 文件(其他task的文件還沒有生成好),然后退出for循環(huán),發(fā)現(xiàn)hostNameTaskMap的size等于1,直接退出while循環(huán)。那么此處就選了test162 0。

最后,創(chuàng)建了文件:_bsp/_defaultZkManagerDir/job_201403301409_0006/zkServerList_test162 0

Giraph源碼分析(一)— 啟動ZooKeeper服務(wù)

onlineZooKeeperServers(),根據(jù)zkServerList_test162 0文件,Task 0 先生成zoo.cfg配置文件,使用ProcessBuilder來創(chuàng)建ZooKeeper服務(wù)進程,然后Task 0 再通過socket連接到ZooKeeper服務(wù)進程上,最后創(chuàng)建文件 _bsp/_defaultZkManagerDir/job_201403301409_0006/_zkServer/test162 0 來標記master任務(wù)已完成。worker一直在進行循環(huán)檢測master是否生成好 _bsp/_defaultZkManagerDir/job_201403301409_0006/_zkServer/test162 0即worker等待直到master上的ZooKeeper服務(wù)已經(jīng)啟動完成。

啟動ZooKeeper服務(wù)的命令如下:

Giraph源碼分析(一)— 啟動ZooKeeper服務(wù)

4、determineGraphFunctions()。

GraphTaskManager類中有CentralizedServiceMaster對象和CentralizedServiceWorker 對象,分別對應(yīng)于master和worker。每個BSP compute node扮演的角色判定邏輯如下:

a) If not split master, everyone does the everything and/or running ZooKeeper.
b) If split master/worker, masters also run ZooKeeper
c) If split master/worker == true and giraph.zkList is set, the master will not instantiate a ZK instance, but will assume a quorum is already active on the cluster for Giraph to use.

該判定在GraphTaskManager 類中的靜態(tài)方法determineGraphFunctions()中定義,片段代碼如下:

Giraph源碼分析(一)— 啟動ZooKeeper服務(wù)

默認的,Giraph會區(qū)分master和worker。會在master上面啟動zookeeper服務(wù),不會在worker上啟動ZooKeeper服務(wù)。那么Task 0 就是master+ZooKeeper,其他Tasks就是workers

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

本文標題:Giraph源碼分析(一)—啟動ZooKeeper服務(wù)-創(chuàng)新互聯(lián)
文章地址:http://www.chinadenli.net/article36/dijcsg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計手機網(wǎng)站建設(shè)響應(yīng)式網(wǎng)站ChatGPT網(wǎng)站改版微信公眾號

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化