我安装了cloudera管理器(CDH 5)并创建了自己的冲突器。一切都很好,但当我运行任务时,它运行得很慢(18分钟)。但是ruby的脚本运行了大约5秒。
我的任务包括:
#mapper.py
import sys
def do_map(doc):
for word in doc.split():
yield word.lower(), 1
for line in sys.stdin:
for key, value in do_map(line):
print(key + "t" + str(value))
和
#reducer.py
import sys
def do_reduce(word, values):
return word, sum(values)
prev_key = None
values = []
for line in sys.stdin:
key, value = line.split("t")
if key != prev_key and prev_key is not None:
result_key, result_value = do_reduce(prev_key, values)
print(result_key + "t" + str(result_value))
values = []
prev_key = key
values.append(int(value))
if prev_key is not None:
result_key, result_value = do_reduce(prev_key, values)
print(result_key + "t" + str(result_value))
我运行我的任务这是命令:
yarn jar hadoop-streaming.jar -input lenta_articles -output lenta_wordcount -file mapper.py -file reducer.py -mapper "python mapper.py" -reducer "python reducer.py"
运行命令日志:
15/11/17 10:14:27 WARN streaming.StreamJob: -file option is deprecated, please use generic option -files instead.
packageJobJar: [mapper.py, reducer.py] [/opt/cloudera/parcels/CDH-5.4.8-1.cdh5.4.8.p0.4/jars/hadoop-streaming-2.6.0-cdh5.4.8.jar] /tmp/streamjob8334226755199432389.jar tmpDir=null
15/11/17 10:14:29 INFO client.RMProxy: Connecting to ResourceManager at manager/10.128.181.136:8032
15/11/17 10:14:29 INFO client.RMProxy: Connecting to ResourceManager at manager/10.128.181.136:8032
15/11/17 10:14:31 INFO mapred.FileInputFormat: Total input paths to process : 909
15/11/17 10:14:32 INFO mapreduce.JobSubmitter: number of splits:909
15/11/17 10:14:32 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1447762910705_0010
15/11/17 10:14:32 INFO impl.YarnClientImpl: Submitted application application_1447762910705_0010
15/11/17 10:14:32 INFO mapreduce.Job: The url to track the job: http://manager:8088/proxy/application_1447762910705_0010/
15/11/17 10:14:32 INFO mapreduce.Job: Running job: job_1447762910705_0010
15/11/17 10:14:49 INFO mapreduce.Job: Job job_1447762910705_0010 running in uber mode : false
15/11/17 10:14:49 INFO mapreduce.Job: map 0% reduce 0%
15/11/17 10:16:04 INFO mapreduce.Job: map 1% reduce 0%
lenta_wordcount文件夹的大小为2.5 mb。它由909个文件组成。А平均文件大小3КБ。
如果你需要学习或执行任何命令,请提问
我做错了什么?
Hadoop在处理大量小文件方面效率不高,但在处理少量大文件方面效率很高。
既然您已经使用了Cloudera,请参阅Cloudera文章中引用的使用Hadoop的大量小文件来提高性能的替代方案
处理缓慢的主要原因
读取小文件通常会导致大量查找和从数据节点跳到数据节点以检索每个小文件,所有这些都是一种低效的数据访问模式
如果你有更多数量的文件,你需要更多数量的映射器来读取&过程数据。成千上万的映射器处理小文件&通过网络将输出传递给Reducer将降低性能。
使用LZO压缩将输入作为顺序文件传递是处理大量小文件的最佳选择之一。看看SE问题1和其他可选
还有一些其他的选择(有些与phtyon无关),但你应该看看这篇文章
Change the ingestion process/interval
Batch file consolidation
Sequence files
HBase
S3DistCp (If using Amazon EMR)
Using a CombineFileInputFormat
Hive configuration settings
Using Hadoop’s append capabilities