Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Improve performance of UpdateHostDb - parameterize logging - set logging level of information which is later found in the HostDb itself to DEBUG (avoid that frequent log messages flood the log files) - if DNS look-ups are not enabled (no -check* options passed): - do not count and log the hosts skipped not yet eligible for DNS look-ups - do not create DNS resolver threads

Sebastian Nagel13f8504a3860
diff --git a/src/java/org/apache/nutch/hostdb/UpdateHostDbMapper.java b/src/java/org/apache/nutch/hostdb/UpdateHostDbMapper.java
index b8abac340..3f94b5850 100644
--- a/src/java/org/apache/nutch/hostdb/UpdateHostDbMapper.java
+++ b/src/java/org/apache/nutch/hostdb/UpdateHostDbMapper.java
@@ -147,7 +147,7 @@ public class UpdateHostDbMapper
// Filtered out?
if (buffer == null) {
context.getCounter("UpdateHostDb", "filtered_records").increment(1);
- LOG.info("UpdateHostDb: {} crawldatum has been filtered", hostName);
+ LOG.debug("UpdateHostDb: {} crawldatum has been filtered", hostName);
return;
}
@@ -194,17 +194,19 @@ public class UpdateHostDbMapper
// Am i a redirect?
if (reprUrl != null) {
- LOG.info("UpdateHostDb: homepage: " + keyStr + " redirects to: " + args[0]);
+ LOG.debug("UpdateHostDb: homepage: {} redirects to: {}", keyStr,
+ args[0]);
context.write(host, new NutchWritable(hostDatum));
hostDatum.setHomepageUrl(reprUrl);
} else {
- LOG.info("UpdateHostDb: homepage: " + keyStr +
- " redirects to: " + args[0] + " but has been filtered out");
+ LOG.debug(
+ "UpdateHostDb: homepage: {} redirects to: {} but has been filtered out",
+ keyStr, args[0]);
}
} else {
hostDatum.setHomepageUrl(homepage);
context.write(host, new NutchWritable(hostDatum));
- LOG.info("UpdateHostDb: homepage: " + homepage);
+ LOG.debug("UpdateHostDb: homepage: {}", homepage);
}
}
}
@@ -219,7 +221,7 @@ public class UpdateHostDbMapper
// Filtered out?
if (buffer == null) {
context.getCounter("UpdateHostDb", "filtered_records").increment(1);
- LOG.info("UpdateHostDb: {} hostdatum has been filtered", keyStr);
+ LOG.debug("UpdateHostDb: {} hostdatum has been filtered", keyStr);
return;
}
@@ -243,7 +245,7 @@ public class UpdateHostDbMapper
// Filtered out?
if (buffer == null) {
context.getCounter("UpdateHostDb", "filtered_records").increment(1);
- LOG.info("UpdateHostDb: {} score has been filtered", keyStr);
+ LOG.debug("UpdateHostDb: {} score has been filtered", keyStr);
return;
}
diff --git a/src/java/org/apache/nutch/hostdb/UpdateHostDbReducer.java b/src/java/org/apache/nutch/hostdb/UpdateHostDbReducer.java
index d7156edb4..1e41fb6df 100644
--- a/src/java/org/apache/nutch/hostdb/UpdateHostDbReducer.java
+++ b/src/java/org/apache/nutch/hostdb/UpdateHostDbReducer.java
@@ -58,6 +58,7 @@ public class UpdateHostDbReducer
protected static boolean checkFailed = false;
protected static boolean checkNew = false;
protected static boolean checkKnown = false;
+ protected static boolean checkAny = false;
protected static boolean force = false;
protected static long now = new Date().getTime();
protected static String[] numericFields;
@@ -82,6 +83,7 @@ public class UpdateHostDbReducer
checkFailed = conf.getBoolean(UpdateHostDb.HOSTDB_CHECK_FAILED, false);
checkNew = conf.getBoolean(UpdateHostDb.HOSTDB_CHECK_NEW, false);
checkKnown = conf.getBoolean(UpdateHostDb.HOSTDB_CHECK_KNOWN, false);
+ checkAny = checkNew || checkKnown || checkFailed;
force = conf.getBoolean(UpdateHostDb.HOSTDB_FORCE_CHECK, false);
numericFields = conf.getStrings(UpdateHostDb.HOSTDB_NUMERIC_FIELDS);
stringFields = conf.getStrings(UpdateHostDb.HOSTDB_STRING_FIELDS);
@@ -133,12 +135,14 @@ public class UpdateHostDbReducer
}
}
- // Initialize the thread pool with our queue
- executor = new ThreadPoolExecutor(numResolverThreads, numResolverThreads,
- 5, TimeUnit.SECONDS, queue);
+ if (checkAny) {
+ // Initialize the thread pool with our queue
+ executor = new ThreadPoolExecutor(numResolverThreads, numResolverThreads,
+ 5, TimeUnit.SECONDS, queue);
- // Run all threads in the pool
- executor.prestartAllCoreThreads();
+ // Run all threads in the pool
+ executor.prestartAllCoreThreads();
+ }
}
/**
@@ -284,7 +288,7 @@ public class UpdateHostDbReducer
counts.put(numericFields[i], 1l);
}
} catch (Exception e) {
- LOG.error(e.getMessage() + " when processing values for " + key.toString());
+ LOG.error("{} when processing values for {}", e.getMessage(), key);
}
}
}
@@ -386,9 +390,9 @@ public class UpdateHostDbReducer
// Do not progress, the datum will be written in the resolver thread
return;
- } else {
+ } else if (checkAny) {
context.getCounter("UpdateHostDb", "skipped_not_eligible").increment(1);
- LOG.info("UpdateHostDb: {}: skipped_not_eligible", key);
+ LOG.debug("UpdateHostDb: {}: skipped_not_eligible", key);
}
// Run finalize phase for optional custom crawldatum processors
@@ -449,6 +453,10 @@ public class UpdateHostDbReducer
*/
@Override
public void cleanup(Context context) {
+ if (executor == null)
+ // no DNS resolver threads running
+ return;
+
LOG.info("UpdateHostDb: feeder finished, waiting for shutdown");
// If we're here all keys have been fed and we can issue a shut down