hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1499526 - in /httpcomponents/benchmark/httpclient/branches/4.2.x: ./ src/main/java/org/apache/http/client/benchmark/
Date Wed, 03 Jul 2013 19:14:58 GMT
Author: olegk
Date: Wed Jul  3 19:14:57 2013
New Revision: 1499526

URL: http://svn.apache.org/r1499526
Log:
Run each agent in a separate process

Added:
    httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/ApacheHttpClient.java
  (contents, props changed)
      - copied, changed from r1499525, httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
    httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/BenchRunner.java
  (with props)
    httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/Config.java
      - copied, changed from r1499525, httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java
    httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpAgent.java
  (contents, props changed)
      - copied, changed from r1499525, httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java
    httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpJRE.java
  (contents, props changed)
      - copied, changed from r1499525, httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java
    httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/JettyHttpClient.java
  (contents, props changed)
      - copied, changed from r1499525, httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
    httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/NingHttpClient.java
  (contents, props changed)
      - copied, changed from r1499525, httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
Removed:
    httpcomponents/benchmark/httpclient/branches/4.2.x/pom.xml
    httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java
    httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
    httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java
    httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
    httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
Modified:
    httpcomponents/benchmark/httpclient/branches/4.2.x/build.gradle
    httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/Benchmark.java

Modified: httpcomponents/benchmark/httpclient/branches/4.2.x/build.gradle
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/branches/4.2.x/build.gradle?rev=1499526&r1=1499525&r2=1499526&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/branches/4.2.x/build.gradle (original)
+++ httpcomponents/benchmark/httpclient/branches/4.2.x/build.gradle Wed Jul  3 19:14:57 2013
@@ -1,5 +1,4 @@
 apply plugin: 'java'
-apply plugin: 'application'
 
 repositories {
     mavenCentral()
@@ -10,17 +9,28 @@ version = '0.1-SNAPSHOT'
 sourceCompatibility = '1.6'
 
 dependencies {
+    compile group: 'commons-cli', name: 'commons-cli', version: '1.2'
     compile group: 'org.eclipse.jetty', name: 'jetty-server', version: '8.1.7.v20120910'
     compile group: 'org.eclipse.jetty', name: 'jetty-client', version: '8.1.7.v20120910'
-    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.5.10'
-    compile group: 'org.slf4j', name: 'slf4j-nop', version: '1.5.10'
-    compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.3-beta2'
-    compile group: 'org.apache.httpcomponents', name: 'httpcore-nio', version: '4.3-beta2'
-    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3-beta2'
-    compile group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.0-beta4'
-    compile group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.0-beta4'
+    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.6.2'
+    compile group: 'org.slf4j', name: 'slf4j-nop', version: '1.6.2'
+    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.2.5'
     compile group: 'com.ning', name: 'async-http-client', version: '1.7.12'
 }
 
-mainClassName = 'org.apache.http.client.benchmark.Benchmark'
+task benchmark(dependsOn: 'classes') << {
+    def agents = [
+            'HttpJRE',
+            'ApacheHttpClient',
+//            'JettyHttpClient',
+            'NingHttpClient']
+    agents.each { agent ->
+        javaexec {
+            main = "org.apache.http.client.benchmark.${agent}"
+            classpath = sourceSets.main.runtimeClasspath
+        }
+        sleep(2000)
+    }
+}
 
+defaultTasks 'clean', 'benchmark'

Copied: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/ApacheHttpClient.java
(from r1499525, httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java)
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/ApacheHttpClient.java?p2=httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/ApacheHttpClient.java&p1=httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java&r1=1499525&r2=1499526&rev=1499526&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
(original)
+++ httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/ApacheHttpClient.java
Wed Jul  3 19:14:57 2013
@@ -50,12 +50,12 @@ import org.apache.http.params.SyncBasicH
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.util.VersionInfo;
 
-public class TestHttpClient4 implements TestHttpAgent {
+public class ApacheHttpClient implements HttpAgent {
 
     private final PoolingClientConnectionManager mgr;
     private final DefaultHttpClient httpclient;
 
-    public TestHttpClient4() {
+    public ApacheHttpClient() {
         super();
         HttpParams params = new SyncBasicHttpParams();
         params.setParameter(HttpProtocolParams.PROTOCOL_VERSION,
@@ -177,32 +177,12 @@ public class TestHttpClient4 implements 
         VersionInfo vinfo = VersionInfo.loadVersionInfo("org.apache.http.client",
                 Thread.currentThread().getContextClassLoader());
         return "Apache HttpClient 4 (ver: " +
-            ((vinfo != null) ? vinfo.getRelease() : VersionInfo.UNAVAILABLE) + ")";
+                ((vinfo != null) ? vinfo.getRelease() : VersionInfo.UNAVAILABLE) + ")";
     }
 
-    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]);
-        }
-
-        TestHttpClient4 test = new TestHttpClient4();
-        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();
-        }
+    public static void main(final String[] args) throws Exception {
+        final Config config = BenchRunner.parseConfig(args);
+        BenchRunner.run(new ApacheHttpClient(), config);
     }
 
 }
\ No newline at end of file

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/ApacheHttpClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/ApacheHttpClient.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/ApacheHttpClient.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/BenchRunner.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/BenchRunner.java?rev=1499526&view=auto
==============================================================================
--- httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/BenchRunner.java
(added)
+++ httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/BenchRunner.java
Wed Jul  3 19:14:57 2013
@@ -0,0 +1,267 @@
+/*
+ * ====================================================================
+ *
+ *  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 org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+import org.eclipse.jetty.http.HttpStatus;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.util.ByteArrayOutputStream2;
+import org.eclipse.jetty.util.IO;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+public class BenchRunner {
+
+    public static Config parseConfig(final String[] args) throws ParseException {
+        final Config config = new Config();
+        if (args.length > 0) {
+            final Option kopt = new Option("k", false, "Enable the HTTP KeepAlive feature,
" +
+                    "i.e., perform multiple requests within one HTTP session. " +
+                    "Default is no KeepAlive");
+            kopt.setRequired(false);
+            final Option copt = new Option("c", true, "Concurrency while performing the "
+
+                    "benchmarking session. The default is to just use a single thread/client");
+            copt.setRequired(false);
+            copt.setArgName("concurrency");
+
+            final Option nopt = new Option("n", true, "Number of requests to perform for
the " +
+                    "benchmarking session. The default is to just perform a single " +
+                    "request which usually leads to non-representative benchmarking " +
+                    "results");
+            nopt.setRequired(false);
+            nopt.setArgName("requests");
+
+            final Option lopt = new Option("l", true, "Request content length");
+            nopt.setRequired(false);
+            nopt.setArgName("content length");
+
+            final Options options = new Options();
+            options.addOption(kopt);
+            options.addOption(nopt);
+            options.addOption(copt);
+            options.addOption(lopt);
+
+            final CommandLineParser parser = new PosixParser();
+            final CommandLine cmd = parser.parse(options, args);
+            if (cmd.hasOption('h')) {
+                final HelpFormatter formatter = new HelpFormatter();
+                formatter.printHelp("Benchmark [options]", options);
+                System.exit(1);
+            }
+            if (cmd.hasOption('k')) {
+                config.setKeepAlive(true);
+            }
+            if (cmd.hasOption('c')) {
+                final String s = cmd.getOptionValue('c');
+                try {
+                    config.setConcurrency(Integer.parseInt(s));
+                } catch (final NumberFormatException ex) {
+                    System.err.println("Invalid number for concurrency: " + s);
+                    System.exit(-1);
+                }
+            }
+            if (cmd.hasOption('n')) {
+                final String s = cmd.getOptionValue('n');
+                try {
+                    config.setRequests(Integer.parseInt(s));
+                } catch (final NumberFormatException ex) {
+                    System.err.println("Invalid number of requests: " + s);
+                    System.exit(-1);
+                }
+            }
+            if (cmd.hasOption('l')) {
+                final String s = cmd.getOptionValue('l');
+                try {
+                    config.setContentLength(Integer.parseInt(s));
+                } catch (final NumberFormatException ex) {
+                    System.err.println("Invalid content length: " + s);
+                    System.exit(-1);
+                }
+            }
+            final String[] cmdargs = cmd.getArgs();
+            if (cmdargs.length > 0) {
+                try {
+                    config.setUri(new URI(cmdargs[0]));
+                } catch (final URISyntaxException ex) {
+                    System.err.println("Invalid request URL : " + cmdargs[0]);
+                    System.exit(-1);
+                }
+            }
+
+        } else {
+            config.setKeepAlive(true);
+            config.setRequests(1000000);
+            config.setConcurrency(50);
+        }
+        return config;
+    }
+
+    public static void run(final HttpAgent agent, final Config config) throws Exception {
+        final SelectChannelConnector connector = new SelectChannelConnector();
+        final Server server = new Server();
+        server.addConnector(connector);
+        server.setHandler(new RandomDataHandler());
+
+        server.start();
+        final int port = connector.getLocalPort();
+
+        final byte[] content = new byte[config.getContentLength()];
+        final int r = Math.abs(content.hashCode());
+        for (int i = 0; i < content.length; i++) {
+            content[i] = (byte) ((r + i) % 96 + 32);
+        }
+
+        final URI warmup = new URI("http", null, "localhost", port, "/rnd", "c=2048", null);
+        final URI target = new URI("http", null, "localhost", port, "/echo", null, null);
+
+        try {
+            try {
+                agent.init();
+                // Warm up
+                agent.get(warmup, 500, 2);
+                // Sleep a little
+                Thread.sleep(5000);
+
+                System.out.println("=================================");
+                System.out.println("HTTP agent: " + agent.getClientName());
+                System.out.println("---------------------------------");
+                System.out.println(config.getRequests() + " POST requests");
+                System.out.println("---------------------------------");
+
+                final long startTime = System.currentTimeMillis();
+                final Stats stats = agent.post(target, content, config.getRequests(), config.getConcurrency());
+                final long finishTime = System.currentTimeMillis();
+                Stats.printStats(target, startTime, finishTime, stats);
+            } finally {
+                agent.shutdown();
+            }
+            System.out.println("---------------------------------");
+        } finally {
+            server.stop();
+        }
+        server.join();
+    }
+
+    static class RandomDataHandler extends AbstractHandler {
+
+        public RandomDataHandler() {
+            super();
+        }
+
+        @Override
+        public void handle(
+                final String target,
+                final Request baseRequest,
+                final HttpServletRequest request,
+                final HttpServletResponse response) throws IOException, ServletException
{
+            if (target.equals("/rnd")) {
+                rnd(request, response);
+            } else if (target.equals("/echo")) {
+                echo(request, response);
+            } else {
+                response.setStatus(HttpStatus.NOT_FOUND_404);
+                final Writer writer = response.getWriter();
+                writer.write("Target not found: " + target);
+                writer.flush();
+            }
+        }
+
+        private void rnd(
+                final HttpServletRequest request,
+                final HttpServletResponse response) throws IOException {
+            int count = 100;
+            final String s = request.getParameter("c");
+            try {
+                count = Integer.parseInt(s);
+            } catch (final NumberFormatException ex) {
+                response.setStatus(500);
+                final Writer writer = response.getWriter();
+                writer.write("Invalid query format: " + request.getQueryString());
+                writer.flush();
+                return;
+            }
+
+            response.setStatus(200);
+            response.setContentLength(count);
+
+            final OutputStream outstream = response.getOutputStream();
+            final byte[] tmp = new byte[1024];
+            final int r = Math.abs(tmp.hashCode());
+            int remaining = count;
+            while (remaining > 0) {
+                final int chunk = Math.min(tmp.length, remaining);
+                for (int i = 0; i < chunk; i++) {
+                    tmp[i] = (byte) ((r + i) % 96 + 32);
+                }
+                outstream.write(tmp, 0, chunk);
+                remaining -= chunk;
+            }
+            outstream.flush();
+        }
+
+        private void echo(
+                final HttpServletRequest request,
+                final HttpServletResponse response) throws IOException {
+
+            final ByteArrayOutputStream2 buffer = new ByteArrayOutputStream2();
+            final InputStream instream = request.getInputStream();
+            if (instream != null) {
+                IO.copy(instream, buffer);
+                buffer.flush();
+            }
+            final byte[] content = buffer.getBuf();
+            final int len = buffer.getCount();
+
+            response.setStatus(200);
+            response.setContentLength(len);
+
+            final OutputStream outstream = response.getOutputStream();
+            outstream.write(content, 0, len);
+            outstream.flush();
+        }
+
+    }
+
+}

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/BenchRunner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/BenchRunner.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/BenchRunner.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/Benchmark.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/Benchmark.java?rev=1499526&r1=1499525&r2=1499526&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/Benchmark.java
(original)
+++ httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/Benchmark.java
Wed Jul  3 19:14:57 2013
@@ -25,176 +25,20 @@
  */
 package org.apache.http.client.benchmark;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Writer;
-import java.net.URI;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.jetty.http.HttpStatus;
-import org.eclipse.jetty.server.Request;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.handler.AbstractHandler;
-import org.eclipse.jetty.server.nio.SelectChannelConnector;
-import org.eclipse.jetty.util.ByteArrayOutputStream2;
-import org.eclipse.jetty.util.IO;
-
 public class Benchmark {
 
-    public static void main(String[] args) throws Exception {
-
-        String ns = System.getProperty("hc.benchmark.n-requests", "200000");
-        String nc = System.getProperty("hc.benchmark.concurrent", "20");
-        String cls = System.getProperty("hc.benchmark.content-len", "2048");
-
-        int n = Integer.parseInt(ns);
-        int c = Integer.parseInt(nc);
-        int contentLen = Integer.parseInt(cls);
-
-        SelectChannelConnector connector = new SelectChannelConnector();
-        Server server = new Server();
-        server.addConnector(connector);
-        server.setHandler(new RandomDataHandler());
-
-        server.start();
-        int port = connector.getLocalPort();
-
-        TestHttpAgent[] agents = new TestHttpAgent[] {
-                new TestHttpJRE(),
-                new TestHttpClient4(),
-                new TestJettyHttpClient(),
-                new TestNingHttpClient()
-        };
-
-        byte[] content = new byte[contentLen];
-        int r = Math.abs(content.hashCode());
-        for (int i = 0; i < content.length; i++) {
-            content[i] = (byte) ((r + i) % 96 + 32);
-        }
-
-        URI warmup = new URI("http", null, "localhost", port, "/rnd", "c=2048", null);
-        URI target1 = new URI("http", null, "localhost", port, "/rnd", "c=" + contentLen,
null);
-        URI target2 = new URI("http", null, "localhost", port, "/echo", null, null);
-
-        try {
-            for (TestHttpAgent agent: agents) {
-                try {
-                    agent.init();
-                    // Warm up
-                    agent.get(warmup, 500, 2);
-                    // Sleep a little
-                    Thread.sleep(5000);
-
-                    System.out.println("=================================");
-                    System.out.println("HTTP agent: " + agent.getClientName());
-                    System.out.println("---------------------------------");
-                    System.out.println(n + " GET requests");
-                    System.out.println("---------------------------------");
-
-                    long startTime1 = System.currentTimeMillis();
-                    Stats stats1 = agent.get(target1, n, c);
-                    long finishTime1 = System.currentTimeMillis();
-                    Stats.printStats(target1, startTime1, finishTime1, stats1);
-                    System.out.println("---------------------------------");
-                    System.out.println(n + " POST requests");
-                    System.out.println("---------------------------------");
-
-                    long startTime2 = System.currentTimeMillis();
-                    Stats stats2 = agent.post(target2, content, n, c);
-                    long finishTime2 = System.currentTimeMillis();
-                    Stats.printStats(target2, startTime2, finishTime2, stats2);
-                } finally {
-                    agent.shutdown();
-                }
-                System.out.println("---------------------------------");
-            }
-        } finally {
-            server.stop();
-        }
-        server.join();
-    }
-
-    static class RandomDataHandler extends AbstractHandler {
-
-        public RandomDataHandler() {
-            super();
-        }
-
-        public void handle(
-                final String target,
-                final Request baseRequest,
-                final HttpServletRequest request,
-                final HttpServletResponse response) throws IOException, ServletException
{
-            if (target.equals("/rnd")) {
-                rnd(request, response);
-            } else if (target.equals("/echo")) {
-                echo(request, response);
-            } else {
-                response.setStatus(HttpStatus.NOT_FOUND_404);
-                Writer writer = response.getWriter();
-                writer.write("Target not found: " + target);
-                writer.flush();
-            }
-        }
-
-        private void rnd(
-                final HttpServletRequest request,
-                final HttpServletResponse response) throws IOException {
-            int count = 100;
-            String s = request.getParameter("c");
-            try {
-                count = Integer.parseInt(s);
-            } catch (NumberFormatException ex) {
-                response.setStatus(500);
-                Writer writer = response.getWriter();
-                writer.write("Invalid query format: " + request.getQueryString());
-                writer.flush();
-                return;
-            }
-
-            response.setStatus(200);
-            response.setContentLength(count);
-
-            OutputStream outstream = response.getOutputStream();
-            byte[] tmp = new byte[1024];
-            int r = Math.abs(tmp.hashCode());
-            int remaining = count;
-            while (remaining > 0) {
-                int chunk = Math.min(tmp.length, remaining);
-                for (int i = 0; i < chunk; i++) {
-                    tmp[i] = (byte) ((r + i) % 96 + 32);
-                }
-                outstream.write(tmp, 0, chunk);
-                remaining -= chunk;
-            }
-            outstream.flush();
-        }
-
-        private void echo(
-                final HttpServletRequest request,
-                final HttpServletResponse response) throws IOException {
-
-            ByteArrayOutputStream2 buffer = new ByteArrayOutputStream2();
-            InputStream instream = request.getInputStream();
-            if (instream != null) {
-                IO.copy(instream, buffer);
-                buffer.flush();
-            }
-            byte[] content = buffer.getBuf();
-            int len = buffer.getCount();
-
-            response.setStatus(200);
-            response.setContentLength(len);
-
-            OutputStream outstream = response.getOutputStream();
-            outstream.write(content, 0, len);
-            outstream.flush();
-        }
-
+    public static void main(final String[] args) throws Exception {
+        final Config config = BenchRunner.parseConfig(args);
+        if (config.getUri() == null) {
+            System.err.println("Please specify a target URI");
+            System.exit(-1);
+        }
+        System.out.println("Running benchmark against " + config.getUri());
+        BenchRunner.run(new HttpJRE(), config);
+        BenchRunner.run(new ApacheHttpClient(), config);
+        BenchRunner.run(new JettyHttpClient(), config);
+        BenchRunner.run(new ApacheHttpClient(), config);
+        BenchRunner.run(new NingHttpClient(), config);
     }
 
 }

Copied: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/Config.java
(from r1499525, httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java)
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/Config.java?p2=httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/Config.java&p1=httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java&r1=1499525&r2=1499526&rev=1499526&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java
(original)
+++ httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/Config.java
Wed Jul  3 19:14:57 2013
@@ -27,16 +27,60 @@ package org.apache.http.client.benchmark
 
 import java.net.URI;
 
-public interface TestHttpAgent {
+public final class Config {
 
-    void init() throws Exception;
+    private URI uri;
+    private int requests;
+    private int concurrency;
+    private boolean keepAlive;
+    private int contentLength;
+
+    public Config() {
+        super();
+        this.requests = 1;
+        this.concurrency = 1;
+        this.contentLength = 2048;
+        this.keepAlive = false;
+    }
+
+    public URI getUri() {
+        return uri;
+    }
+
+    public void setUri(final URI uri) {
+        this.uri = uri;
+    }
+
+    public int getRequests() {
+        return requests;
+    }
+
+    public void setRequests(final int requests) {
+        this.requests = requests;
+    }
+
+    public int getConcurrency() {
+        return concurrency;
+    }
+
+    public void setConcurrency(final int concurrency) {
+        this.concurrency = concurrency;
+    }
+
+    public boolean isKeepAlive() {
+        return keepAlive;
+    }
+
+    public void setKeepAlive(final boolean keepAlive) {
+        this.keepAlive = keepAlive;
+    }
+
+    public int getContentLength() {
+        return contentLength;
+    }
+
+    public void setContentLength(final int contentLength) {
+        this.contentLength = contentLength;
+    }
 
-    void shutdown() throws Exception;
-
-    String getClientName();
-
-    Stats get(URI target, int n, int c) throws Exception;
-
-    Stats post(URI target, byte[] content, int n, int c) throws Exception;
-
-}
\ No newline at end of file
+}

Copied: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpAgent.java
(from r1499525, httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java)
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpAgent.java?p2=httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpAgent.java&p1=httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java&r1=1499525&r2=1499526&rev=1499526&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java
(original)
+++ httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpAgent.java
Wed Jul  3 19:14:57 2013
@@ -27,7 +27,7 @@ package org.apache.http.client.benchmark
 
 import java.net.URI;
 
-public interface TestHttpAgent {
+public interface HttpAgent {
 
     void init() throws Exception;
 

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpAgent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpAgent.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpAgent.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpJRE.java
(from r1499525, httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java)
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpJRE.java?p2=httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpJRE.java&p1=httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java&r1=1499525&r2=1499526&rev=1499526&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java
(original)
+++ httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpJRE.java
Wed Jul  3 19:14:57 2013
@@ -32,9 +32,9 @@ import java.net.HttpURLConnection;
 import java.net.URI;
 import java.net.URL;
 
-public class TestHttpJRE implements TestHttpAgent {
+public class HttpJRE implements HttpAgent {
 
-    public TestHttpJRE() {
+    public HttpJRE() {
         super();
     }
 
@@ -132,29 +132,9 @@ public class TestHttpJRE implements Test
         return "JRE HTTP " + System.getProperty("java.version");
     }
 
-    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]);
-        }
-
-        TestHttpJRE test = new TestHttpJRE();
-        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();
-        }
+    public static void main(final String[] args) throws Exception {
+        final Config config = BenchRunner.parseConfig(args);
+        BenchRunner.run(new HttpJRE(), config);
     }
 
 }
\ No newline at end of file

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpJRE.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpJRE.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/HttpJRE.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/JettyHttpClient.java
(from r1499525, httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java)
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/JettyHttpClient.java?p2=httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/JettyHttpClient.java&p1=httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java&r1=1499525&r2=1499526&rev=1499526&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
(original)
+++ httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/JettyHttpClient.java
Wed Jul  3 19:14:57 2013
@@ -34,11 +34,11 @@ import org.eclipse.jetty.io.Buffer;
 import org.eclipse.jetty.io.ByteArrayBuffer;
 import org.eclipse.jetty.server.Server;
 
-public class TestJettyHttpClient implements TestHttpAgent {
+public class JettyHttpClient implements HttpAgent {
 
     private final HttpClient client;
 
-    public TestJettyHttpClient() {
+    public JettyHttpClient() {
         super();
         this.client = new HttpClient();
         this.client.setRequestBufferSize(8 * 1024);
@@ -139,29 +139,9 @@ public class TestJettyHttpClient impleme
 
     }
 
-    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]);
-        }
-
-        TestJettyHttpClient test = new TestJettyHttpClient();
-        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();
-        }
+    public static void main(final String[] args) throws Exception {
+        final Config config = BenchRunner.parseConfig(args);
+        BenchRunner.run(new JettyHttpClient(), config);
     }
 
 }
\ No newline at end of file

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/JettyHttpClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/JettyHttpClient.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/JettyHttpClient.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/NingHttpClient.java
(from r1499525, httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java)
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/NingHttpClient.java?p2=httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/NingHttpClient.java&p1=httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java&r1=1499525&r2=1499526&rev=1499526&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
(original)
+++ httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/NingHttpClient.java
Wed Jul  3 19:14:57 2013
@@ -36,11 +36,11 @@ import com.ning.http.client.HttpResponse
 import com.ning.http.client.HttpResponseStatus;
 import com.ning.http.client.Request;
 
-public class TestNingHttpClient implements TestHttpAgent {
+public class NingHttpClient implements HttpAgent {
 
     private AsyncHttpClient client;
 
-    public TestNingHttpClient() {
+    public NingHttpClient() {
         super();
     }
 
@@ -137,29 +137,9 @@ public class TestNingHttpClient implemen
 
     }
 
-    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();
-        }
+    public static void main(final String[] args) throws Exception {
+        final Config config = BenchRunner.parseConfig(args);
+        BenchRunner.run(new NingHttpClient(), config);
     }
 
 }
\ No newline at end of file

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/NingHttpClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/NingHttpClient.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/benchmark/httpclient/branches/4.2.x/src/main/java/org/apache/http/client/benchmark/NingHttpClient.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message