使用hadoop mapperreduce来统计大文件的行数-续1

使用前面的脚本与直接使用 wc –l 来计算大文件的行数进行比较,具体结果如下:

文件大小 文件行数 Wc –l 时间() Mapperreduce 时间()
5.8g 2497440 4 171
103g 960000000 280 2172

可以看出,直接使用wc –l 进行统计的效率要比使用hadoop mapperreduce来统计高比较多,但因为使用hadoop mapperreduce统计时要把文件上传到hdfs上,而上传这个过程实际上会花费很长的时间,于是修改了代码去除了上传文件的过程(这两个文件在前面测试时已经上传到hdsf上了),具体脚本如下:

#!/bin/bash
file_name=$1
#删除结果目录
hadoop fs -rm -r /bigdata/output/test/
#统计行数
hadoop jar $HADOOP_HOME/contrib/streaming/hadoop-streaming-1.0.1.jar -files count.sh -input /bigdata/input/test/$file_name -output /bigdata/output/test/ -mapper 'wc -l' -reducer "sh count.sh"


又重新对这两个文件进行了测试,具体结果如下:

文件大小 文件行数 Wc –l 时间() Mapperreduce 时间()
5.8g 2497440 4 171
103g 960000000 280 2172

可以看到随着文件的增大,使用hadoop mapperreduce方式进行统计的效率比直接使用wc –l的方式要高,但前提是这些文件已经上传到hdfs上了。

附测试环境的hadoop配置:

两台namenode,三台datanode

配置都为2个物理cpu24核,内存为64g


你可能感兴趣的:(hadoop,Streaming)