使用 Nutch 内容限制的建议

Advice in Using Nutch Content Limit

我正在使用 Nutch 2.1 来抓取整个域(例如 company.com)。我曾经 运行 遇到过这个问题,由于 Apache Nutch 中设置的内容限制,我没有得到我想要抓取的所有链接。通常,我查看内容时,只有页面的上半部分存储在数据库中,因此下半部分的链接没有被提取。

为了解决这个问题,我更改了 nutch-site.xml 以便内容限制如下所示:

<property>
    <name>http.content.limit</name>
    <value>-1</value>
    <description>The length limit for downloaded content using the http
    protocol, in bytes. If this value is nonnegative (>=0), content longer
    than it will be truncated; otherwise, no truncation at all. Do not
    confuse this setting with the file.content.limit setting.
    </description>
</property>

这样做解决了问题,但在某些时候,我遇到了 OutOfMemory 错误,此输出 在解析时证明了这一点:

ParserJob: starting
ParserJob: resuming:    false
ParserJob: forced reparse:  false
ParserJob: parsing all
Exception in thread "main" java.lang.RuntimeException: job failed: name=parse, jobid=job_local_0001
at org.apache.nutch.util.NutchJob.waitForCompletion(NutchJob.java:54)
at org.apache.nutch.parse.ParserJob.run(ParserJob.java:251)
at org.apache.nutch.parse.ParserJob.parse(ParserJob.java:259)
at org.apache.nutch.parse.ParserJob.run(ParserJob.java:302)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65)
at org.apache.nutch.parse.ParserJob.main(ParserJob.java:306)

这是我的hadoop.log(靠近错误的部分):

    2016-01-22 02:02:35,898 INFO  crawl.SignatureFactory - Using Signature impl: org.apache.nutch.crawl.MD5Signature
2016-01-22 02:02:37,255 WARN  util.NativeCodeLoader - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
2016-01-22 02:02:39,130 INFO  mapreduce.GoraRecordReader - gora.buffer.read.limit = 10000
2016-01-22 02:02:39,255 INFO  mapreduce.GoraRecordWriter - gora.buffer.write.limit = 10000
2016-01-22 02:02:39,322 INFO  crawl.SignatureFactory - Using Signature impl: org.apache.nutch.crawl.MD5Signature
2016-01-22 02:02:53,018 WARN  mapred.FileOutputCommitter - Output path is null in cleanup
2016-01-22 02:02:53,031 WARN  mapred.LocalJobRunner - job_local_0001
java.lang.OutOfMemoryError: Java heap space
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3051)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2991)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3532)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943)
    at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1441)
    at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:2936)
    at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:477)
    at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:2631)
    at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1800)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2221)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2293)
    at org.apache.gora.sql.store.SqlStore.execute(SqlStore.java:423)
    at org.apache.gora.query.impl.QueryBase.execute(QueryBase.java:71)
    at org.apache.gora.mapreduce.GoraRecordReader.executeQuery(GoraRecordReader.java:66)
    at org.apache.gora.mapreduce.GoraRecordReader.nextKeyValue(GoraRecordReader.java:102)
    at org.apache.hadoop.mapred.MapTask$NewTrackingRecordReader.nextKeyValue(MapTask.java:532)
    at org.apache.hadoop.mapreduce.MapContext.nextKeyValue(MapContext.java:67)
    at org.apache.hadoop.map

我只是在将内容限制设置为-1 时才遇到这个问题。但是,如果我不这样做,我可能无法获得我想要抓取的所有链接。关于如何使用内容限制的任何建议?这样做真的不可取吗?如果是这样,我可以使用哪些可能的替代方案?谢谢!

问题在于您将抓取深度设置为无限制 (-1)。当您的爬虫系统命中 https://en.wikipedia.org, https://wikipedia.org and https://en.wikibooks.org 等繁重的 URL 时,您的系统可能会在爬虫过程中 运行 内存不足。您应该通过设置 NUTCH_HEAPSIZE 环境变量值 e.g., export NUTCH_HEAPSIZE=4000 来增加 Nuch 的内存(请参阅 Nutch 脚本中的详细信息)。请注意,此值相当于 Hadoop 的 HADOOP_HEAPSIZE。如果还是不行,你应该增加系统的物理内存^ ^

希望这对您有所帮助,

乐国岛