Apache Nutch is an extensible and scalable web crawler
NUTCH-1413 Record response time
Sebastian Nagele8fbd2427596
diff --git a/CHANGES.txt b/CHANGES.txtindex 466764347..8827943a5 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,8 @@ Nutch Change LogNutch Development Trunk+* NUTCH-1413 Record response time (Yasin Kılınç, Talat Uyarer, snagel)+* NUTCH-1325 HostDB for Nutch (markus, tejasp)* NUTCH-1680 CrawlDbReader to dump minRetry value (markus)diff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex bd5a92abc..61133e640 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -266,6 +266,16 @@</description></property>+<property>+ <name>http.store.responsetime</name>+ <value>true</value>+ <description>Enables us to record the response time of the+ host which is the time period between start connection to end+ connection of a pages host. The response time in milliseconds+ is stored in CrawlDb in CrawlDatum's meta data under key "_rs_"+ </description>+</property>+<!-- FTP properties --><property>diff --git a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.javaindex ca21e2b8f..575467014 100644--- a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java+++ b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java@@ -37,6 +37,7 @@ import org.apache.nutch.util.DeflateUtils;// Hadoop importsimport org.apache.hadoop.conf.Configuration;+import org.apache.hadoop.io.IntWritable;import org.apache.hadoop.io.Text;// crawler-commons imports@@ -47,7 +48,8 @@ import crawlercommons.robots.BaseRobotRules;*/public abstract class HttpBase implements Protocol {-+ public static final Text RESPONSE_TIME = new Text("_rs_");+public static final int BUFFER_SIZE = 8 * 1024;private static final byte[] EMPTY_CONTENT = new byte[0];@@ -92,6 +94,12 @@ public abstract class HttpBase implements Protocol {/** Do we use HTTP/1.1? */protected boolean useHttp11 = false;++ /**+ * Record response time in CrawlDatum's meta data, see property+ * http.store.responsetime.+ */+ protected boolean responseTime = true;/** Skip page if Crawl-Delay longer than this value. */protected long maxCrawlDelay = -1L;@@ -123,6 +131,7 @@ public abstract class HttpBase implements Protocol {this.accept = conf.get("http.accept", accept);// backward-compatible default settingthis.useHttp11 = conf.getBoolean("http.useHttp11", false);+ this.responseTime = conf.getBoolean("http.store.responsetime", true);this.robots.setConf(conf);logConf();}@@ -137,8 +146,15 @@ public abstract class HttpBase implements Protocol {String urlString = url.toString();try {URL u = new URL(urlString);++ long startTime = System.currentTimeMillis();Response response = getResponse(u, datum, false); // make a request+ if(this.responseTime) {+ int elapsedTime = (int) (System.currentTimeMillis() - startTime);+ datum.getMetaData().put(RESPONSE_TIME, new IntWritable(elapsedTime));+ }+int code = response.getCode();byte[] content = response.getContent();Content c = new Content(u.toString(), u.toString(),