Apache Nutch is an extensible and scalable web crawler
NUTCH-769 Fetcher to skip queues for URLS getting repeated exceptions.
Andrzej Bialecki837dd3de2ea2
diff --git a/CHANGES.txt b/CHANGES.txtindex 86aed1c3f..36f9cb64c 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,9 @@ Nutch Change LogUnreleased Changes+* NUTCH-769 Fetcher to skip queues for URLS getting repeated exceptions+ (Julien Nioche via ab)+* NUTCH-768 - Upgrade Nutch 1.0 to use Hadoop 0.20.1, also upgrades Xerces toversion 2.9.1. (kubes)diff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex 6f4884de4..fe92fc4ae 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -610,6 +610,16 @@</description></property>+<property>+ <name>fetcher.max.exceptions.per.queue</name>+ <value>-1</value>+ <description>The maximum number of protocol-level exceptions (e.g. timeouts) per+ host (or IP) queue. Once this value is reached, any remaining entries from this+ queue are purged, effectively stopping the fetching from this host/IP. The default+ value of -1 deactivates this limit.+ </description>+</property>+<!-- indexer properties --><property>diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java b/src/java/org/apache/nutch/fetcher/Fetcher.javaindex 38a858664..3bdb2751f 100644--- a/src/java/org/apache/nutch/fetcher/Fetcher.java+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java@@ -208,6 +208,7 @@ public class Fetcher extends Configured implements Tool,List<FetchItem> queue = Collections.synchronizedList(new LinkedList<FetchItem>());Set<FetchItem> inProgress = Collections.synchronizedSet(new HashSet<FetchItem>());AtomicLong nextFetchTime = new AtomicLong();+ AtomicInteger exceptionCounter = new AtomicInteger();long crawlDelay;long minCrawlDelay;int maxThreads;@@ -236,6 +237,10 @@ public class Fetcher extends Configured implements Tool,return inProgress.size();}+ public int incrementExceptionCounter() {+ return exceptionCounter.incrementAndGet();+ }+public void finishFetchItem(FetchItem it, boolean asap) {if (it != null) {inProgress.remove(it);@@ -306,6 +311,7 @@ public class Fetcher extends Configured implements Tool,long crawlDelay;long minCrawlDelay;long timelimit = -1;+ int maxExceptionsPerQueue = -1;Configuration conf;public FetchItemQueues(Configuration conf) {@@ -316,6 +322,7 @@ public class Fetcher extends Configured implements Tool,this.crawlDelay = (long) (conf.getFloat("fetcher.server.delay", 1.0f) * 1000);this.minCrawlDelay = (long) (conf.getFloat("fetcher.server.min.delay", 0.0f) * 1000);this.timelimit = conf.getLong("fetcher.timelimit.mins", -1);+ this.maxExceptionsPerQueue = conf.getInt("fetcher.max.exceptions.per.queue", -1);}public int getTotalSize() {@@ -402,6 +409,36 @@ public class Fetcher extends Configured implements Tool,return count;}+ /**+ * Increment the exception counter of a queue in case of an exception e.g.+ * timeout; when higher than a given threshold simply empty the queue.+ *+ * @param queueid+ * @return number of purged items+ */+ public synchronized int checkExceptionThreshold(String queueid) {+ FetchItemQueue fiq = queues.get(queueid);+ if (fiq == null) {+ return 0;+ }+ if (fiq.getQueueSize() == 0) {+ return 0;+ }+ int excCount = fiq.incrementExceptionCounter();+ if (maxExceptionsPerQueue!= -1 && excCount >= maxExceptionsPerQueue) {+ // too many exceptions for items in this queue - purge it+ int deleted = fiq.emptyQueue();+ LOG.info("* queue: " + queueid + " >> removed " + deleted+ + " URLs from queue because " + excCount + " exceptions occurred");+ for (int i = 0; i < deleted; i++) {+ totalSize.decrementAndGet();+ }+ return deleted;+ }+ return 0;+ }++public synchronized void dump() {for (String id : queues.keySet()) {FetchItemQueue fiq = queues.get(id);@@ -673,6 +710,8 @@ public class Fetcher extends Configured implements Tool,case ProtocolStatus.EXCEPTION:logError(fit.url, status.getMessage());+ int killedURLs = fetchQueues.checkExceptionThreshold(fit.getQueueID());+ reporter.incrCounter("FetcherStatus", "Exceptions", killedURLs);/* FALLTHROUGH */case ProtocolStatus.RETRY: // retrycase ProtocolStatus.BLOCKED: