hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r762128 - in /httpcomponents/httpclient/trunk/httpclient-benchmark: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/http/ src/main/java/org/apache/http/client/ src/main/java/org/apache/...
Date Sun, 05 Apr 2009 18:04:27 GMT
Author: olegk
Date: Sun Apr  5 18:04:27 2009
New Revision: 762128

URL: http://svn.apache.org/viewvc?rev=762128&view=rev
Log:
Added HttpClient Benchmark module

Added:
    httpcomponents/httpclient/trunk/httpclient-benchmark/
    httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml   (with props)
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient3.java
  (with props)
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
  (with props)
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
  (with props)
    httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java
  (with props)

Added: httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml?rev=762128&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml (added)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml Sun Apr  5 18:04:27 2009
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   $HeadURL:$
+   $Revision:$
+   $Date:$
+
+   ====================================================================
+   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 />.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.httpcomponents</groupId>
+    <artifactId>httpcomponents-client</artifactId>
+    <version>4.0-beta3-SNAPSHOT</version>
+  </parent>
+  <artifactId>httpclient-benchmark</artifactId>
+  <name>HttpClient Benchmarks</name>
+  <description>
+   HttpComponents HttpClient - Benchmarks
+  </description>
+  <url>http://hc.apache.org/httpcomponents-client</url>
+  <packaging>jar</packaging>  
+
+  <licenses>
+    <license>
+      <name>Apache License</name>
+      <url>../LICENSE.txt</url>
+      <distribution>repo</distribution>
+    </license>
+  </licenses>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>${pom.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-httpclient</groupId>
+      <artifactId>commons-httpclient</artifactId>
+      <version>3.1</version>
+    </dependency>
+  </dependencies>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+    <maven.compile.source>1.5</maven.compile.source>
+    <maven.compile.target>1.5</maven.compile.target>
+    <maven.compile.optimize>true</maven.compile.optimize>
+    <maven.compile.deprecation>true</maven.compile.deprecation>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>${maven.compile.source}</source>
+          <target>${maven.compile.target}</target>
+          <optimize>${maven.compile.optimize}</optimize>
+          <showDeprecations>${maven.compile.deprecation}</showDeprecations>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient3.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient3.java?rev=762128&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient3.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient3.java
Sun Apr  5 18:04:27 2009
@@ -0,0 +1,102 @@
+package org.apache.http.client.benchmark;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+
+public class TestHttpClient3 {
+
+    public static void main(String[] args) throws Exception {
+        if (args.length < 2) {
+            System.out.println("Usage: <target URI> <no of requests>");
+            System.exit(-1);
+        }
+        String targetURI = args[0];
+        int n = Integer.parseInt(args[1]);
+        
+        HttpClient httpclient = new HttpClient();
+        httpclient.getParams().setVersion(
+                HttpVersion.HTTP_1_1);
+        httpclient.getParams().setBooleanParameter(
+                HttpMethodParams.USE_EXPECT_CONTINUE, false);
+        httpclient.getHttpConnectionManager().getParams()
+                .setStaleCheckingEnabled(false);
+        
+        GetMethod httpget = new GetMethod(targetURI);
+
+        byte[] buffer = new byte[4096];
+        
+        long startTime;
+        long finishTime;
+        int successCount = 0;
+        int failureCount = 0;
+        String serverName = "unknown";
+        long total = 0;
+        long contentLen = 0;
+        long totalContentLen = 0;
+        
+        startTime = System.currentTimeMillis();
+        for (int i = 0; i < n; i++) {
+            try {
+                httpclient.executeMethod(httpget);
+                InputStream instream = httpget.getResponseBodyAsStream();
+                contentLen = 0;
+                if (instream != null) {
+                    int l = 0;
+                    while ((l = instream.read(buffer)) != -1) {
+                        total += l;
+                        contentLen += l;
+                    }
+                }
+                successCount++;
+                totalContentLen += contentLen;
+            } catch (IOException ex) {
+                failureCount++;
+            } finally {
+                httpget.releaseConnection();
+            }
+        }
+        finishTime = System.currentTimeMillis();
+        
+        Header header = httpget.getResponseHeader("Server");
+        if (header != null) {
+            serverName = header.getValue();
+        }
+        
+        float totalTimeSec = (float) (finishTime - startTime) / 1000;
+        float reqsPerSec = (float) successCount / totalTimeSec; 
+        float timePerReqMs = (float) (finishTime - startTime) / (float) successCount; 
+        
+        System.out.print("Server Software:\t");
+        System.out.println(serverName);
+        System.out.println();
+        System.out.print("Document URI:\t\t");
+        System.out.println(targetURI);
+        System.out.print("Document Length:\t");
+        System.out.print(contentLen);
+        System.out.println(" bytes");
+        System.out.println();
+        System.out.print("Time taken for tests:\t");
+        System.out.print(totalTimeSec);
+        System.out.println(" seconds");
+        System.out.print("Complete requests:\t");
+        System.out.println(successCount);
+        System.out.print("Failed requests:\t");
+        System.out.println(failureCount);
+        System.out.print("Content transferred:\t");
+        System.out.print(total);
+        System.out.println(" bytes");
+        System.out.print("Requests per second:\t");
+        System.out.print(reqsPerSec);
+        System.out.println(" [#/sec] (mean)");
+        System.out.print("Time per request:\t");
+        System.out.print(timePerReqMs);
+        System.out.println(" [ms] (mean)");
+    }
+
+}

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

Propchange: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient3.java
------------------------------------------------------------------------------
    svn:executable = *

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

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

Added: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java?rev=762128&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
Sun Apr  5 18:04:27 2009
@@ -0,0 +1,113 @@
+package org.apache.http.client.benchmark;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpProtocolParams;
+
+public class TestHttpClient4 {
+
+    public static void main(String[] args) throws Exception {
+        if (args.length < 2) {
+            System.out.println("Usage: <target URI> <no of requests>");
+            System.exit(-1);
+        }
+        String targetURI = args[0];
+        int n = Integer.parseInt(args[1]);
+       
+        BasicHttpParams params = new BasicHttpParams();
+        params.setParameter(HttpProtocolParams.PROTOCOL_VERSION,
+                HttpVersion.HTTP_1_1);
+        params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE,
+                false);
+        params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK,
+                false);
+        params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE,
+                8 * 1024);
+       
+        DefaultHttpClient httpclient = new DefaultHttpClient(params);
+       
+        HttpGet httpget = new HttpGet(targetURI);
+
+        byte[] buffer = new byte[4096];
+       
+        long startTime;
+        long finishTime;
+        int successCount = 0;
+        int failureCount = 0;
+        String serverName = "unknown";
+        long total = 0;
+        long contentLen = 0;
+        long totalContentLen = 0;
+       
+        startTime = System.currentTimeMillis();
+        for (int i = 0; i < n; i++) {
+            HttpResponse response = httpclient.execute(httpget);
+            HttpEntity entity = response.getEntity();
+            if (entity != null) {
+                InputStream instream = entity.getContent();
+                try {
+                    contentLen = 0;
+                    if (instream != null) {
+                        int l = 0;
+                        while ((l = instream.read(buffer)) != -1) {
+                            total += l;
+                            contentLen += l;
+                        }
+                    }
+                    successCount++;
+                    totalContentLen += contentLen;
+                } catch (IOException ex) {
+                    httpget.abort();
+                    failureCount++;
+                } finally {
+                    instream.close();
+                }
+            }
+            Header header = response.getFirstHeader("Server");
+            if (header != null) {
+                serverName = header.getValue();
+            }
+        }
+        finishTime = System.currentTimeMillis();
+       
+        float totalTimeSec = (float) (finishTime - startTime) / 1000;
+        float reqsPerSec = (float) successCount / totalTimeSec;
+        float timePerReqMs = (float) (finishTime - startTime) / (float) successCount;
+       
+        System.out.print("Server Software:\t");
+        System.out.println(serverName);
+        System.out.println();
+        System.out.print("Document URI:\t\t");
+        System.out.println(targetURI);
+        System.out.print("Document Length:\t");
+        System.out.print(contentLen);
+        System.out.println(" bytes");
+        System.out.println();
+        System.out.print("Time taken for tests:\t");
+        System.out.print(totalTimeSec);
+        System.out.println(" seconds");
+        System.out.print("Complete requests:\t");
+        System.out.println(successCount);
+        System.out.print("Failed requests:\t");
+        System.out.println(failureCount);
+        System.out.print("Content transferred:\t");
+        System.out.print(total);
+        System.out.println(" bytes");
+        System.out.print("Requests per second:\t");
+        System.out.print(reqsPerSec);
+        System.out.println(" [#/sec] (mean)");
+        System.out.print("Time per request:\t");
+        System.out.print(timePerReqMs);
+        System.out.println(" [ms] (mean)");
+    }
+   
+} 
\ No newline at end of file

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

Propchange: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
------------------------------------------------------------------------------
    svn:executable = *

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

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

Added: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java?rev=762128&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
Sun Apr  5 18:04:27 2009
@@ -0,0 +1,161 @@
+package org.apache.http.client.benchmark;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.Socket;
+import java.net.URI;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultHttpClientConnection;
+import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.BasicHttpProcessor;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpRequestExecutor;
+import org.apache.http.protocol.RequestConnControl;
+import org.apache.http.protocol.RequestContent;
+import org.apache.http.protocol.RequestExpectContinue;
+import org.apache.http.protocol.RequestTargetHost;
+import org.apache.http.protocol.RequestUserAgent;
+
+public class TestHttpCore {
+
+    public static void main(String[] args) throws Exception {
+        if (args.length < 2) {
+            System.out.println("Usage: <target URI> <no of requests>");
+            System.exit(-1);
+        }
+        URI targetURI = new URI(args[0]);
+        int n = Integer.parseInt(args[1]);
+       
+        HttpHost targetHost = new HttpHost(
+                targetURI.getHost(),
+                targetURI.getPort());
+       
+        BasicHttpParams params = new BasicHttpParams();
+        params.setParameter(HttpProtocolParams.PROTOCOL_VERSION,
+                HttpVersion.HTTP_1_1);
+        params.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE,
+                false);
+        params.setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK,
+                false);
+        params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE,
+                8 * 1024);
+       
+        BasicHttpRequest httpget = new BasicHttpRequest("GET", targetURI.getPath());
+
+        byte[] buffer = new byte[4096];
+       
+        long startTime;
+        long finishTime;
+        int successCount = 0;
+        int failureCount = 0;
+        String serverName = "unknown";
+        long total = 0;
+        long contentLen = 0;
+        long totalContentLen = 0;
+       
+        HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
+        BasicHttpProcessor httpproc = new BasicHttpProcessor();
+        // Required protocol interceptors
+        httpproc.addInterceptor(new RequestContent());
+        httpproc.addInterceptor(new RequestTargetHost());
+        // Recommended protocol interceptors
+        httpproc.addInterceptor(new RequestConnControl());
+        httpproc.addInterceptor(new RequestUserAgent());
+        httpproc.addInterceptor(new RequestExpectContinue());
+       
+        HttpContext context = new BasicHttpContext();
+
+        DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
+
+        DefaultConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();
+       
+        startTime = System.currentTimeMillis();
+        for (int i = 0; i < n; i++) {
+            if (!conn.isOpen()) {
+                Socket socket = new Socket(
+                        targetHost.getHostName(),
+                        targetHost.getPort() > 0 ? targetHost.getPort() : 80);
+                conn.bind(socket, params);
+            }
+
+            context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+            context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, targetHost);
+
+            httpexecutor.preProcess(httpget, httpproc, context);
+            HttpResponse response = httpexecutor.execute(httpget, conn, context);
+            httpexecutor.postProcess(response, httpproc, context);
+           
+            HttpEntity entity = response.getEntity();
+            if (entity != null) {
+                InputStream instream = entity.getContent();
+                try {
+                    contentLen = 0;
+                    if (instream != null) {
+                        int l = 0;
+                        while ((l = instream.read(buffer)) != -1) {
+                            total += l;
+                            contentLen += l;
+                        }
+                    }
+                    successCount++;
+                    totalContentLen += contentLen;
+                } catch (IOException ex) {
+                    conn.shutdown();
+                    failureCount++;
+                } finally {
+                    instream.close();
+                }
+            }
+            if (!connStrategy.keepAlive(response, context)) {
+                conn.close();
+            }
+            Header header = response.getFirstHeader("Server");
+            if (header != null) {
+                serverName = header.getValue();
+            }
+        }
+        finishTime = System.currentTimeMillis();
+       
+        float totalTimeSec = (float) (finishTime - startTime) / 1000;
+        float reqsPerSec = (float) successCount / totalTimeSec;
+        float timePerReqMs = (float) (finishTime - startTime) / (float) successCount;
+       
+        System.out.print("Server Software:\t");
+        System.out.println(serverName);
+        System.out.println();
+        System.out.print("Document URI:\t\t");
+        System.out.println(targetURI);
+        System.out.print("Document Length:\t");
+        System.out.print(contentLen);
+        System.out.println(" bytes");
+        System.out.println();
+        System.out.print("Time taken for tests:\t");
+        System.out.print(totalTimeSec);
+        System.out.println(" seconds");
+        System.out.print("Complete requests:\t");
+        System.out.println(successCount);
+        System.out.print("Failed requests:\t");
+        System.out.println(failureCount);
+        System.out.print("Content transferred:\t");
+        System.out.print(total);
+        System.out.println(" bytes");
+        System.out.print("Requests per second:\t");
+        System.out.print(reqsPerSec);
+        System.out.println(" [#/sec] (mean)");
+        System.out.print("Time per request:\t");
+        System.out.print(timePerReqMs);
+        System.out.println(" [ms] (mean)");
+    }
+   
+}
\ No newline at end of file

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

Propchange: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
------------------------------------------------------------------------------
    svn:executable = *

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

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

Added: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java?rev=762128&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java
Sun Apr  5 18:04:27 2009
@@ -0,0 +1,93 @@
+package org.apache.http.client.benchmark;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.net.URL;
+
+public class TestHttpJRE {
+
+    public static void main(String[] args) throws Exception {
+        if (args.length < 2) {
+            System.out.println("Usage: <target URI> <no of requests>");
+            System.exit(-1);
+        }
+        URI targetURI = new URI(args[0]);
+        int n = Integer.parseInt(args[1]);
+       
+        URL url = targetURI.toURL();
+       
+        byte[] buffer = new byte[4096];
+       
+        long startTime;
+        long finishTime;
+        int successCount = 0;
+        int failureCount = 0;
+        String serverName = "unknown";
+        long total = 0;
+        long contentLen = 0;
+        long totalContentLen = 0;
+       
+        startTime = System.currentTimeMillis();
+        for (int i = 0; i < n; i++) {
+            HttpURLConnection c = (HttpURLConnection) url.openConnection();
+            c.connect();
+            InputStream instream = c.getInputStream();
+            try {
+                contentLen = 0;
+                if (instream != null) {
+                    int l = 0;
+                    while ((l = instream.read(buffer)) != -1) {
+                        total += l;
+                        contentLen += l;
+                    }
+                }
+                if (c.getResponseCode() == 200) {
+                    successCount++;
+                } else {
+                    failureCount++;
+                }
+                totalContentLen += contentLen;
+            } catch (IOException ex) {
+                failureCount++;
+            }
+            String s = c.getHeaderField("Server");
+            if (s != null) {
+                serverName = s;                
+            }
+        }
+        finishTime = System.currentTimeMillis();
+       
+        float totalTimeSec = (float) (finishTime - startTime) / 1000;
+        float reqsPerSec = (float) successCount / totalTimeSec;
+        float timePerReqMs = (float) (finishTime - startTime) / (float) successCount;
+       
+        System.out.print("Server Software:\t");
+        System.out.println(serverName);
+        System.out.println();
+        System.out.print("Document URI:\t\t");
+        System.out.println(targetURI);
+        System.out.print("Document Length:\t");
+        System.out.print(contentLen);
+        System.out.println(" bytes");
+        System.out.println();
+        System.out.print("Time taken for tests:\t");
+        System.out.print(totalTimeSec);
+        System.out.println(" seconds");
+        System.out.print("Complete requests:\t");
+        System.out.println(successCount);
+        System.out.print("Failed requests:\t");
+        System.out.println(failureCount);
+        System.out.print("Content transferred:\t");
+        System.out.print(total);
+        System.out.println(" bytes");
+        System.out.print("Requests per second:\t");
+        System.out.print(reqsPerSec);
+        System.out.println(" [#/sec] (mean)");
+        System.out.print("Time per request:\t");
+        System.out.print(timePerReqMs);
+        System.out.println(" [ms] (mean)");
+    }
+ 
+} 
\ No newline at end of file

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

Propchange: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java
------------------------------------------------------------------------------
    svn:executable = *

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

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



Mime
View raw message