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 2014/05/14 17:09:51 UTC
svn commit: r1594594 - in /httpcomponents/benchmark/httpclient/trunk:
build.gradle src/main/java/org/apache/http/client/benchmark/Benchmark.java
src/main/java/org/apache/http/client/benchmark/CommonsHttpClient.java
Author: olegk
Date: Wed May 14 15:09:51 2014
New Revision: 1594594
URL: http://svn.apache.org/r1594594
Log:
Added Commons HttpClient 3.1 benchmark
Added:
httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/CommonsHttpClient.java (with props)
Modified:
httpcomponents/benchmark/httpclient/trunk/build.gradle
httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/Benchmark.java
Modified: httpcomponents/benchmark/httpclient/trunk/build.gradle
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/trunk/build.gradle?rev=1594594&r1=1594593&r2=1594594&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/trunk/build.gradle (original)
+++ httpcomponents/benchmark/httpclient/trunk/build.gradle Wed May 14 15:09:51 2014
@@ -14,6 +14,7 @@ dependencies {
compile group: 'org.eclipse.jetty', name: 'jetty-client', version: '8.1.15.v20140411'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.6.2'
compile group: 'org.slf4j', name: 'slf4j-nop', version: '1.6.2'
+ compile group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.3.2'
compile group: 'org.apache.httpcomponents', name: 'httpcore-nio', version: '4.3.2'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.3.3'
@@ -24,6 +25,7 @@ dependencies {
task benchmark(dependsOn: 'classes') << {
def agents = [
'HttpJRE',
+ 'CommonsHttpClient',
'ApacheHttpClient',
'ApacheHttpCoreNIO',
'ApacheHttpAsyncClient',
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=1594594&r1=1594593&r2=1594594&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 Wed May 14 15:09:51 2014
@@ -35,6 +35,7 @@ public class Benchmark {
}
System.out.println("Running benchmark against " + config.getUri());
BenchRunner.run(new HttpJRE(), config);
+ BenchRunner.run(new CommonsHttpClient(), config);
BenchRunner.run(new ApacheHttpClient(), config);
BenchRunner.run(new JettyHttpClient(), config);
BenchRunner.run(new ApacheHttpCoreNIO(), config);
Added: httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/CommonsHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/CommonsHttpClient.java?rev=1594594&view=auto
==============================================================================
--- httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/CommonsHttpClient.java (added)
+++ httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/CommonsHttpClient.java Wed May 14 15:09:51 2014
@@ -0,0 +1,161 @@
+/*
+ * ====================================================================
+ *
+ * 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.io.InputStream;
+import java.net.URI;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpMethodRetryHandler;
+import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+
+public class CommonsHttpClient implements HttpAgent {
+
+ private final MultiThreadedHttpConnectionManager mgr;
+ private final HttpClient httpclient;
+
+ public CommonsHttpClient() {
+ super();
+ this.mgr = new MultiThreadedHttpConnectionManager();
+ this.mgr.getParams().setConnectionTimeout(15000);
+ this.httpclient = new HttpClient(this.mgr);
+ this.httpclient.getParams().setVersion(
+ HttpVersion.HTTP_1_1);
+ this.httpclient.getParams().setBooleanParameter(
+ HttpMethodParams.USE_EXPECT_CONTINUE, false);
+ this.httpclient.getHttpConnectionManager().getParams()
+ .setStaleCheckingEnabled(false);
+ this.httpclient.getParams().setSoTimeout(15000);
+
+ HttpMethodRetryHandler retryhandler = new HttpMethodRetryHandler() {
+
+ public boolean retryMethod(final HttpMethod httpmethod, final IOException ex, int count) {
+ return false;
+ }
+
+ };
+ this.httpclient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryhandler); }
+
+ public void init() {
+ }
+
+ public void shutdown() {
+ this.mgr.shutdown();
+ }
+
+ Stats execute(final URI target, final byte[] content, int n, int c) throws Exception {
+ this.mgr.getParams().setMaxTotalConnections(2000);
+ this.mgr.getParams().setDefaultMaxConnectionsPerHost(c);
+ Stats stats = new Stats(n, c);
+ WorkerThread[] workers = new WorkerThread[c];
+ for (int i = 0; i < workers.length; i++) {
+ workers[i] = new WorkerThread(stats, target, content);
+ }
+ for (int i = 0; i < workers.length; i++) {
+ workers[i].start();
+ }
+ for (int i = 0; i < workers.length; i++) {
+ workers[i].join();
+ }
+ return stats;
+ }
+
+ class WorkerThread extends Thread {
+
+ private final Stats stats;
+ private final URI target;
+ private final byte[] content;
+
+ WorkerThread(final Stats stats, final URI target, final byte[] content) {
+ super();
+ this.stats = stats;
+ this.target = target;
+ this.content = content;
+ }
+
+ @Override
+ public void run() {
+ byte[] buffer = new byte[4096];
+ while (!this.stats.isComplete()) {
+ HttpMethod httpmethod;
+ if (this.content == null) {
+ GetMethod httpget = new GetMethod(target.toASCIIString());
+ httpmethod = httpget;
+ } else {
+ PostMethod httppost = new PostMethod(target.toASCIIString());
+ httppost.setRequestEntity(new ByteArrayRequestEntity(content));
+ httpmethod = httppost;
+ }
+ long contentLen = 0;
+ try {
+ httpclient.executeMethod(httpmethod);
+ InputStream instream = httpmethod.getResponseBodyAsStream();
+ if (instream != null) {
+ int l = 0;
+ while ((l = instream.read(buffer)) != -1) {
+ contentLen += l;
+ }
+ }
+ if (httpmethod.getStatusCode() == 200) {
+ this.stats.success(contentLen);
+ } else {
+ this.stats.failure(contentLen);
+ }
+ } catch (IOException ex) {
+ this.stats.failure(contentLen);
+ } finally {
+ httpmethod.releaseConnection();
+ }
+ }
+ }
+
+ }
+
+ public Stats get(final URI target, int n, int c) throws Exception {
+ return execute(target, null, n, c);
+ }
+
+ public Stats post(URI target, byte[] content, int n, int c) throws Exception {
+ return execute(target, content, n, c);
+ }
+
+ public String getClientName() {
+ return "Apache HttpClient 3.1";
+ }
+
+ public static void main(String[] args) throws Exception {
+ final Config config = BenchRunner.parseConfig(args);
+ BenchRunner.run(new CommonsHttpClient(), config);
+ }
+
+}
Propchange: httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/CommonsHttpClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/CommonsHttpClient.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/CommonsHttpClient.java
------------------------------------------------------------------------------
svn:mime-type = text/plain