mr中间结果优化
转载请注明出处:http://blog.csdn.net/lastsweetop/article/details/9187721
作为输入
作为输出
- package com.sweetop.styhadoop;
- import org.apache.hadoop.fs.Path;
- import org.apache.hadoop.io.IntWritable;
- import org.apache.hadoop.io.Text;
- import org.apache.hadoop.io.compress.GzipCodec;
- import org.apache.hadoop.mapreduce.Job;
- import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
- import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
- import java.io.IOException;
- /**
- * Created with IntelliJ IDEA.
- * User: lastsweetop
- * Date: 13-6-27
- * Time: 下午7:48
- * To change this template use File | Settings | File Templates.
- */
- public class MaxTemperatureWithCompression {
- public static void main(String[] args) throws Exception {
- if (args.length!=2){
- System.out.println("Usage: MaxTemperature <input path> <out path>");
- System.exit(-1);
- }
- Job job=new Job();
- job.setJarByClass(MaxTemperature.class);
- job.setJobName("Max Temperature");
- FileInputFormat.addInputPath(job, new Path(args[0]));
- FileOutputFormat.setOutputPath(job, new Path(args[1]));
- job.setMapperClass(MaxTemperatrueMapper.class);
- job.setCombinerClass(MaxTemperatureReducer.class);
- job.setReducerClass(MaxTemperatureReducer.class);
- job.setOutputKeyClass(Text.class);
- job.setOutputValueClass(IntWritable.class);
- FileOutputFormat.setCompressOutput(job, true);
- FileOutputFormat.setOutputCompressorClass(job, GzipCodec.class);
- System.exit(job.waitForCompletion(true)?0:1);
- }
- }
输入也是一个压缩文件
- ~/hadoop/bin/hadoop com.sweetop.styhadoop.MaxTemperatureWithCompression input/data.gz output/
- [hadoop@namenode test]$hadoop fs -get output/part-r-00000.gz .
- [hadoop@namenode test]$ls
- 1901 1902 ch2 ch3 ch4 data.gz news.gz news.txt part-r-00000.gz
- [hadoop@namenode test]$gunzip -c part-r-00000.gz
- 1901<span style="white-space:pre"> </span>317
- 1902<span style="white-space:pre"> </span>244
如果你要将序列文件做为输出,你需要设置mapred.output.compression.type属性来指定压缩类型,默认是RECORD类型,它会按单个的record压缩,如果指定为BLOCK类型,它将一组record压缩,压缩效果自然是BLOCK好。
- SequenceFileOutputFormat.setOutputCompressionType(job, SequenceFile.CompressionType.BLOCK);
如果你用Tool接口来跑mapreduce的话,可以在命令行设置这些参数,明显比硬编码好很多
压缩map输出
- Configuration conf = new Configuration();
- conf.setBoolean("mapred.compress.map.output", true);
- conf.setClass("mapred.map.output.compression.codec",GzipCodec.class, CompressionCodec.class);
- Job job=new Job(conf);
mr中间结果优化的更多相关文章
- 【Hadoop】Hadoop MR 性能优化 Combiner机制
1.概念 2.参考资料 提高hadoop的mapreduce job效率笔记之二(尽量的用Combiner) :http://sishuo(k).com/forum/blogPost/list/582 ...
- Hive整体优化策略
一 整体架构优化 现在hive的整体框架如下,计算引擎不仅仅支持Map/Reduce,并且还支持Tez.Spark等.根据不同的计算引擎又可以使用不同的资源调度和存储系统. 整体架构优化点: 1 根据 ...
- MR中的combiner和partitioner
1.combiner combiner是MR编程模型中的一个组件: 有些任务中map可能会产生大量的本地输出,combiner的作用就是在map端对输出先做一次合并,以减少map和reduce节点之间 ...
- Hadoop优化
一.影响MR程序效率的因素 1.计算机性能: CPU.内存.磁盘.网络, 计算机的性能会影响MR程序的速度与效率 2.I/O方面 1)数据倾斜(代码优化) 2)map和reduce数量设置不合理(通过 ...
- Hadoop3.x 三大组件详解
Hadoop Hadoop适合海量数据分布式存储和分布式计算 运行用户使用简单的编程模型实现跨机器集群对海量数据进行分布式计算处理 1. 概述 1.1 简介 Hadoop核心组件 HDFS (分布式文 ...
- 浅析Hadoop文件格式
Hadoop 作为MR 的开源实现,一直以动态运行解析文件格式并获得比MPP数据库快上几倍的装载速度为优势.不过,MPP数据库社区也一直批评Hadoop由于文件格式并非为特定目的而建,因此序列化和反序 ...
- hadoop 原理: 浅析Hadoop文件格式
Hadoop 作为MR 的开源实现,一直以动态运行解析文件格式并获得比MPP数据库快上几倍的装载速度为优势.不过,MPP数据库社区也一直批评Hadoop由于文件格式并非 为特定目的而建,因此序列化和反 ...
- 【原创】大数据基础之Hive(5)性能调优Performance Tuning
1 compress & mr hive默认的execution engine是mr hive> set hive.execution.engine;hive.execution.eng ...
- Shark简介、部署及编译小结
http://blog.csdn.net/pelick/article/details/11964291 Shark简介 Shark即Hive on Spark,本质上是通过Hive的HQL解析,把H ...
随机推荐
- C语言 域名通配符实现
本例实现通配符 * 的功能,不支持*在字符串的末尾, 仅提供思路,函数仅做简单单元测试. 如有使用,还请自己进行修改 // str1: 待匹配字符串 // str2: 带通配符字串 int wildc ...
- MySQL 中now()时间戳用法
MySQL 中now()时间戳用法 UPDATE news set addtime = unix_timestamp(now()); #结果:1452001082
- Linux 监测内存常用的工具sar free vmstat
Linux 检测内存常用的工具sar free vmstat free 内存统计信息解释 total 内存总量used 内存使用的大小free 内存剩余大小shared 共享内存大小buffers 块 ...
- iOS开发之UITableView的使用
这一篇记录的是iOS开发中UITableView的使用,iOS中的UITableView跟Android中的ListView特别相似,以下用一个Demo来说明: 1.Xcode中新建projectTe ...
- mindmanager2018优化
mindmanager2018优化 CreationTime--2018年6月6日09:35:02 Author:Marydon 1.点击“文件”-“选项”进入配置界面,在“常规”选项中,建议勾选 ...
- ffmpeg command
1. 列出当前系统的设备列表 ffmpeg -list_devices true -f dshow -i dummy 2. 列出设备Integrated Camera的信息 ffmpeg -list_ ...
- Android的学习之路(四)项目中清单文件的学习和android中经常使用的显示单位
1.所谓的清单文件就是项目中的AndroidManifest.xml文件.这个文件但是有大用处的.比方:app的名字,图标.app支持的版本号app的包名等等.以下我就介绍下这个清单文件的各个參数的作 ...
- 峰值因子,峰均比,Reference Level
峰值因子(CREST Factor,CF)与 峰均比( Peak-to-Average Ratio,PAR) 对于一个波形信号,在一段时间内信号幅度峰值比上信号幅度的有效值即为信号的峰值因子,它表征了 ...
- 温故而知新 forEach 无法中断(break)的问题
forEach无法使用break和return来中断,只能使用throw catch来达到中断的效果了. var id = (function(){ // forEach 是无法中断的.除非用这种ha ...
- Spring Boot 概念知识
转 http://rapharino.com/coder/Spring-Boot-Induction/ Spring Boot Induction 发表于 2016-10-29 | 分类于 c ...