Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-3067 Improve performance of FetchItemQueues if error state is preserved

Sebastian Nagelbd2fce6ff391
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index b1c2b1556..45e933b4d 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -1173,6 +1173,17 @@
</description>
</property>
+<property>
+ <name>fetcher.exceptions.per.queue.clear.after</name>
+ <value>1800</value>
+ <description>Time in seconds after which exception counters in
+ queues can be cleared. This happens only if no items are queued in
+ this queue and the configured time span has elapsed in addition to
+ the crawl delay including the exponential backoff time, see
+ fetcher.exceptions.per.queue.delay.
+ </description>
+</property>
+
<property>
<name>fetcher.throughput.threshold.pages</name>
<value>-1</value>
diff --git a/src/java/org/apache/nutch/fetcher/FetchItemQueues.java b/src/java/org/apache/nutch/fetcher/FetchItemQueues.java
index 5138c8c0f..db2dece17 100644
--- a/src/java/org/apache/nutch/fetcher/FetchItemQueues.java
+++ b/src/java/org/apache/nutch/fetcher/FetchItemQueues.java
@@ -57,6 +57,7 @@ public class FetchItemQueues {
long timelimit = -1;
int maxExceptionsPerQueue = -1;
long exceptionsPerQueueDelay = -1;
+ long exceptionsPerQueueClearAfter = 1800 * 1000L;
boolean feederAlive = true;
Configuration conf;
@@ -88,6 +89,8 @@ public class FetchItemQueues {
"fetcher.max.exceptions.per.queue", -1);
this.exceptionsPerQueueDelay = (long) (conf
.getFloat("fetcher.exceptions.per.queue.delay", .0f) * 1000);
+ this.exceptionsPerQueueClearAfter = (long) (conf
+ .getFloat("fetcher.exceptions.per.queue.clear.after", 1800.0f) * 1000);
int dedupRedirMaxTime = conf.getInt("fetcher.redirect.dedupcache.seconds",
-1);
@@ -179,25 +182,41 @@ public class FetchItemQueues {
it = queues.entrySet().iterator();
}
+ boolean keepExceptionState = (maxExceptionsPerQueue > -1
+ || exceptionsPerQueueDelay > 0);
+
while (it.hasNext()) {
FetchItemQueue fiq = it.next().getValue();
// reap empty queues which do not hold state required to ensure politeness
if (fiq.getQueueSize() == 0 && fiq.getInProgressSize() == 0) {
if (!feederAlive) {
- // no more fetch items added
+ // no more fetch items added: queue can be safely removed
it.remove();
- } else if ((maxExceptionsPerQueue > -1 || exceptionsPerQueueDelay > 0)
- && fiq.exceptionCounter.get() > 0) {
- // keep queue because the exceptions counter is bound to it
- // and is required to skip or delay items on this queue
- } else if (fiq.nextFetchTime.get() > System.currentTimeMillis()) {
+ continue;
+ }
+
+ if (fiq.nextFetchTime.get() > System.currentTimeMillis()) {
// keep queue to have it blocked in case new fetch items of this queue
// are added by the QueueFeeder
- } else {
- // empty queue without state
- it.remove();
+ continue;
}
+
+ if (keepExceptionState && fiq.exceptionCounter.get() > 0) {
+ if ((fiq.nextFetchTime.get() + exceptionsPerQueueClearAfter) < System
+ .currentTimeMillis()) {
+ /*
+ * the time configured by fetcher.exceptions.per.queue.clear.after
+ * has passed in addition to the delay defined by the exponential
+ * backoff
+ */
+ it.remove();
+ }
+ continue;
+ }
+
+ // queue is empty and does not hold state required to ensure politeness
+ it.remove();
continue;
}