作者|白松
成都網(wǎng)絡(luò)公司-成都網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)十年經(jīng)驗成就非凡,專業(yè)從事成都網(wǎng)站制作、做網(wǎng)站、外貿(mào)營銷網(wǎng)站建設(shè),成都網(wǎng)頁設(shè)計,成都網(wǎng)頁制作,軟文推廣,廣告投放平臺等。十年來已成功提供全面的成都網(wǎng)站建設(shè)方案,打造行業(yè)特色的成都網(wǎng)站建設(shè)案例,建站熱線:18980820575,我們期待您的來電!
1、?添加類,把每個超步發(fā)送的消息量大小寫入Hadoop的Counter中。在org.apache.giraph.counters包下新建GiraphMessages類,來統(tǒng)計消息量。
源代碼如下:
package org.apache.giraph.counters;
import java.util.Iterator;
import java.util.Map;
import org.apache.hadoop.mapreduce.Mapper.Context;
import com.google.common.collect.Maps;
/**
* Hadoop Counters in group "Giraph Messages" for counting every superstep
* message count.
*/
public class GiraphMessages extends HadoopCountersBase {
/** Counter group name for the giraph Messages */
public static final String GROUP_NAME = "Giraph Messages";
/** Singleton instance for everyone to use */
private static GiraphMessages INSTANCE;
/** superstep time in msec */
private final Map superstepMessages;
private GiraphMessages(Context context) {
super(context, GROUP_NAME);
superstepMessages = Maps.newHashMap();
}
/**
* Instantiate with Hadoop Context.
*
* @param context
* Hadoop Context to use.
*/
public static void init(Context context) {
INSTANCE = new GiraphMessages(context);
}
/**
* Get singleton instance.
*
* @return singleton GiraphTimers instance.
*/
public static GiraphMessages getInstance() {
return INSTANCE;
}
/**
* Get counter for superstep messages
*
* @param superstep
* @return
*/
public GiraphHadoopCounter getSuperstepMessages(long superstep) {
GiraphHadoopCounter counter = superstepMessages.get(superstep);
if (counter == null) {
String counterPrefix = "Superstep- " + superstep+" ";
counter = getCounter(counterPrefix);
superstepMessages.put(superstep, counter);
}
return counter;
}
@Override
public Iterator iterator() {
return superstepMessages.values().iterator();
}
}
2、在BspServiceMaster類中添加統(tǒng)計功能。Master在每次同步時候,會聚集每個Worker發(fā)送的消息量大小(求和),存儲于GlobalStats中。因此只需要在每次同步后,從GlobalStats對象中取出總的通信量大小,然后寫入GiraphMessages中。格式為
GiraphMessages.init(context);
在BspServiceMaster類的SuperstepState coordinateSuperstep()方法中,添加記錄功能。片段代碼如下:
……
// If the master is halted or all the vertices voted to halt and there
// are no more messages in the system, stop the computation
GlobalStats globalStats = aggregateWorkerStats(getSuperstep());
LOG.info("D-globalStats: "+globalStats+"\n\n");
//添加下面語句。從第0個超步起開始記錄。
if(getSuperstep() != INPUT_SUPERSTEP) {
GiraphMessages.getInstance().getSuperstepMessages(getSuperstep()).increment(globalStats.getMessageCount());
}
……
3、實驗結(jié)果如下:
完!