You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/08/09 13:11:21 UTC

svn commit: r1155309 - in /httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark: ./ src/main/java/org/apache/http/client/benchmark/

Author: olegk
Date: Tue Aug  9 11:11:21 2011
New Revision: 1155309

URL: http://svn.apache.org/viewvc?rev=1155309&view=rev
Log:
HttpCore benchmark sampler to make use of a connection pool; upgraded Ning Http Client to version 1.6.4

Modified:
    httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/pom.xml
    httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
    httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
    httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java

Modified: httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/pom.xml?rev=1155309&r1=1155308&r2=1155309&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/pom.xml (original)
+++ httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/pom.xml Tue Aug  9 11:11:21 2011
@@ -60,12 +60,6 @@
       <scope>compile</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.httpcomponents</groupId>
-      <artifactId>httpcore</artifactId>
-      <version>4.1.1</version>
-      <scope>compile</scope>
-    </dependency>
-    <dependency>
       <groupId>commons-httpclient</groupId>
       <artifactId>commons-httpclient</artifactId>
       <version>3.1</version>
@@ -98,7 +92,7 @@
     <dependency>
       <groupId>com.ning</groupId>
       <artifactId>async-http-client</artifactId>
-      <version>1.5.0</version>
+      <version>1.6.4</version>
       <scope>compile</scope>
     </dependency>
   </dependencies>

Modified: httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java?rev=1155309&r1=1155308&r2=1155309&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java (original)
+++ httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java Tue Aug  9 11:11:21 2011
@@ -42,7 +42,7 @@ import org.apache.http.conn.scheme.Schem
 import org.apache.http.conn.ssl.SSLSocketFactory;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.impl.conn.PoolingClientConnectionManager;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
@@ -52,7 +52,7 @@ import org.apache.http.util.VersionInfo;
 
 public class TestHttpClient4 implements TestHttpAgent {
 
-    private final ThreadSafeClientConnManager mgr;
+    private final PoolingClientConnectionManager mgr;
     private final DefaultHttpClient httpclient;
 
     public TestHttpClient4() {
@@ -71,7 +71,7 @@ public class TestHttpClient4 implements 
         SchemeRegistry schemeRegistry = new SchemeRegistry();
         schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
         schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
-        this.mgr = new ThreadSafeClientConnManager(schemeRegistry);
+        this.mgr = new PoolingClientConnectionManager(schemeRegistry);
         this.httpclient = new DefaultHttpClient(this.mgr, params);
         this.httpclient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
 

Modified: httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java?rev=1155309&r1=1155308&r2=1155309&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java (original)
+++ httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java Tue Aug  9 11:11:21 2011
@@ -27,11 +27,13 @@ package org.apache.http.client.benchmark
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.Socket;
 import java.net.URI;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
 
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.HeaderIterator;
+import org.apache.http.HttpClientConnection;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
@@ -41,7 +43,8 @@ import org.apache.http.HttpResponse;
 import org.apache.http.HttpVersion;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.impl.DefaultHttpClientConnection;
+import org.apache.http.impl.pool.BasicConnPool;
+import org.apache.http.impl.pool.BasicPoolEntry;
 import org.apache.http.message.BasicHttpEntityEnclosingRequest;
 import org.apache.http.message.BasicHttpRequest;
 import org.apache.http.params.HttpConnectionParams;
@@ -66,6 +69,7 @@ public class TestHttpCore implements Tes
     private final HttpProcessor httpproc;
     private final HttpRequestExecutor httpexecutor;
     private final ConnectionReuseStrategy connStrategy;
+    private final BasicConnPool pool;
 
     public TestHttpCore() {
         super();
@@ -91,6 +95,8 @@ public class TestHttpCore implements Tes
 
         this.httpexecutor = new HttpRequestExecutor();
         this.connStrategy = new DefaultConnectionReuseStrategy();
+
+        this.pool = new BasicConnPool(this.params);
     }
 
     public void init() {
@@ -100,6 +106,8 @@ public class TestHttpCore implements Tes
     }
 
     Stats execute(final URI target, final byte[] content, int n, int c) throws Exception {
+        this.pool.setMaxTotal(2000);
+        this.pool.setDefaultMaxPerRoute(c);
         HttpHost targetHost = new HttpHost(target.getHost(), target.getPort());
         StringBuilder buffer = new StringBuilder();
         buffer.append(target.getPath());
@@ -143,29 +151,27 @@ public class TestHttpCore implements Tes
         public void run() {
             byte[] buffer = new byte[4096];
             HttpContext context = new BasicHttpContext();
-            DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
-            try {
-                while (!this.stats.isComplete()) {
-                    HttpRequest request;
-                    if (this.content == null) {
-                        BasicHttpRequest httpget = new BasicHttpRequest("GET", this.requestUri);
-                        request = httpget;
-                    } else {
-                        BasicHttpEntityEnclosingRequest httppost = new BasicHttpEntityEnclosingRequest("POST",
-                                this.requestUri);
-                        httppost.setEntity(new ByteArrayEntity(this.content));
-                        request = httppost;
-                    }
 
-                    long contentLen = 0;
-                    try {
-                        if (!conn.isOpen()) {
-                            Socket socket = new Socket(
-                                    this.targetHost.getHostName(),
-                                    this.targetHost.getPort() > 0 ? this.targetHost.getPort() : 80);
-                            conn.bind(socket, params);
-                        }
+            while (!this.stats.isComplete()) {
+                HttpRequest request;
+                if (this.content == null) {
+                    BasicHttpRequest httpget = new BasicHttpRequest("GET", this.requestUri);
+                    request = httpget;
+                } else {
+                    BasicHttpEntityEnclosingRequest httppost = new BasicHttpEntityEnclosingRequest("POST",
+                            this.requestUri);
+                    httppost.setEntity(new ByteArrayEntity(this.content));
+                    request = httppost;
+                }
 
+                long contentLen = 0;
+                boolean reusable = false;
+
+                Future<BasicPoolEntry> future = pool.lease(targetHost, null);
+                try {
+                    BasicPoolEntry entry = future.get();
+                    try {
+                        HttpClientConnection conn = entry.getConnection();
                         context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
                         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, targetHost);
 
@@ -188,8 +194,8 @@ public class TestHttpCore implements Tes
                                 instream.close();
                             }
                         }
-                        if (!connStrategy.keepAlive(response, context)) {
-                            conn.close();
+                        if (connStrategy.keepAlive(response, context)) {
+                            reusable = true;
                         }
                         for (HeaderIterator it = request.headerIterator(); it.hasNext();) {
                             it.next();
@@ -200,16 +206,18 @@ public class TestHttpCore implements Tes
                         } else {
                             this.stats.failure(contentLen);
                         }
-                    } catch (IOException ex) {
-                        this.stats.failure(contentLen);
-                    } catch (HttpException ex) {
-                        this.stats.failure(contentLen);
+                    } finally {
+                        pool.release(entry, reusable);
                     }
+                } catch (InterruptedException ex) {
+                    this.stats.failure(contentLen);
+                } catch (ExecutionException ex) {
+                    this.stats.failure(contentLen);
+                } catch (IOException ex) {
+                    this.stats.failure(contentLen);
+                } catch (HttpException ex) {
+                    this.stats.failure(contentLen);
                 }
-            } finally {
-                try {
-                    conn.shutdown();
-                } catch (IOException ignore) {}
             }
         }
 

Modified: httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java?rev=1155309&r1=1155308&r2=1155309&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java (original)
+++ httpcomponents/httpclient/branches/conn-mgmt-redesign/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java Tue Aug  9 11:11:21 2011
@@ -94,7 +94,7 @@ public class TestNingHttpClient implemen
     }
 
     public String getClientName() {
-        return "Ning async HTTP client 1.5.0";
+        return "Ning async HTTP client 1.6.4";
     }
 
     static class SimpleAsyncHandler implements AsyncHandler<Object> {