hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1032663 - in /httpcomponents/httpclient/trunk: ./ httpclient-benchmark/ httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/
Date Mon, 08 Nov 2010 18:32:15 GMT
Author: olegk
Date: Mon Nov  8 18:32:15 2010
New Revision: 1032663

URL: http://svn.apache.org/viewvc?rev=1032663&view=rev
Log:
Added Ning Async HTTP client to the HTTP client benchmark 

Added:
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
    httpcomponents/httpclient/trunk/pom.xml

Modified: httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml?rev=1032663&r1=1032662&r2=1032663&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml (original)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml Mon Nov  8 18:32:15 2010
@@ -40,6 +40,18 @@
   <url>http://hc.apache.org/httpcomponents-client</url>
   <packaging>jar</packaging>
 
+  <repositories>
+    <repository>
+      <id>jboss</id>
+      <name>JBoss Repository</name>
+      <layout>default</layout>
+      <url>http://oss.sonatype.org/content/repositories/releases</url>
+      <snapshots>
+        <enabled>false</enabled>
+      </snapshots>
+    </repository>
+  </repositories>
+
   <dependencies>
     <dependency>
       <groupId>org.apache.httpcomponents</groupId>
@@ -83,6 +95,12 @@
       <version>1.5.10</version>
       <scope>compile</scope>
     </dependency>
+    <dependency>
+      <groupId>com.ning</groupId>
+      <artifactId>async-http-client</artifactId>
+      <version>1.3.3</version>
+      <scope>compile</scope>
+    </dependency>
   </dependencies>
 
   <properties>

Modified: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java?rev=1032663&r1=1032662&r2=1032663&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java
Mon Nov  8 18:32:15 2010
@@ -48,8 +48,8 @@ public class Benchmark {
 
    public static void main(String[] args) throws Exception {
        
-       String ns = System.getProperty("hc.benchmark.n-requests", "100000");
-       String nc = System.getProperty("hc.benchmark.concurrent", "25");
+       String ns = System.getProperty("hc.benchmark.n-requests", "200000");
+       String nc = System.getProperty("hc.benchmark.concurrent", "100");
        String cls = System.getProperty("hc.benchmark.content-len", "2048");
        
        int n = Integer.parseInt(ns);
@@ -82,7 +82,8 @@ public class Benchmark {
                new TestHttpJRE(),
                new TestHttpCore(),
                new TestHttpClient4(),
-               new TestJettyHttpClient()
+               new TestJettyHttpClient(),
+               new TestNingHttpClient()
        };
 
        byte[] content = new byte[contentLen];

Modified: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java?rev=1032663&r1=1032662&r2=1032663&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
Mon Nov  8 18:32:15 2010
@@ -107,7 +107,7 @@ public class TestJettyHttpClient impleme
 
         @Override
         protected void onResponseContent(final Buffer content) throws IOException {
-            this.contentLen += content.length();
+            this.contentLen += content.asArray().length;
             super.onResponseContent(content);
         }
 

Added: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java?rev=1032663&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
Mon Nov  8 18:32:15 2010
@@ -0,0 +1,165 @@
+/*
+ * ====================================================================
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.client.benchmark;
+
+import java.io.IOException;
+import java.net.URI;
+
+import com.ning.http.client.AsyncHandler;
+import com.ning.http.client.AsyncHttpClient;
+import com.ning.http.client.AsyncHttpClientConfig;
+import com.ning.http.client.HttpResponseBodyPart;
+import com.ning.http.client.HttpResponseHeaders;
+import com.ning.http.client.HttpResponseStatus;
+import com.ning.http.client.Request;
+
+public class TestNingHttpClient implements TestHttpAgent {
+
+    private AsyncHttpClient client;
+
+    public TestNingHttpClient() {
+        super();
+    }
+
+    public void init() throws Exception {
+    }
+
+    public void shutdown() throws Exception {
+        this.client.close();
+    }
+
+    Stats execute(final URI targetURI, byte[] content, int n, int c) throws Exception {
+        if (this.client != null) {
+            this.client.close();
+        }
+        AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()
+            .setKeepAlive(true)
+            .setCompressionEnabled(false)
+            .setMaximumConnectionsPerHost(c)
+            .setMaximumConnectionsTotal(2000)
+            .setRequestTimeoutInMs(15000)
+            .build(); 
+        this.client = new AsyncHttpClient(config);
+
+        Stats stats = new Stats(n, c);
+
+        for (int i = 0; i < n; i++) {
+            Request request;
+            if (content == null) {
+                request = this.client.prepareGet(targetURI.toASCIIString())
+                    .build();            
+            } else {
+                request = this.client.preparePost(targetURI.toASCIIString())
+                    .setBody(content)
+                    .build();            
+            }
+            try {
+                this.client.executeRequest(request, new SimpleAsyncHandler(stats));
+            } catch (IOException ex) {
+            }
+        }
+        stats.waitFor();
+        return stats;
+    }
+
+    public Stats get(final URI target, int n, int c) throws Exception {
+        return execute(target, null, n, c);
+    }
+
+    public Stats post(final URI target, byte[] content, int n, int c) throws Exception {
+        return execute(target, content, n, c);
+    }
+
+    public String getClientName() {
+        return "Ning Async HTTP client 1.3"; 
+    }
+
+    static class SimpleAsyncHandler implements AsyncHandler<Object> {
+
+        private final Stats stats;
+        private int status = 0;
+        private long contentLen = 0;
+
+        SimpleAsyncHandler(final Stats stats) {
+            super();
+            this.stats = stats;
+        }
+        
+        public STATE onStatusReceived(final HttpResponseStatus responseStatus) throws Exception
{
+            this.status = responseStatus.getStatusCode();
+            return STATE.CONTINUE;
+        }
+
+        public STATE onHeadersReceived(final HttpResponseHeaders headers) throws Exception
{
+            return STATE.CONTINUE;
+        }
+
+        public STATE onBodyPartReceived(final HttpResponseBodyPart bodyPart) throws Exception
{
+            this.contentLen += bodyPart.getBodyPartBytes().length;
+            return STATE.CONTINUE;
+        }
+
+        public Object onCompleted() throws Exception {
+            if (this.status == 200) {
+                this.stats.success(this.contentLen);
+            } else {
+                this.stats.failure(this.contentLen);
+            }
+            return STATE.CONTINUE;
+        }
+
+        public void onThrowable(final Throwable t) {
+            this.stats.failure(this.contentLen);
+        }
+
+    };
+
+    public static void main(String[] args) throws Exception {
+        if (args.length < 2) {
+            System.out.println("Usage: <target URI> <no of requests> <concurrent
connections>");
+            System.exit(-1);
+        }
+        URI targetURI = new URI(args[0]);
+        int n = Integer.parseInt(args[1]);
+        int c = 1;
+        if (args.length > 2) {
+            c = Integer.parseInt(args[2]);
+        }
+        
+        TestNingHttpClient test = new TestNingHttpClient();
+        test.init();
+        try {
+            long startTime = System.currentTimeMillis();
+            Stats stats = test.get(targetURI, n, c);
+            long finishTime = System.currentTimeMillis();
+
+            Stats.printStats(targetURI, startTime, finishTime, stats);
+        } finally {
+            test.shutdown();
+        }
+    }
+
+}
\ No newline at end of file

Propchange: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/pom.xml?rev=1032663&r1=1032662&r2=1032663&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/pom.xml (original)
+++ httpcomponents/httpclient/trunk/pom.xml Mon Nov  8 18:32:15 2010
@@ -89,6 +89,7 @@
       <plugin>
         <artifactId>maven-notice-plugin</artifactId>
         <groupId>org.apache.httpcomponents</groupId>
+        <version>0.0.2-SNAPSHOT</version>
         <executions>
           <execution>
             <id>attach-notice-license</id>



Mime
View raw message