当前位置:网站首页>MapReduce压缩
MapReduce压缩
2022-04-23 09:50:00 【zhaojiew】
压缩原则
- 运算密集型的 Job,少用压缩
- IO 密集型的 Job,多用压缩
压缩算法对比
压缩格式 | Hadoop 自带 | 算法 | 文件扩展 名 | 是否可切片 | 换成压缩格式后,原来的程序是否需要修改 |
---|---|---|---|---|---|
DEFLATE | 是 | DEFLATE | .deflate | 否 | 和文本处理一样,不需要修改 |
Gzip | 是 | DEFLATE | .gz | 否 | 和文本处理一样,不需要修改 |
bzip2 | 是 | bzip2 | .bz2 | 是 | 和文本处理一样,不需要修改 |
LZO | 否 | LZO | .lzo | 是 | 需要建索引,还需要指定输入格式 |
Snappy | 是 | Snappy | .snappy | 否 | 和文本处理一样,不需要修改 |
压缩性能对比
压缩算法 | 原始文件大小 | 压缩文件大小 | 压缩速度 | 解压速度 |
---|---|---|---|---|
gzip | 8.3GB | 1.8GB | 17.5MB/s | 58MB/s |
bzip2 | 8.3GB | 1.1GB | 2.4MB/s | 9.5MB/s |
LZO | 8.3GB | 2.9GB | 49.3MB/s | 74.6MB/s |
压缩算法选择
需要考虑压缩/解压缩速度、压缩率(压缩后存储大小)、压缩后是否可以支持切片
mapper输入端
无须显示指定使用的编解码方式, Hadoop自动检查文件扩展名,如果扩展名能够匹配,就会用恰当的编解码方式对文件进行压缩和解压。
企业开发:考虑因素。
- 数据量小于块大小,重点考虑压缩和解压缩速度比较快的LZO/Snappy
- 数据量非常大,重点考虑支持切片的Bzip2和LZO
mapper输出端
企业开发中如何选择:为了减少MapTask和ReduceTask之间的网络IO,重点考虑压缩和解压缩快的LZO、 Snappy。
reducer输出端
具体看需求:
-
如果数据永久保存,考虑压缩率比较高的Bzip2和Gzip
-
如果作为下一个MapReduce输入,需要考虑数据量和是否支持切片
压缩参数配置
Hadoop 编码/解码器
压缩格式 | 对应的编码/解码器 |
---|---|
DEFLATE | org.apache.hadoop.io.compress.DefaultCodec |
gzip | org.apache.hadoop.io.compress.GzipCodec |
bzip2 | org.apache.hadoop.io.compress.BZip2Codec |
LZO | com.hadoop.compression.lzo.LzopCodec |
Snappy | org.apache.hadoop.io.compress.SnappyCodec |
参数配置
参数 | 默认值 | 阶段 | 建议 |
---|---|---|---|
io.compression.codecs (在 core-site.xml 中配置) |
无,需要在命令行输入 hadoop checknative 查看 | 输入压缩 | Hadoop 使用文件扩展 名判断是否支持某种 编解码器 |
mapreduce.map.output.compress (在 mapred-site.xml中配置) |
false | mapper 输出 | 这个参数设为 true 启 用压缩 |
mapreduce.map.output.compress.codec (在 mapred site.xml 中配置) |
org.apache.hadoop.io.com press.DefaultCodec | mapper 输出 | 企业多使用 LZO 或 Snappy 编解码器在此 阶段压缩数据 |
mapreduce.output.fileoutpu tformat.compress (在 mapred-site.xml 中配置) |
false | reducer 输出 | 这个参数设为 true 启 用压缩 |
mapreduce.output.fileoutpu tformat.compress.codec (在 mapred-site.xml 中配置) |
org.apache.hadoop.io.com press.DefaultCodec | reducer 输出 | 使用标准工具或者编 解码器,如 gzip 和 bzip2 |
压缩例程
Map 输出端采用压缩
Hadoop 源码支持的压缩格式有: BZip2Codec、 DefaultCodec
在driver中配置,和hdfs客户端的配置方式类似
Configuration conf = new Configuration();
// 开启 map 端输出压缩
conf.setBoolean("mapreduce.map.output.compress", true);
// 设置 map 端输出压缩方式
conf.setClass("mapreduce.map.output.compress.codec", BZip2Codec.class, CompressionCodec.class);
Job job = Job.getInstance(conf);
Reduce 输出端采用压缩
FileInputFormat.setInputPaths(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
// 设置 reduce 端输出压缩开启
FileOutputFormat.setCompressOutput(job, true);
// 设置压缩的方式
FileOutputFormat.setOutputCompressorClass(job, BZip2Codec.class);
//FileOutputFormat.setOutputCompressorClass(job, GzipCodec.class);
// FileOutputFormat.setOutputCompressorClass(job, DefaultCodec.class);
版权声明
本文为[zhaojiew]所创,转载请带上原文链接,感谢
https://blog.csdn.net/sinat_41567654/article/details/124307217
边栏推荐
- [codeforces - 208e] blood cousins
- SAP salv14 background output salv data can directly save files and send emails (with sorting, hyperlink and filtering format)
- SAP CR transmission request sequence and dependency check
- P1446 [hnoi2008] cards (Burnside theorem + DP count)
- Kernel PWN learning (3) -- ret2user & kernel ROP & qwb2018 core
- Creation of raid0 and RAID5 and Simulation of how RAID5 works
- Exclusive thoughts and cases of JS
- Alibaba cloud architects interpret the four mainstream game architectures
- Redis 异常 read error on connection 解决方案
- How to obtain geographical location based on photos and how to prevent photos from leaking geographical location
猜你喜欢
SAP RFC_ CVI_ EI_ INBOUND_ Main BP master data creation example (Demo customer only)
Go language learning notes - language interface | go language from scratch
Introduction to sap pi / PO login and basic functions
Redis 异常 read error on connection 解决方案
DVWA range practice
PHP notes (I): development environment configuration
工业元宇宙平台规划与建设
Amazon cloud technology entry Resource Center, easy access to the cloud from 0 to 1
Interviewer: let's talk about some commonly used PHP functions. Fortunately, I saw this article before the interview
Go language learning notes - structure | go language from scratch
随机推荐
重载、重写、隐藏的对比
Pyqt5与通信
Learn FPGA (from Verilog to HLS)
[COCI] Vje š TICA (subset DP)
kernel-pwn学习(4)--Double Fetch&&0CTF2018-baby
ABAP implementation publishes restful services for external invocation example
自定义登录失败处理
構建元宇宙時代敏捷制造的九種能力
理解作用域
Comparison of overloading, rewriting and hiding
JS DOM learn three ways to create elements
[geek challenge 2019] havefun1
Odoo 服务器搭建备忘
Amazon cloud technology entry Resource Center, easy access to the cloud from 0 to 1
中控学习型红外遥控模块支持网络和串口控制
ES-aggregation聚合分析
实践六 Windows操作系统安全攻防
Mobius inversion
Classic routine: DP problem of a kind of string counting
论文阅读《Integrity Monitoring Techniques for Vision Navigation Systems》