gpt4 book ai didi

hadoop - Hadoop 上的 MRJob 和 mapreduce 任务分区

转载 作者:可可西里 更新时间:2023-11-01 14:59:29 26 4
gpt4 key购买 nike

我正在尝试使用 Python MRJob 库执行 mapreduce 作业,但在将其正确分布到我的 Hadoop 集群时遇到了一些问题。我相信我只是缺少 mapreduce 的基本原则。我的集群是一个小型的,一主一从测试集群。基本思想是我只是请求一系列带有参数的网页,对它们进行一些分析并返回网页上的一些属性。

我的 map 函数的输入只是一个带有如下参数的 URL 列表:

http://guelph.backpage.com/automotive/?layout=bla&keyword=towing
http://guelph.backpage.com/whatever/?p=blah
http://semanticreference.com/search.html?go=Search&q=red
http://copiahcounty.wlbt.com/h/events?ename=drupaleventsxmlapi&s=rrr
http://sweetrococo.livejournal.com/34076.html?mode=ffff

这样初始输入的键值对就是key:None, val:URL。

以下是我的 map 功能:

def mapper(self, key, url):
'''Yield domain as the key, and (url, query parameter) tuple as the value'''

parsed_url = urlparse(url)
domain = parsed_url.scheme + "://" + parsed_url.netloc + "/"

if self.myclass.check_if_param(parsed_url):

parsed_url_query = parsed_url.query
url_q_dic = parse_qs(parsed_url_query)

for query_param, query_val in url_q_dic.iteritems():

#yielding a tuple in mrjob will yield a list
yield domain, (url, query_param)

非常简单,我只是检查以确保 URL 有一个参数并生成 URL 的域作为键和一个元组给我 URL 和查询参数作为值,MRJob 友好地将其转换为列表以传递给reducer,如下所示:

def reducer(self, domain, url_query_params):

final_list = []
for url_query_param in url_query_params:

url_to_list_props = url_query_param[0]
param_to_list_props = url_query_param[1]

#set our target that we will request and do some analysis on
self.myclass.set_target(url_to_list_props, param_to_list_props)

#perform a bunch of requests and do analysis on the URL requested
props_list = self.myclass.get_props()

for prop in props_list:

final_list.append(prop)

#index this stuff to a central db
MapReduceIndexer(domain, final_list).add_prop_info()


yield domain, final_list

我的问题是只运行了一个 reducer 任务。我希望 reducer 任务的数量等于映射器发出的唯一键的数量。上面代码的最终结果是我有一个 reducer 在 master 上运行,但是 slave 闲置着什么都不做,这显然是不理想的。我注意到在我的输出中启动了一些 mapper 任务,但始终只有 1 个 reducer 任务。除此之外,任务运行顺利,一切都按预期进行。

我的问题是……我究竟做错了什么?我是在误解 reduce 步骤还是在某处搞砸了我的键值对?为什么没有多个 reducer 在这个作业上运行?

更新:好的,根据给出的答案,我将 mapred.reduce.tasks 增加到更高(这是我现在意识到的默认值 1)。这确实是我得到 1 个 reducer 的原因。我现在看到同时执行 3 个 reduce 任务。我现在在我的奴隶上有一个导入错误需要解决,但至少我有所进展......

最佳答案

reducer 的数量与输入数据的形式完全无关。对于 MRJob,您似乎需要 bootstrap options

关于hadoop - Hadoop 上的 MRJob 和 mapreduce 任务分区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14118908/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com