【问题标题】:File not cacheing on AWS Elastic Map Reduce文件未在 AWS Elastic Mapreduce 上缓存
【发布时间】:2014-08-18 11:15:14
【问题描述】:

我在 AWS Elastic MapReduce 上运行以下 MapReduce:

./elastic-mapreduce --create --stream --name CLI_FLOW_LARGE --mapper s3://classify.mysite.com/mapper.py --reducer s3://classify.mysite.com/reducer.py --input s3n://classify.mysite.com/s3_list.txt --output s3://classify.mysite.com/dat_output4/ --cache s3n://classify.mysite.com/classifier.py#classifier.py --cache-archive s3n://classify.mysite.com/policies.tar.gz#policies --bootstrap-action s3://classify.mysite.com/bootstrap.sh --enable-debugging --master-instance-type m1.large --slave-instance-type m1.large --instance-type m1.large

由于某种原因,cacheFile classifier.py 似乎没有被缓存。当reducer.py 尝试导入它时出现此错误:

  File "/mnt/var/lib/hadoop/mapred/taskTracker/hadoop/jobcache/job_201204290242_0001/attempt_201204290242_0001_r_000000_0/work/./reducer.py", line 12, in <module>
    from classifier import text_from_html, train_classifiers
ImportError: No module named classifier

classifier.py 绝对存在于s3n://classify.mysite.com/classifier.py。值得一提的是,政策存档似乎加载得很好。

【问题讨论】:

  • 我认为它可能被缓存了,但是你的 python 路径有问题。 reducer.py 和 classifier.py 是否被缓存到同一个目录中?如果没有,您将不得不摆弄sys.path
  • 我以为缓存的东西在工作目录中?
  • 其实你是对的!发布我现在找到的解决方案..

标签: python hadoop amazon-web-services elastic-map-reduce


【解决方案1】:

我不知道如何在 EC2 中解决这个问题,但我之前在传统的 Hadoop 部署中使用 Python 看到过这个问题。希望课程能顺利完成。

我们需要做的是将reduce.py所在的目录添加到python路径中,因为大概classifier.py也在那里。不管什么原因,这个地方不在python路径中,所以找不到classifier。

import sys
import os.path

# add the directory where reducer.py is to the python path
sys.path.append(os.path.dirname(__file__))
# __file__ is the location of reduce.py, along with "reduce.py"
# dirname strips the file name and only gives the directory
# sys.path is the python path where it looks for modules

from classifier import text_from_html, train_classifiers

您的代码可能在本地运行的原因是您运行它的当前工作目录。就当前工作目录而言,Hadoop 可能不会从您所在的同一位置运行它。

【讨论】:

    【解决方案2】:

    orangeoctopus 在他的评论中值得称赞。必须附加工作目录系统路径:

    sys.path.append('./')

    另外,我建议任何与我有类似问题的人阅读这篇关于在 AWS 上使用分布式缓存的精彩文章: https://forums.aws.amazon.com/message.jspa?messageID=152538

    【讨论】:

    • 这很奇怪。我认为python已经在路径中有.。我实际上有一个答案暗示了这一点,但证实. 在路径中......所以我将它切换为评论:)。
    • 我取消删除它以防您想查看详细信息。
    猜你喜欢
    • 2016-04-03
    • 2011-08-03
    • 1970-01-01
    • 2012-07-05
    • 2015-01-15
    • 1970-01-01
    • 2017-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多