基本的hadoop mapreduce工作正在启动,但尚未完成

时间:2015-07-25 16:25:20

标签: python macos hadoop mapreduce

我正在考虑Hadoop,但是当我尝试提交mapreduce作业时,Hadoop似乎开始了,但随后没有任何进展或其他活动的迹象。应用程序状态页面说它已经提交并显示作业,但没有任何反应,我很好奇在哪里寻找解决这个问题。

我正在使用Hadoop 2.7.1版,使用Homebrew和Java 1.8.0_45安装在OS X 10.10.4中。我按照以下说明对其进行了配置:https://datarecipe.wordpress.com/2015/06/05/setup-hadoop-2-6-on-mac-osx-10-9/

数据是一个简单的文本文件,名为“purchases.txt”,包含此文件(制表符分隔):

2013-03-29  2:30    miami   cup 2.43    visa
2013-04-23  1:34    miami   cup 2.43    visa
2013-04-23  10:15   LA  spoon   1.32    visa
2013-04-28  6:34    LA  bottle  3.56    cash
2013-05-23  1:43    miami   glass   3.21    visa

我已将其上传到hadoop(已创建数据文件夹):

hadoop fs -put purchases.txt /data/

然后我在python中设置了以下映射器(根据在线教程)并将其称为“mapper.py”:

import sys

def mapper():
    for line in sys.stdin:
        tempdata = line.strip().split("\n")
        for l in tempdata:
            if (len(l.split("\t")) == 6):
                date, time, store, item, cost, payment = l.split("\t")
                print("{0}\t{1}".format(store,cost))

def main():
    mapper()

if __name__=="__main__":
    main()

我为reducer代码做了同样的事,并称之为“reducer.py”:

import sys

def reducer():
    salesTotal = 0
    oldKey = None
    for line in sys.stdin:
        data = line.strip().split("\t")
        if len(data)!=2:
            continue
        thisKey, thisSale = data
        if oldKey and oldKey != thisKey:
            print("{0}\t{1}".format(oldKey,salesTotal))
            salesTotal=0
        oldKey = thisKey
        salesTotal+=float(thisSale)
    if oldKey != None:
        print("{0}\t{1}".format(oldKey,salesTotal))

def main():
    reducer()

if __name__=="__main__":
    main()

在命令行上测试这些代码:

Tophers-Retina-MBP:Hadoop tkessler$ cat purchases.txt | ./mapper.py | sort | ./reducer.py 
LA  4.88
miami   5.640000000000001

然而,当我运行流程来在Hadoop中运行它时,它只是停在这里:

Tophers-Retina-MBP:lib tkessler$ hadoop jar ./hadoop-streaming-2.7.1.jar -mapper ~/PycharmProjects/Hadoop/mapper.py -reducer ~/PycharmProjects/Hadoop/reducer.py -file ~/PycharmProjects/Hadoop/mapper.py -input /data -output /project1out
packageJobJar: [/Users/tkessler/PycharmProjects/Hadoop/mapper.py, /var/folders/f_/3zvmc1g95lqgt1cp2dtnrtqw0000gp/T/hadoop-unjar2355518779286421017/] [] /var/folders/f_/3zvmc1g95lqgt1cp2dtnrtqw0000gp/T/streamjob8766144507660069606.jar tmpDir=null

似乎启动工作就好了,接受mapper和reducer,并运行“mapred job -list all”显示作业都在运行,但它永远不会完成,状态只是列为“未知” 。如果有人有任何见解,我不确定它是否存在hadoop配置问题或其他问题。

增加:

当我运行以下示例命令时,进度似乎停在以下行:

Tophers-Retina-MBP:~ tkessler$ hadoop jar /usr/local/Cellar/hadoop/2.7.1/libexec/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.1.jar pi 4 1000
Number of Maps  = 4
Samples per Map = 1000
Wrote input for Map #0
Wrote input for Map #1
Wrote input for Map #2
Wrote input for Map #3
Starting Job

1 个答案:

答案 0 :(得分:0)

通过关闭namenode和datanode来清除Hadoop,然后使用brew uninstall hadoop将其卸载,然后按照此页面上的说明进行设置:http://amodernstory.com/2014/09/23/installing-hadoop-on-mac-osx-yosemite/

现在似乎工作得很好,所以也许只是一个轻微的配置更改(可能是临时文件位置),但它现在处理映射器和reducer非常好。