You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2010/03/05 16:20:54 UTC
svn commit: r919446 - in
/httpcomponents/httpclient/trunk/httpclient-benchmark: ./
src/main/java/org/apache/http/client/benchmark/
Author: olegk
Date: Fri Mar 5 15:20:53 2010
New Revision: 919446
URL: http://svn.apache.org/viewvc?rev=919446&view=rev
Log:
Added Jetty HttpClient sample
Added:
httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java (with props)
Modified:
httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml
httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java
httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java
httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient3.java
httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java
httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java
Modified: httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml?rev=919446&r1=919445&r2=919446&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml (original)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/pom.xml Fri Mar 5 15:20:53 2010
@@ -76,6 +76,12 @@
<scope>compile</scope>
</dependency>
<dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-client</artifactId>
+ <version>7.0.1.v20091125</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.10</version>
Modified: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java?rev=919446&r1=919445&r2=919446&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Benchmark.java Fri Mar 5 15:20:53 2010
@@ -71,9 +71,14 @@
new TestHttpClient3(),
new TestHttpJRE(),
new TestHttpCore(),
- new TestHttpClient4()
+ new TestHttpClient4(),
+ new TestJettyHttpClient()
};
+ for (TestHttpAgent agent: agents) {
+ agent.init();
+ }
+
byte[] content = new byte[contentLen];
int r = Math.abs(content.hashCode());
for (int i = 0; i < content.length; i++) {
Modified: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java?rev=919446&r1=919445&r2=919446&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpAgent.java Fri Mar 5 15:20:53 2010
@@ -29,6 +29,8 @@
public interface TestHttpAgent {
+ void init() throws Exception;
+
String getClientName();
Stats get(URI target, int count) throws Exception;
Modified: 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=919446&r1=919445&r2=919446&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient3.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient3.java Fri Mar 5 15:20:53 2010
@@ -53,6 +53,9 @@
.setStaleCheckingEnabled(false);
}
+ public void init() {
+ }
+
public Stats execute(final HttpMethod httpmethod, int n) throws Exception {
Stats stats = new Stats();
Modified: 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=919446&r1=919445&r2=919446&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java Fri Mar 5 15:20:53 2010
@@ -64,6 +64,9 @@
this.httpclient = new DefaultHttpClient(params);
}
+ public void init() {
+ }
+
public Stats execute(final HttpUriRequest request, int n) throws Exception {
Stats stats = new Stats();
Modified: 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=919446&r1=919445&r2=919446&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpCore.java Fri Mar 5 15:20:53 2010
@@ -91,6 +91,9 @@
this.connStrategy = new DefaultConnectionReuseStrategy();
}
+ public void init() {
+ }
+
public Stats execute(
final HttpHost targetHost, final HttpRequest request, int n) throws Exception {
Modified: 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=919446&r1=919445&r2=919446&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpJRE.java Fri Mar 5 15:20:53 2010
@@ -38,6 +38,9 @@
super();
}
+ public void init() {
+ }
+
public Stats execute(final URI targetURI, byte[] content, int n) throws Exception {
Stats stats = new Stats();
Added: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java?rev=919446&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java (added)
+++ httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java Fri Mar 5 15:20:53 2010
@@ -0,0 +1,152 @@
+/*
+ * ====================================================================
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.client.benchmark;
+
+import java.io.IOException;
+import java.net.URI;
+
+import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.client.HttpExchange;
+import org.eclipse.jetty.io.Buffer;
+import org.eclipse.jetty.io.ByteArrayBuffer;
+import org.eclipse.jetty.server.Server;
+
+public class TestJettyHttpClient implements TestHttpAgent {
+
+ private final HttpClient client;
+
+ public TestJettyHttpClient() {
+ super();
+ this.client = new HttpClient();
+ this.client.setConnectorType(HttpClient.CONNECTOR_SOCKET);
+ this.client.setRequestBufferSize(8 * 1024);
+ this.client.setResponseBufferSize(8 * 1024);
+ }
+
+ public void init() throws Exception {
+ this.client.start();
+ }
+
+ public Stats execute(final URI targetURI, byte[] content, int n) throws Exception {
+
+ Stats stats = new Stats();
+
+ int successCount = 0;
+ int failureCount = 0;
+ long totalContentLen = 0;
+
+ for (int i = 0; i < n; i++) {
+ SimpleHttpExchange exchange = new SimpleHttpExchange();
+ exchange.setURL(targetURI.toASCIIString());
+
+ if (content != null) {
+ exchange.setMethod("POST");
+ exchange.setRequestContent(new ByteArrayBuffer(content));
+ }
+
+ try {
+ this.client.send(exchange);
+ exchange.waitForDone();
+ if (exchange.status == 200) {
+ successCount++;
+ } else {
+ failureCount++;
+ }
+ stats.setContentLen(exchange.contentLen);
+ totalContentLen += exchange.contentLen;
+ } catch (IOException ex) {
+ failureCount++;
+ }
+ if (exchange.server != null) {
+ stats.setServerName(exchange.server);
+ }
+ }
+ stats.setSuccessCount(successCount);
+ stats.setFailureCount(failureCount);
+ stats.setTotalContentLen(totalContentLen);
+ return stats;
+ }
+
+ public Stats get(final URI target, int n) throws Exception {
+ return execute(target, null, n);
+ }
+
+ public Stats post(final URI target, byte[] content, int n) throws Exception {
+ return execute(target, content, n);
+ }
+
+ public String getClientName() {
+ return "Jetty " + Server.getVersion();
+ }
+
+ 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]);
+
+ TestJettyHttpClient test = new TestJettyHttpClient();
+
+ long startTime = System.currentTimeMillis();
+ Stats stats = test.get(targetURI, n);
+ long finishTime = System.currentTimeMillis();
+
+ Stats.printStats(targetURI, startTime, finishTime, stats);
+ }
+
+ static class SimpleHttpExchange extends HttpExchange {
+
+ private final Buffer serverHeader = new ByteArrayBuffer("Server");
+
+ long contentLen = 0;
+ int status = 0;
+ String server;
+
+ protected void onResponseStatus(
+ final Buffer version, int status, final Buffer reason) throws IOException {
+ this.status = status;
+ super.onResponseStatus(version, status, reason);
+ }
+
+ @Override
+ protected void onResponseHeader(final Buffer name, final Buffer value) throws IOException {
+ super.onResponseHeader(name, value);
+ if (name.equalsIgnoreCase(this.serverHeader)) {
+ this.server = value.toString("ASCII");
+ }
+ }
+
+ @Override
+ protected void onResponseContent(final Buffer content) throws IOException {
+ this.contentLen += content.length();
+ super.onResponseContent(content);
+ }
+
+ };
+
+}
\ No newline at end of file
Propchange: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestJettyHttpClient.java
------------------------------------------------------------------------------
svn:keywords = Rev Date