Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Optionally skip pages with abnormally large Crawl-Delay values. Original patch submitted by Dennis Kubes.

Andrzej Bialecki32bf3a0edfaa
diff --git a/CHANGES.txt b/CHANGES.txt
index 10907949d..960f8f873 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -10,6 +10,9 @@ Unreleased changes (0.9-dev)
3. NUTCH-260 - Update hadoop version to 0.5.0 (Renaud Richardet,
siren)
+ 4. Optionally skip pages with abnormally large values of Crawl-Delay
+ (Dennis Kubes via ab)
+
Release 0.8 - 2006-07-25
0. Totally new architecture, based on hadoop
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index 501639467..86a8b2259 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -379,6 +379,18 @@
successive requests to the same server.</description>
</property>
+<property>
+ <name>fetcher.max.crawl.delay</name>
+ <value>30</value>
+ <description>
+ If the Crawl-Delay in robots.txt is set to greater than this value (in
+ seconds) then the fetcher will skip this page, generating an error report.
+ If set to -1 the fetcher will never skip such pages and will wait the
+ amount of time retrieved from robots.txt Crawl-Delay, however long that
+ might be.
+ </description>
+</property>
+
<property>
<name>fetcher.threads.fetch</name>
<value>10</value>
diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java b/src/java/org/apache/nutch/fetcher/Fetcher.java
index 63e0d4345..5558b4952 100644
--- a/src/java/org/apache/nutch/fetcher/Fetcher.java
+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java
@@ -199,6 +199,7 @@ public class Fetcher extends Configured implements MapRunnable {
case ProtocolStatus.NOTFOUND:
case ProtocolStatus.ACCESS_DENIED:
case ProtocolStatus.ROBOTS_DENIED:
+ case ProtocolStatus.WOULDBLOCK:
case ProtocolStatus.NOTMODIFIED:
output(url, datum, null, CrawlDatum.STATUS_FETCH_GONE);
break;
diff --git a/src/java/org/apache/nutch/protocol/ProtocolStatus.java b/src/java/org/apache/nutch/protocol/ProtocolStatus.java
index 7a0697bb7..30184ca34 100644
--- a/src/java/org/apache/nutch/protocol/ProtocolStatus.java
+++ b/src/java/org/apache/nutch/protocol/ProtocolStatus.java
@@ -25,7 +25,7 @@ import org.apache.hadoop.io.VersionedWritable;
import org.apache.hadoop.io.WritableUtils;
/**
- * @author Andrzej Bialecki &lt;[email protected]&gt;
+ * @author Andrzej Bialecki
*/
public class ProtocolStatus extends VersionedWritable {
@@ -55,11 +55,15 @@ public class ProtocolStatus extends VersionedWritable {
/** Access denied by robots.txt rules. */
public static final int ROBOTS_DENIED = 18;
/** Too many redirects. */
- public static final int REDIR_EXCEEDED = 19;
+ public static final int REDIR_EXCEEDED = 19;
/** Not fetching. */
public static final int NOTFETCHING = 20;
/** Unchanged since the last fetch. */
public static final int NOTMODIFIED = 21;
+ /** Request was refused by protocol plugins, because it would block.
+ * The expected number of milliseconds to wait before retry may be provided
+ * in args. */
+ public static final int WOULDBLOCK = 22;
// Useful static instances for status codes that don't usually require any
// additional arguments.
@@ -72,6 +76,7 @@ public class ProtocolStatus extends VersionedWritable {
public static final ProtocolStatus STATUS_REDIR_EXCEEDED = new ProtocolStatus(REDIR_EXCEEDED);
public static final ProtocolStatus STATUS_NOTFETCHING = new ProtocolStatus(NOTFETCHING);
public static final ProtocolStatus STATUS_NOTMODIFIED = new ProtocolStatus(NOTMODIFIED);
+ public static final ProtocolStatus STATUS_WOULDBLOCK = new ProtocolStatus(WOULDBLOCK);
private int code;
private long lastModified;
@@ -93,6 +98,7 @@ public class ProtocolStatus extends VersionedWritable {
codeToName.put(new Integer(REDIR_EXCEEDED), "redir_exceeded");
codeToName.put(new Integer(NOTFETCHING), "notfetching");
codeToName.put(new Integer(NOTMODIFIED), "notmodified");
+ codeToName.put(new Integer(WOULDBLOCK), "wouldblock");
}
public ProtocolStatus() {
@@ -183,6 +189,7 @@ public class ProtocolStatus extends VersionedWritable {
code == REDIR_EXCEEDED ||
code == RETRY ||
code == TEMP_MOVED ||
+ code == WOULDBLOCK ||
code == PROTO_NOT_FOUND;
}
diff --git a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java
index 600d79a6e..0f8fb4c79 100644
--- a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java
+++ b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java
@@ -125,6 +125,9 @@ public abstract class HttpBase implements Protocol {
/** Do we use HTTP/1.1? */
protected boolean useHttp11 = false;
+
+ /** Skip page if Crawl-Delay longer than this value. */
+ protected long maxCrawlDelay = -1L;
/** Creates a new instance of HttpBase */
public HttpBase() {
@@ -152,6 +155,7 @@ public abstract class HttpBase implements Protocol {
this.userAgent = getAgentString(conf.get("http.agent.name"), conf.get("http.agent.version"), conf
.get("http.agent.description"), conf.get("http.agent.url"), conf.get("http.agent.email"));
this.serverDelay = (long) (conf.getFloat("fetcher.server.delay", 1.0f) * 1000);
+ this.maxCrawlDelay = (long)(conf.getInt("fetcher.max.crawl.delay", -1) * 1000);
// backward-compatible default setting
this.byIP = conf.getBoolean("fetcher.threads.per.host.by.ip", true);
this.useHttp11 = conf.getBoolean("http.http11", false);
@@ -185,6 +189,14 @@ public abstract class HttpBase implements Protocol {
long crawlDelay = robots.getCrawlDelay(this, u);
long delay = crawlDelay > 0 ? crawlDelay : serverDelay;
+ if (maxCrawlDelay >= 0 && delay > maxCrawlDelay) {
+ // skip this page, otherwise the thread would block for too long.
+ LOGGER.info("Skipping: " + u + " exceeds fetcher.max.crawl.delay, max="
+ + (maxCrawlDelay / 1000) + ", Crawl-Delay=" + (delay / 1000));
+ Content c = new Content(u.toString(), u.toString(), EMPTY_CONTENT,
+ null, null, this.conf);
+ return new ProtocolOutput(c, ProtocolStatus.STATUS_WOULDBLOCK);
+ }
String host = blockAddr(u, delay);
Response response;
try {