hadoop_MR优化:压缩
压缩文件的好处
1.减小文件存储所占空间
2.加快文件传输效率,从而提高系统的处理速度
3.降低IO读写的次数
压缩文件的坏处
1.使用数据时先对文件解压,加重CPU负荷,压缩越狠,解压时间越长
Snappy<LZ4<LZO<GZIP<BZIP2
//开启map压缩********************************************************
configuration.setBoolean(Job.MAP_OUTPUT_COMPRESS,true);
//指定压缩类型
configuration.setClass(Job.MAP_OUTPUT_COMPRESS_CODEC,
GzipCodec.class, CompressionCodec.class);
//开启reduce端输出为压缩文件**************************************
FileOutputFormat.setCompressOutput(job, true);
//指定压缩类型
FileOutputFormat.setOutputCompressorClass(job, GzipCodec.class);