Giraph源码分析(七)—— 添加消息统计功能
发表于:2025-02-24 作者:千家信息网编辑
千家信息网最后更新 2025年02月24日,作者|白松1、 添加类,把每个超步发送的消息量大小写入Hadoop的Counter中。在org.apache.giraph.counters包下新建GiraphMessages类,来统计消息量。源代码
千家信息网最后更新 2025年02月24日Giraph源码分析(七)—— 添加消息统计功能
作者|白松
1、 添加类,把每个超步发送的消息量大小写入Hadoop的Counter中。在org.apache.giraph.counters包下新建GiraphMessages类,来统计消息量。
源代码如下:
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类中添加统计功能。Master在每次同步时候,会聚集每个Worker发送的消息量大小(求和),存储于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 computationGlobalStats globalStats = aggregateWorkerStats(getSuperstep()); LOG.info("D-globalStats: "+globalStats+"\n\n");//添加下面语句。从第0个超步起开始记录。if(getSuperstep() != INPUT_SUPERSTEP) { GiraphMessages.getInstance().getSuperstepMessages(getSuperstep()).increment(globalStats.getMessageCount());}……
3、实验结果如下:
完!
消息
大小
功能
统计
代码
对象
方法
同步
存储
一行
作者
实际
时候
格式
源代码
片段
结果
语句
白松
上步
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
计算机网络技术专升本难吗统招
大学生网络安全情景短句
服务器配置与管理的书籍
网易实况足球有服务器么
关闭mysql的服务器
福师大考研网络安全
db2数据库连接数高
国泰君安数据库登陆
最新网络安全培训课程
唐宋文学编年系地数据库
帐套初始化数据库
武汉帮帮手软件开发有限公司
数据库二维表 设计
58软件开发的加班情况
服务器端管理端客户端区别
常州数据库审计服务
mc服务器怎么做才能热闹一点
球球大作战连不上服务器
最终幻想14哪个服务器
比尔盖茨科技电子软件开发工程
固件下载软件开发
EDA网络安全认证
中国医院网络安全攻防培训
数据库清除安全日志
网络安全挖洞具体步骤
网络安全知识培训考试题
栾城区节能软件开发服务供应
linuxdb2数据库安装步骤
网网络安全的手抄报图片
网络安全与信息化体系建设