Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-2950 Improve performance of UpdateHostDb - avoid needless conversion between host name and URL and back if -filter and -normalize are off - URLUtil: use ROOT locale when converting host name / URL to lowercase

Sebastian Nagel70b2d5e556d9
diff --git a/src/java/org/apache/nutch/hostdb/UpdateHostDbMapper.java b/src/java/org/apache/nutch/hostdb/UpdateHostDbMapper.java
index f64285009..ecd225637 100644
--- a/src/java/org/apache/nutch/hostdb/UpdateHostDbMapper.java
+++ b/src/java/org/apache/nutch/hostdb/UpdateHostDbMapper.java
@@ -72,25 +72,40 @@ public class UpdateHostDbMapper
}
/**
- * Filters and or normalizes the input hostname
+ * Filters and or normalizes the input hostname by applying the configured URL
+ * filters and normalizers the URL "http://hostname/".
*
- * @param url the input hostname
- * @return the processed hostname, or null if there was a fatal error
+ * @param hostName
+ * the input hostname
+ * @return the normalized hostname, or null if the URL is excluded by URL
+ * filters or failed to be normalized converted
*/
- protected String filterNormalize(String url) {
- url = "http://" + url + "/";
+ protected String filterNormalize(String hostName) {
+
+ if (!filter && !normalize) {
+ // nothing to do
+ return hostName;
+ }
+
+ String url = "http://" + hostName + "/";
+ String normalizedUrl = url;
try {
if (normalize)
- url = normalizers.normalize(url, URLNormalizers.SCOPE_DEFAULT);
+ normalizedUrl = normalizers.normalize(url, URLNormalizers.SCOPE_DEFAULT);
if (filter)
- url = filters.filter(url);
- if (url == null)
+ normalizedUrl = filters.filter(normalizedUrl);
+ if (normalizedUrl == null)
return null;
} catch (Exception e) {
return null;
}
+ if (normalizedUrl.equals(url)) {
+ // URL did not change during normalization
+ return hostName;
+ }
+
// Turn back to host
return URLUtil.getHost(url);
}
@@ -114,13 +129,15 @@ public class UpdateHostDbMapper
// Check if we process records from the CrawlDB
if (key instanceof Text && value instanceof CrawlDatum) {
+ String hostName = URLUtil.getHost(keyStr);
+
// Get the normalized and filtered host of this URL
- buffer = filterNormalize(URLUtil.getHost(keyStr));
+ buffer = filterNormalize(hostName);
// Filtered out?
if (buffer == null) {
context.getCounter("UpdateHostDb", "filtered_records").increment(1);
- LOG.info("UpdateHostDb: " + URLUtil.getHost(keyStr) + " crawldatum has been filtered");
+ LOG.info("UpdateHostDb: {} crawldatum has been filtered", hostName);
return;
}
diff --git a/src/java/org/apache/nutch/util/URLUtil.java b/src/java/org/apache/nutch/util/URLUtil.java
index 24a4cf03f..dca911abe 100644
--- a/src/java/org/apache/nutch/util/URLUtil.java
+++ b/src/java/org/apache/nutch/util/URLUtil.java
@@ -20,6 +20,7 @@ import java.net.IDN;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
+import java.util.Locale;
import java.util.regex.Pattern;
import org.apache.nutch.util.domain.DomainSuffix;
@@ -430,7 +431,7 @@ public class URLUtil {
*/
public static String getHost(String url) {
try {
- return new URL(url).getHost().toLowerCase();
+ return new URL(url).getHost().toLowerCase(Locale.ROOT);
} catch (MalformedURLException e) {
return null;
}