You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by as...@apache.org on 2008/09/08 12:50:58 UTC

svn commit: r693050 - in /httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/benchmark: CommandLineUtils.java HttpBenchmark.java

Author: asankha
Date: Mon Sep  8 03:50:56 2008
New Revision: 693050

URL: http://svn.apache.org/viewvc?rev=693050&view=rev
Log:
close connections cleanly before ending a run
Support new options :
  -o : Use http 1.0 instead of default http 1.1
  -t <n> : Use the socket timeout as <n> milliseconds
  -H "h1: v1","h2: v2" : Support multiple http headers to work around a CLI limitation

Modified:
    httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/benchmark/CommandLineUtils.java
    httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/benchmark/HttpBenchmark.java

Modified: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/benchmark/CommandLineUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/benchmark/CommandLineUtils.java?rev=693050&r1=693049&r2=693050&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/benchmark/CommandLineUtils.java (original)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/benchmark/CommandLineUtils.java Mon Sep  8 03:50:56 2008
@@ -45,6 +45,9 @@
         Option iopt = new Option("i", false, "Do HEAD requests instead of GET.");
         iopt.setRequired(false);
 
+        Option oopt = new Option("o", false, "Use HTTP/S 1.0");
+        oopt.setRequired(false);
+
         Option kopt = new Option("k", false, "Enable the HTTP KeepAlive feature, " +
             "i.e., perform multiple requests within one HTTP session. " +
             "Default is no KeepAlive");
@@ -70,9 +73,13 @@
         Topt.setRequired(false);
         Topt.setArgName("content-type");
 
+        Option topt = new Option("t", true, "Client side socket timeout (in ms) - default 60 Secs");
+        topt.setRequired(false);
+        topt.setArgName("socket-Timeout");
+
         Option Hopt = new Option("H", true, "Add arbitrary header line, " +
             "eg. 'Accept-Encoding: gzip' inserted after all normal " +
-            "header lines. (repeatable)");
+            "header lines. (repeatable as -H \"h1: v1\",\"h2: v2\" etc)");
         Hopt.setRequired(false);
         Hopt.setArgName("header");
 
@@ -96,6 +103,8 @@
         options.addOption(vopt);
         options.addOption(Hopt);
         options.addOption(hopt);
+        options.addOption(topt);
+        options.addOption(oopt);
         return options;
     }
 
@@ -154,7 +163,21 @@
         }
 
         if (cmd.hasOption('H')) {
-            httpBenchmark.headers = cmd.getOptionValues('H');
+            String headerStr = cmd.getOptionValue('H');
+            httpBenchmark.headers = headerStr.split(",");
+        }
+
+        if (cmd.hasOption('t')) {
+            String t = cmd.getOptionValue('t');
+            try {
+                httpBenchmark.socketTimeout = Integer.parseInt(t);
+            } catch (NumberFormatException ex) {
+                printError("Invalid socket timeout: " + t);
+            }
+        }
+
+        if (cmd.hasOption('o')) {
+            httpBenchmark.useHttp1_0 = true;
         }
     }
 

Modified: httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/benchmark/HttpBenchmark.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/benchmark/HttpBenchmark.java?rev=693050&r1=693049&r2=693050&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/benchmark/HttpBenchmark.java (original)
+++ httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/benchmark/HttpBenchmark.java Mon Sep  8 03:50:56 2008
@@ -67,7 +67,7 @@
  */
 public class HttpBenchmark {
 
-    private HttpParams params = getHttpParams();
+    private HttpParams params = null;
     private HttpRequest[] request = null;
     private HttpHost host = null;
     protected int verbosity = 0;
@@ -80,6 +80,8 @@
     protected String[] headers = null;
     protected boolean doHeadInsteadOfGet = false;
     private long contentLength = -1;
+    protected int socketTimeout = 60000;
+    protected boolean useHttp1_0 = false;
 
     public static void main(String[] args) throws Exception {
 
@@ -99,6 +101,9 @@
 
 
     private void prepare() {
+        // prepare http params
+        params = getHttpParams(socketTimeout, useHttp1_0);
+
         host = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
 
         // Prepare requests for each thread
@@ -189,12 +194,14 @@
         ResultProcessor.printResults(workers, host, url.toString(), contentLength);
     }
 
-    private static HttpParams getHttpParams() {
+    private HttpParams getHttpParams(int socketTimeout, boolean useHttp1_0) {
         HttpParams params = new BasicHttpParams();
-        params.setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1)
+        params.setParameter(HttpProtocolParams.PROTOCOL_VERSION,
+            useHttp1_0 ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1)
             .setParameter(HttpProtocolParams.USER_AGENT, "Jakarta-HttpComponents-Bench/1.1")
             .setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false)
-            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false);
+            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false)
+            .setIntParameter(HttpConnectionParams.SO_TIMEOUT, socketTimeout);
         return params;
     }