MR-5.MapReduce计数器介绍
2016-01-26 19:26
183 查看
计数器(couter)
在许多情况下,用户需要了解分析的数据,统计出输入记录数、统计数据无效记录数。通过计算器可以检测程序存储缺陷和数据集质量高低问题。计算器分成两类:内置计数器和自定义计算器。内置计数器
Hadoop为每个作业维护提供若干内置计数器。以描述作业的指标。l File System Counters
l Map-Reduce Framework
l Shuffle Errors
l File Input Format Counters
l File Output Format Counters
自定义计数器
MapReduce允许用户编写程序来定义计数器,计数器的值可以在mapper或者reducer中增加。MapReduce框架将跨所有的map和reduce聚集这些计数器,并在作业结束时产生一个最终结果。案例分析:
(1)在MapReduce的mapper端计数器设定
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { if (value.toString().contains("hello")) { // 输入敏感词统计-当查询到hello关键字的词汇时,计数器加1 context.getCounter("Sensitive Counters", "hello").increment(1L); } String[] words = value.toString().split("\t"); for (String word : words) { k2.set(word.getBytes()); v2.set(1); context.write(k2, v2); } } |
这里包括内置计数器的获取和用户自定义的计数器的获取。
Counters counters = job.getCounters(); //获取自定义的counter信息 Counter c1 = counters.findCounter("Sensitive Counters","hello"); System.out.println(c1.getValue()); //获取系统内置的counter信息 Counter c21 = counters.findCounter(TaskCounter.MAP_INPUT_RECORDS); Counter c22 = counters.findCounter(TaskCounter.MAP_OUTPUT_RECORDS); System.out.println(c21.getValue() + "-> " + c22.getValue()); |
相关文章推荐
- uva 11462 - Age Sort
- pytest相关问题解析
- java线程安全之死锁问题
- ehcache+spring配置
- Excel中的四舍六入五成双
- 关于Bitcode的探索
- 分类器组合方法
- 贴段脚本...Linux命令批量执行,免密码登录配置
- Socket通信之一次通路多次会话问题
- hdu2795
- [Java - 调用WebService]{http://schemas.microsoft.com/ws/2005/05/addressing/none}ActionNotSupported
- JPA学习笔记(2)之相关接口/类
- Android中关于键盘的处理
- HUST 1027 Enemy Target! 最小点覆盖集
- 微服务构建大应用
- MR-4.MapReduce使用压缩
- poj-1094 Sorting It All Out
- 字符串匹配算法-KMP详解
- ?12星座综合实力排行,第一名居然是他……
- 网络攻击