【发布时间】:2019-08-22 11:42:48
【问题描述】:
我正在使用 Apache Nutch 以编程方式在 EMR 集群中以 6 个周期抓取大约 7000 个 URL(在抓取过程中几乎没有自定义 map-reduce 作业)。 版本是:nutch=v1.15 hadoop=2.7.3 我在具有 20 个 EC2 m4.large 现场实例的 Amazon EMR 集群上运行它。爬取的代码是:
public crawl(Folder seeds, Folder output)
throws IOException, InterruptedException {
final Folder crawldb = output.folder("crawldb");
try {
new Injector(this.conf).inject(
crawldb.path(), seeds.path(),
true, true
);
} catch (final ClassNotFoundException err) {
throw new IOException("Failed to inject URLs", err);
}
final Folder segments = output.mkdir("segments");
// cycles = 6 in my case
for (int idx = 0; idx < cycles; ++idx) {
this.cycle(crawldb, segments);
}
}
private void cycle(final Folder crawldb, final Folder segments)
throws IOException, InterruptedException {
try {
Logger.info(this, "Generating...");
// configured as 1_000_000 in EMR cluster
final int topn = this.conf.getInt("yc.gen.topn", 1000);
// configured as 40 (2 x slave_nodes) in EMR cluster
final int nfetch = this.conf.getInt("yc.gen.nfetch", 1);
new Generator(this.conf).generate(
crawldb.path(),
segments.path(),
nfetch, topn, System.currentTimeMillis()
);
// the latest segment
final Optional<Folder> next = Batch.nextSegment(segments);
if (next.isPresent()) {
final Path sgmt = next.get().path();
Logger.info(this, "Fetching %s...", sgmt);
new Fetcher(this.conf).fetch(
// @checkstyle MagicNumber (1 line)
sgmt, 10
);
Logger.info(this, "Parsing %s...", sgmt);
new ParseSegment(this.conf).parse(sgmt);
}
new CrawlDb(this.conf).update(
crawldb.path(),
// all segments paths
segments.subfolders().stream()
.toArray(Path[]::new),
true, true
);
} catch (final ClassNotFoundException err) {
throw new IOException(
"Failed to generate/fetch/parse segment", err
);
}
}
当我使用 7000 个种子 URL 和 6 个运行周期运行它时,Nutch 在FetchData 作业上变得非常慢:它运行了大约 3 个小时,而且它似乎在等待最后一个映射器完成大约 2.5 个小时(见附件截图)。这项工作可能有什么问题,以及如何加快 FetchData 阶段,也许我可以将其配置为跳过慢速获取器(如果我错过了几个 URL,这不是一个大问题)。
【问题讨论】:
标签: hadoop mapreduce web-crawler amazon-emr nutch