hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1478314 - in /httpcomponents/benchmark/httpclient/trunk: ./ src/main/java/org/apache/http/client/benchmark/
Date Thu, 02 May 2013 10:28:19 GMT
Author: olegk
Date: Thu May  2 10:28:18 2013
New Revision: 1478314

URL: http://svn.apache.org/r1478314
Log:
Code formatting and cleanup

Added:
    httpcomponents/benchmark/httpclient/trunk/.gitignore
Modified:
    httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/Benchmark.java
    httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/Stats.java
    httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java
    httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
    httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java

Added: httpcomponents/benchmark/httpclient/trunk/.gitignore
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/trunk/.gitignore?rev=1478314&view=auto
==============================================================================
--- httpcomponents/benchmark/httpclient/trunk/.gitignore (added)
+++ httpcomponents/benchmark/httpclient/trunk/.gitignore Thu May  2 10:28:18 2013
@@ -0,0 +1,7 @@
+.classpath
+.project
+.settings
+.pydevproject
+.clover
+target
+maven-eclipse.xml

Modified: httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/Benchmark.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/Benchmark.java?rev=1478314&r1=1478313&r2=1478314&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/Benchmark.java
(original)
+++ httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/Benchmark.java
Thu May  2 10:28:18 2013
@@ -47,40 +47,40 @@ public class Benchmark {
 
     public static void main(final 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);
+        final String ns = System.getProperty("hc.benchmark.n-requests", "200000");
+        final String nc = System.getProperty("hc.benchmark.concurrent", "20");
+        final String cls = System.getProperty("hc.benchmark.content-len", "2048");
+
+        final int n = Integer.parseInt(ns);
+        final int c = Integer.parseInt(nc);
+        final int contentLen = Integer.parseInt(cls);
 
-        SelectChannelConnector connector = new SelectChannelConnector();
-        Server server = new Server();
+        final SelectChannelConnector connector = new SelectChannelConnector();
+        final Server server = new Server();
         server.addConnector(connector);
         server.setHandler(new RandomDataHandler());
 
         server.start();
-        int port = connector.getLocalPort();
+        final int port = connector.getLocalPort();
 
-        TestHttpAgent[] agents = new TestHttpAgent[] {
+        final TestHttpAgent[] agents = new TestHttpAgent[] {
                 new TestHttpJRE(),
                 new TestApacheHttpClient(),
                 new TestJettyHttpClient(),
                 new TestNingHttpClient()
         };
 
-        byte[] content = new byte[contentLen];
-        int r = Math.abs(content.hashCode());
+        final byte[] content = new byte[contentLen];
+        final 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 target = new URI("http", null, "localhost", port, "/echo", null, null);
+        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 {
-            for (TestHttpAgent agent: agents) {
+            for (final TestHttpAgent agent: agents) {
                 try {
                     agent.init();
                     // Warm up
@@ -94,9 +94,9 @@ public class Benchmark {
                     System.out.println(n + " POST requests");
                     System.out.println("---------------------------------");
 
-                    long startTime = System.currentTimeMillis();
-                    Stats stats = agent.post(target, content, n, c);
-                    long finishTime = System.currentTimeMillis();
+                    final long startTime = System.currentTimeMillis();
+                    final Stats stats = agent.post(target, content, n, c);
+                    final long finishTime = System.currentTimeMillis();
                     Stats.printStats(target, startTime, finishTime, stats);
                 } finally {
                     agent.shutdown();
@@ -127,7 +127,7 @@ public class Benchmark {
                 echo(request, response);
             } else {
                 response.setStatus(HttpStatus.NOT_FOUND_404);
-                Writer writer = response.getWriter();
+                final Writer writer = response.getWriter();
                 writer.write("Target not found: " + target);
                 writer.flush();
             }
@@ -137,12 +137,12 @@ public class Benchmark {
                 final HttpServletRequest request,
                 final HttpServletResponse response) throws IOException {
             int count = 100;
-            String s = request.getParameter("c");
+            final String s = request.getParameter("c");
             try {
                 count = Integer.parseInt(s);
-            } catch (NumberFormatException ex) {
+            } catch (final NumberFormatException ex) {
                 response.setStatus(500);
-                Writer writer = response.getWriter();
+                final Writer writer = response.getWriter();
                 writer.write("Invalid query format: " + request.getQueryString());
                 writer.flush();
                 return;
@@ -151,12 +151,12 @@ public class Benchmark {
             response.setStatus(200);
             response.setContentLength(count);
 
-            OutputStream outstream = response.getOutputStream();
-            byte[] tmp = new byte[1024];
-            int r = Math.abs(tmp.hashCode());
+            final OutputStream outstream = response.getOutputStream();
+            final byte[] tmp = new byte[1024];
+            final int r = Math.abs(tmp.hashCode());
             int remaining = count;
             while (remaining > 0) {
-                int chunk = Math.min(tmp.length, remaining);
+                final int chunk = Math.min(tmp.length, remaining);
                 for (int i = 0; i < chunk; i++) {
                     tmp[i] = (byte) ((r + i) % 96 + 32);
                 }
@@ -170,18 +170,18 @@ public class Benchmark {
                 final HttpServletRequest request,
                 final HttpServletResponse response) throws IOException {
 
-            ByteArrayOutputStream2 buffer = new ByteArrayOutputStream2();
-            InputStream instream = request.getInputStream();
+            final ByteArrayOutputStream2 buffer = new ByteArrayOutputStream2();
+            final InputStream instream = request.getInputStream();
             if (instream != null) {
                 IO.copy(instream, buffer);
                 buffer.flush();
             }
-            byte[] content = buffer.getBuf();
+            final byte[] content = buffer.getBuf();
 
             response.setStatus(200);
             response.setContentLength(content.length);
 
-            OutputStream outstream = response.getOutputStream();
+            final OutputStream outstream = response.getOutputStream();
             outstream.write(content);
             outstream.flush();
         }

Modified: httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/Stats.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/Stats.java?rev=1478314&r1=1478313&r2=1478314&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/Stats.java
(original)
+++ httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/Stats.java
Thu May  2 10:28:18 2013
@@ -37,7 +37,7 @@ public class Stats {
     private long contentLen = 0;
     private long totalContentLen = 0;
 
-    public Stats(int expectedCount, int concurrency) {
+    public Stats(final int expectedCount, final int concurrency) {
         super();
         this.expectedCount = expectedCount;
         this.concurrency = concurrency;
@@ -47,7 +47,7 @@ public class Stats {
         return this.successCount + this.failureCount >= this.expectedCount;
     }
 
-    public synchronized void success(long contentLen) {
+    public synchronized void success(final long contentLen) {
         if (isComplete()) return;
         this.successCount++;
         this.contentLen = contentLen;
@@ -55,7 +55,7 @@ public class Stats {
         notifyAll();
     }
 
-    public synchronized void failure(long contentLen) {
+    public synchronized void failure(final long contentLen) {
         if (isComplete()) return;
         this.failureCount++;
         this.contentLen = contentLen;
@@ -90,9 +90,9 @@ public class Stats {
     }
 
     public static void printStats(
-            final URI targetURI, long startTime, long finishTime, final Stats stats) {
-        float totalTimeSec = (float) (finishTime - startTime) / 1000;
-        float reqsPerSec = (float) stats.getSuccessCount() / totalTimeSec;
+            final URI targetURI, final long startTime, final long finishTime, final Stats
stats) {
+        final float totalTimeSec = (float) (finishTime - startTime) / 1000;
+        final float reqsPerSec = stats.getSuccessCount() / totalTimeSec;
 
         System.out.print("Document URI:\t\t");
         System.out.println(targetURI);

Modified: httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java?rev=1478314&r1=1478313&r2=1478314&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java
(original)
+++ httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java
Thu May  2 10:28:18 2013
@@ -38,17 +38,19 @@ public class TestHttpJRE implements Test
         super();
     }
 
+    @Override
     public void init() {
     }
 
+    @Override
     public void shutdown() {
     }
 
-    Stats execute(final URI targetURI, byte[] content, int n, int c) throws Exception {
+    Stats execute(final URI targetURI, final byte[] content, final int n, final int c) throws
Exception {
         System.setProperty("http.maxConnections", Integer.toString(c));
-        URL target = targetURI.toURL();
-        Stats stats = new Stats(n, c);
-        WorkerThread[] workers = new WorkerThread[c];
+        final URL target = targetURI.toURL();
+        final Stats stats = new Stats(n, c);
+        final WorkerThread[] workers = new WorkerThread[c];
         for (int i = 0; i < workers.length; i++) {
             workers[i] = new WorkerThread(stats, target, content);
         }
@@ -76,11 +78,11 @@ public class TestHttpJRE implements Test
 
         @Override
         public void run() {
-            byte[] buffer = new byte[4096];
+            final byte[] buffer = new byte[4096];
             while (!this.stats.isComplete()) {
                 long contentLen = 0;
                 try {
-                    HttpURLConnection conn = (HttpURLConnection) this.target.openConnection();
+                    final HttpURLConnection conn = (HttpURLConnection) this.target.openConnection();
                     conn.setReadTimeout(15000);
 
                     if (this.content != null) {
@@ -89,7 +91,7 @@ public class TestHttpJRE implements Test
                         conn.setUseCaches (false);
                         conn.setDoInput(true);
                         conn.setDoOutput(true);
-                        OutputStream out = conn.getOutputStream();
+                        final OutputStream out = conn.getOutputStream();
                         try {
                             out.write(this.content);
                             out.flush ();
@@ -97,7 +99,7 @@ public class TestHttpJRE implements Test
                             out.close();
                         }
                     }
-                    InputStream instream = conn.getInputStream();
+                    final InputStream instream = conn.getInputStream();
                     if (instream != null) {
                         try {
                             int l = 0;
@@ -113,43 +115,46 @@ public class TestHttpJRE implements Test
                     } else {
                         this.stats.failure(contentLen);
                     }
-                } catch (IOException ex) {
+                } catch (final IOException ex) {
                     this.stats.failure(contentLen);
                 }
             }
         }
     }
 
-    public Stats get(final URI target, int n, int c) throws Exception {
+    @Override
+    public Stats get(final URI target, final int n, final int c) throws Exception {
         return execute(target, null, n, c);
     }
 
-    public Stats post(final URI target, byte[] content, int n, int c) throws Exception {
+    @Override
+    public Stats post(final URI target, final byte[] content, final int n, final int c) throws
Exception {
         return execute(target, content, n, c);
     }
 
+    @Override
     public String getClientName() {
         return "JRE HTTP " + System.getProperty("java.version");
     }
 
-    public static void main(String[] args) throws Exception {
+    public static void main(final 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]);
+        final URI targetURI = new URI(args[0]);
+        final int n = Integer.parseInt(args[1]);
         int c = 1;
         if (args.length > 2) {
             c = Integer.parseInt(args[2]);
         }
 
-        TestHttpJRE test = new TestHttpJRE();
+        final TestHttpJRE test = new TestHttpJRE();
         test.init();
         try {
-            long startTime = System.currentTimeMillis();
-            Stats stats = test.get(targetURI, n, c);
-            long finishTime = System.currentTimeMillis();
+            final long startTime = System.currentTimeMillis();
+            final Stats stats = test.get(targetURI, n, c);
+            final long finishTime = System.currentTimeMillis();
 
             Stats.printStats(targetURI, startTime, finishTime, stats);
         } finally {

Modified: httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java?rev=1478314&r1=1478313&r2=1478314&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
(original)
+++ httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
Thu May  2 10:28:18 2013
@@ -47,20 +47,22 @@ public class TestJettyHttpClient impleme
         this.client.setTimeout(15000);
     }
 
+    @Override
     public void init() throws Exception {
         this.client.start();
     }
 
+    @Override
     public void shutdown() throws Exception {
         this.client.stop();
     }
 
-    Stats execute(final URI targetURI, byte[] content, int n, int c) throws Exception {
+    Stats execute(final URI targetURI, final byte[] content, final int n, final int c) throws
Exception {
         this.client.setMaxConnectionsPerAddress(c);
-        Stats stats = new Stats(n, c);
+        final Stats stats = new Stats(n, c);
 
         for (int i = 0; i < n; i++) {
-            SimpleHttpExchange exchange = new SimpleHttpExchange(stats);
+            final SimpleHttpExchange exchange = new SimpleHttpExchange(stats);
             exchange.setURL(targetURI.toASCIIString());
 
             if (content != null) {
@@ -69,7 +71,7 @@ public class TestJettyHttpClient impleme
             }
             try {
                 this.client.send(exchange);
-            } catch (IOException ex) {
+            } catch (final IOException ex) {
                 stats.failure(0L);
             }
         }
@@ -77,14 +79,17 @@ public class TestJettyHttpClient impleme
         return stats;
     }
 
-    public Stats get(final URI target, int n, int c) throws Exception {
+    @Override
+    public Stats get(final URI target, final int n, final int c) throws Exception {
         return execute(target, null, n, c);
     }
 
-    public Stats post(final URI target, byte[] content, int n, int c) throws Exception {
+    @Override
+    public Stats post(final URI target, final byte[] content, final int n, final int c) throws
Exception {
         return execute(target, content, n, c);
     }
 
+    @Override
     public String getClientName() {
         return "Jetty " + Server.getVersion();
     }
@@ -102,14 +107,14 @@ public class TestJettyHttpClient impleme
 
         @Override
         protected void onResponseStatus(
-                final Buffer version, int status, final Buffer reason) throws IOException
{
+                final Buffer version, final int status, final Buffer reason) throws IOException
{
             this.status = status;
             super.onResponseStatus(version, status, reason);
         }
 
         @Override
         protected void onResponseContent(final Buffer content) throws IOException {
-            byte[] tmp = new byte[content.length()];
+            final byte[] tmp = new byte[content.length()];
             content.get(tmp, 0, tmp.length);
             this.contentLen += tmp.length;
             super.onResponseContent(content);
@@ -139,24 +144,24 @@ public class TestJettyHttpClient impleme
 
     }
 
-    public static void main(String[] args) throws Exception {
+    public static void main(final 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]);
+        final URI targetURI = new URI(args[0]);
+        final int n = Integer.parseInt(args[1]);
         int c = 1;
         if (args.length > 2) {
             c = Integer.parseInt(args[2]);
         }
 
-        TestJettyHttpClient test = new TestJettyHttpClient();
+        final TestJettyHttpClient test = new TestJettyHttpClient();
         test.init();
         try {
-            long startTime = System.currentTimeMillis();
-            Stats stats = test.get(targetURI, n, c);
-            long finishTime = System.currentTimeMillis();
+            final long startTime = System.currentTimeMillis();
+            final Stats stats = test.get(targetURI, n, c);
+            final long finishTime = System.currentTimeMillis();
 
             Stats.printStats(targetURI, startTime, finishTime, stats);
         } finally {

Modified: httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java?rev=1478314&r1=1478313&r2=1478314&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
(original)
+++ httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestNingHttpClient.java
Thu May  2 10:28:18 2013
@@ -44,18 +44,20 @@ public class TestNingHttpClient implemen
         super();
     }
 
+    @Override
     public void init() throws Exception {
     }
 
+    @Override
     public void shutdown() throws Exception {
         this.client.close();
     }
 
-    Stats execute(final URI targetURI, byte[] content, int n, int c) throws Exception {
+    Stats execute(final URI targetURI, final byte[] content, final int n, final int c) throws
Exception {
         if (this.client != null) {
             this.client.close();
         }
-        AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()
+        final AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()
             .setAllowPoolingConnection(true)
             .setCompressionEnabled(false)
             .setMaximumConnectionsPerHost(c)
@@ -64,7 +66,7 @@ public class TestNingHttpClient implemen
             .build();
         this.client = new AsyncHttpClient(config);
 
-        Stats stats = new Stats(n, c);
+        final Stats stats = new Stats(n, c);
 
         for (int i = 0; i < n; i++) {
             Request request;
@@ -78,21 +80,24 @@ public class TestNingHttpClient implemen
             }
             try {
                 this.client.executeRequest(request, new SimpleAsyncHandler(stats));
-            } catch (IOException ex) {
+            } catch (final IOException ex) {
             }
         }
         stats.waitFor();
         return stats;
     }
 
-    public Stats get(final URI target, int n, int c) throws Exception {
+    @Override
+    public Stats get(final URI target, final int n, final int c) throws Exception {
         return execute(target, null, n, c);
     }
 
-    public Stats post(final URI target, byte[] content, int n, int c) throws Exception {
+    @Override
+    public Stats post(final URI target, final byte[] content, final int n, final int c) throws
Exception {
         return execute(target, content, n, c);
     }
 
+    @Override
     public String getClientName() {
         return "Ning async HTTP client 1.7.12";
     }
@@ -108,20 +113,24 @@ public class TestNingHttpClient implemen
             this.stats = stats;
         }
 
+        @Override
         public STATE onStatusReceived(final HttpResponseStatus responseStatus) throws Exception
{
             this.status = responseStatus.getStatusCode();
             return STATE.CONTINUE;
         }
 
+        @Override
         public STATE onHeadersReceived(final HttpResponseHeaders headers) throws Exception
{
             return STATE.CONTINUE;
         }
 
+        @Override
         public STATE onBodyPartReceived(final HttpResponseBodyPart bodyPart) throws Exception
{
             this.contentLen += bodyPart.getBodyPartBytes().length;
             return STATE.CONTINUE;
         }
 
+        @Override
         public Object onCompleted() throws Exception {
             if (this.status == 200) {
                 this.stats.success(this.contentLen);
@@ -131,30 +140,31 @@ public class TestNingHttpClient implemen
             return STATE.CONTINUE;
         }
 
+        @Override
         public void onThrowable(final Throwable t) {
             this.stats.failure(this.contentLen);
         }
 
     }
 
-    public static void main(String[] args) throws Exception {
+    public static void main(final 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]);
+        final URI targetURI = new URI(args[0]);
+        final int n = Integer.parseInt(args[1]);
         int c = 1;
         if (args.length > 2) {
             c = Integer.parseInt(args[2]);
         }
 
-        TestNingHttpClient test = new TestNingHttpClient();
+        final TestNingHttpClient test = new TestNingHttpClient();
         test.init();
         try {
-            long startTime = System.currentTimeMillis();
-            Stats stats = test.get(targetURI, n, c);
-            long finishTime = System.currentTimeMillis();
+            final long startTime = System.currentTimeMillis();
+            final Stats stats = test.get(targetURI, n, c);
+            final long finishTime = System.currentTimeMillis();
 
             Stats.printStats(targetURI, startTime, finishTime, stats);
         } finally {



Mime
View raw message