我正在尝试使用 python 的 MRJob 包编写 MapReduce 作业。该作业处理存储在 S3 中的约 36,000 个文件。每个文件大约 2MB。当我在本地运行作业(将 S3 存储桶下载到我的计算机)时,运行大约需要 1 小时。但是,当我尝试在 EMR 上运行它时,它需要更长的时间(我在 8 小时时停止了它,它在映射器中完成了 10%)。我在下面附上了我的 mapper_init 和 mapper 的代码。有谁知道什么会导致这样的问题?有谁知道如何修理它?我还应该注意,当我将输入限制为 100 个文件的样本时,它工作正常。
def mapper_init(self):
"""
Set class variables that will be useful to our mapper:
filename: the path and filename to the current recipe file
previous_line: The line previously parsed. We need this because the
ingredient name is in the line after the tag
"""
#self.filename = os.environ["map_input_file"] # Not currently used
self.previous_line = "None yet"
# Determining if an item is in a list is O(n) while determining if an
# item is in a set is O(1)
self.stopwords = set(stopwords.words('english'))
self.stopwords = set(self.stopwords_list)
def mapper(self, _, line):
"""
Takes a line from an html file and yields ingredient words from it
Given a line of input from an html file, we check to see if it
contains the identifier that it is an ingredient. Due to the
formatting of our html files from allrecipes.com, the ingredient name
is actually found on the following line. Therefore, we save the
current line so that it can be referenced in the next pass of the
function to determine if we are on an ingredient line.
:param line: a line of text from the html file as a str
:yield: a tuple containing each word in the ingredient as well as a
counter for each word. The counter is not currently being used,
but is left in for future development. e.g. "chicken breast" would
yield "chicken" and "breast"
"""
# TODO is there a better way to get the tag?
if re.search(r'span class="ingredient-name" id="lblIngName"',
self.previous_line):
self.previous_line = line
line = self.process_text(line)
line_list = set(line.split())
for word in line_list:
if word not in self.stopwords:
yield (word, 1)
else:
self.previous_line = line
yield ('', 0)
最佳答案
问题是你有更多的小文件。使用 s3distcp 添加引导步骤以将文件复制到 EMR。在使用 s3distcp 时尝试将小文件聚合到 ~128MB 文件中。
Hadoop 不适用于大量小文件。
由于您是手动将文件下载到计算机并运行,因此运行速度更快。
使用 S3distCP 将文件复制到 EMR 后,使用来自 HDFS 的文件。
关于python - MapReduce 作业(用 python 编写)在 EMR 上运行缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28659865/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我想用ruby编写一个小的命令行实用程序并将其作为gem分发。我知道安装后,Guard、Sass和Thor等某些gem可以从命令行自行运行。为了让gem像二进制文件一样可用,我需要在我的gemspec中指定什么。 最佳答案 Gem::Specification.newdo|s|...s.executable='name_of_executable'...endhttp://docs.rubygems.org/read/chapter/20 关于ruby-在Ruby中编写命令行实用程序
在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
Sinatra新手;我正在运行一些rspec测试,但在日志中收到了一堆不需要的噪音。如何消除日志中过多的噪音?我仔细检查了环境是否设置为:test,这意味着记录器级别应设置为WARN而不是DEBUG。spec_helper:require"./app"require"sinatra"require"rspec"require"rack/test"require"database_cleaner"require"factory_girl"set:environment,:testFactoryGirl.definition_file_paths=%w{./factories./test/
GivenIamadumbprogrammerandIamusingrspecandIamusingsporkandIwanttodebug...mmm...let'ssaaay,aspecforPhone.那么,我应该把“require'ruby-debug'”行放在哪里,以便在phone_spec.rb的特定点停止处理?(我所要求的只是一个大而粗的箭头,即使是一个有挑战性的程序员也能看到:-3)我已经尝试了很多位置,除非我没有正确测试它们,否则会发生一些奇怪的事情:在spec_helper.rb中的以下位置:require'rubygems'require'spork'
我想在Ruby中创建一个用于开发目的的极其简单的Web服务器(不,不想使用现成的解决方案)。代码如下:#!/usr/bin/rubyrequire'socket'server=TCPServer.new('127.0.0.1',8080)whileconnection=server.acceptheaders=[]length=0whileline=connection.getsheaders想法是从命令行运行这个脚本,提供另一个脚本,它将在其标准输入上获取请求,并在其标准输出上返回完整的响应。到目前为止一切顺利,但事实证明这真的很脆弱,因为它在第二个请求上中断并出现错误:/usr/b
是否有可能:before_filter:authenticate_user!||:authenticate_admin! 最佳答案 before_filter:do_authenticationdefdo_authenticationauthenticate_user!||authenticate_admin!end 关于ruby-on-rails-before_filter运行多个方法,我们在StackOverflow上找到一个类似的问题: https://