Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-1182 fetcher to log hung threads

Sebastian Nagelf0c0031d30ce
diff --git a/CHANGES.txt b/CHANGES.txt
index 061ab48ee..7103d6ada 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,8 @@ Nutch Change Log
Nutch Current Development
+* NUTCH-1182 fetcher to log hung threads (snagel)
+
* NUTCH-1759 Upgrade to Crawler Commons 0.4 (jnioche)
* NUTCH-1764 readdb to show command-line help if no action (-stats, -dump, etc.) given (Diaa via snagel)
diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java b/src/java/org/apache/nutch/fetcher/Fetcher.java
index b88c11c10..067bd86ff 100644
--- a/src/java/org/apache/nutch/fetcher/Fetcher.java
+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java
@@ -133,6 +133,8 @@ public class Fetcher extends Configured implements Tool,
FetchItemQueues fetchQueues;
QueueFeeder feeder;
+ LinkedList<FetcherThread> fetcherThreads = new LinkedList<FetcherThread>();
+
/**
* This class described the item to be fetched.
*/
@@ -1178,7 +1180,9 @@ public class Fetcher extends Configured implements Tool,
getConf().setBoolean(Protocol.CHECK_ROBOTS, false);
for (int i = 0; i < threadCount; i++) { // spawn threads
- new FetcherThread(getConf()).start();
+ FetcherThread t = new FetcherThread(getConf());
+ fetcherThreads.add(t);
+ t.start();
}
// select a timeout that avoids a task timeout
@@ -1254,6 +1258,21 @@ public class Fetcher extends Configured implements Tool,
if ((System.currentTimeMillis() - lastRequestStart.get()) > timeout) {
if (LOG.isWarnEnabled()) {
LOG.warn("Aborting with "+activeThreads+" hung threads.");
+ for (int i = 0; i < fetcherThreads.size(); i++) {
+ FetcherThread thread = fetcherThreads.get(i);
+ if (thread.isAlive()) {
+ LOG.warn("Thread #" + i + " hung while processing " + thread.reprUrl);
+ if (LOG.isDebugEnabled()) {
+ StackTraceElement[] stack = thread.getStackTrace();
+ StringBuilder sb = new StringBuilder();
+ sb.append("Stack of thread #").append(i).append(":\n");
+ for (StackTraceElement s : stack) {
+ sb.append(s.toString()).append('\n');
+ }
+ LOG.debug(sb.toString());
+ }
+ }
+ }
}
return;
}