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 2013/04/11 11:20:21 UTC
svn commit: r1466810 - in /httpcomponents/benchmark/httpclient/trunk: ./
src/main/java/org/apache/http/client/benchmark/
Author: olegk
Date: Thu Apr 11 09:20:20 2013
New Revision: 1466810
URL: http://svn.apache.org/r1466810
Log:
Upgraded Ning AHC to version 1.7.12; upgraded HttpClient to version 4.3-beta1; tweaked benchmark code
Added:
httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestApacheHttpClient.java
- copied, changed from r1464622, httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
Removed:
httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java
Modified:
httpcomponents/benchmark/httpclient/trunk/pom.xml
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/TestNingHttpClient.java
Modified: httpcomponents/benchmark/httpclient/trunk/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/trunk/pom.xml?rev=1466810&r1=1466809&r2=1466810&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/trunk/pom.xml (original)
+++ httpcomponents/benchmark/httpclient/trunk/pom.xml Thu Apr 11 09:20:20 2013
@@ -53,7 +53,7 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
- <version>4.2.2</version>
+ <version>4.3-beta1</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -83,7 +83,7 @@
<dependency>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
- <version>1.7.4</version>
+ <version>1.7.12</version>
<scope>compile</scope>
</dependency>
</dependencies>
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=1466810&r1=1466809&r2=1466810&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 Apr 11 09:20:20 2013
@@ -45,7 +45,7 @@ import org.eclipse.jetty.util.IO;
public class Benchmark {
- public static void main(String[] args) throws Exception {
+ 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");
@@ -65,7 +65,7 @@ public class Benchmark {
TestHttpAgent[] agents = new TestHttpAgent[] {
new TestHttpJRE(),
- new TestHttpClient4(),
+ new TestApacheHttpClient(),
new TestJettyHttpClient(),
new TestNingHttpClient()
};
@@ -77,8 +77,7 @@ public class Benchmark {
}
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);
+ URI target = new URI("http", null, "localhost", port, "/echo", null, null);
try {
for (TestHttpAgent agent: agents) {
@@ -92,21 +91,13 @@ public class Benchmark {
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);
+ long startTime = System.currentTimeMillis();
+ Stats stats = agent.post(target, content, n, c);
+ long finishTime = System.currentTimeMillis();
+ Stats.printStats(target, startTime, finishTime, stats);
} finally {
agent.shutdown();
}
@@ -124,6 +115,7 @@ public class Benchmark {
super();
}
+ @Override
public void handle(
final String target,
final Request baseRequest,
Copied: httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestApacheHttpClient.java (from r1464622, httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java)
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestApacheHttpClient.java?p2=httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestApacheHttpClient.java&p1=httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java&r1=1464622&r2=1466810&rev=1466810&view=diff
==============================================================================
--- httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestHttpClient4.java (original)
+++ httpcomponents/benchmark/httpclient/trunk/src/main/java/org/apache/http/client/benchmark/TestApacheHttpClient.java Thu Apr 11 09:20:20 2013
@@ -31,66 +31,47 @@ import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
-import org.apache.http.HttpVersion;
-import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.conn.scheme.PlainSocketFactory;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.config.ConnectionConfig;
+import org.apache.http.config.SocketConfig;
import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.PoolingClientConnectionManager;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.params.SyncBasicHttpParams;
-import org.apache.http.protocol.HttpContext;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.VersionInfo;
-public class TestHttpClient4 implements TestHttpAgent {
+public class TestApacheHttpClient implements TestHttpAgent {
- private final PoolingClientConnectionManager mgr;
- private final DefaultHttpClient httpclient;
+ private final PoolingHttpClientConnectionManager mgr;
+ private final CloseableHttpClient httpclient;
- public TestHttpClient4() {
+ public TestApacheHttpClient() {
super();
- HttpParams params = new SyncBasicHttpParams();
- 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);
- params.setIntParameter(HttpConnectionParams.SO_TIMEOUT,
- 15000);
- SchemeRegistry schemeRegistry = new SchemeRegistry();
- schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
- schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
- this.mgr = new PoolingClientConnectionManager(schemeRegistry);
- this.httpclient = new DefaultHttpClient(this.mgr, params);
- this.httpclient.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
-
- public boolean retryRequest(
- final IOException exception, int executionCount, final HttpContext context) {
- return false;
- }
-
- });
+ ConnectionConfig connectionConfig = ConnectionConfig.custom()
+ .setBufferSize(8 * 1024)
+ .setFragmentSizeHint(8 * 1024)
+ .build();
+ SocketConfig socketConfig = SocketConfig.custom()
+ .setSoTimeout(15000)
+ .build();
+ this.mgr = new PoolingHttpClientConnectionManager();
+ this.mgr.setDefaultSocketConfig(socketConfig);
+ this.mgr.setDefaultConnectionConfig(connectionConfig);
+ this.httpclient = HttpClients.createMinimal(this.mgr);
}
+ @Override
public void init() {
}
+ @Override
public void shutdown() {
this.mgr.shutdown();
}
- Stats execute(final URI target, final byte[] content, int n, int c) throws Exception {
+ Stats execute(final URI target, final byte[] content, final int n, final int c) throws Exception {
this.mgr.setMaxTotal(2000);
this.mgr.setDefaultMaxPerRoute(c);
Stats stats = new Stats(n, c);
@@ -165,14 +146,17 @@ public class TestHttpClient4 implements
}
- 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() {
VersionInfo vinfo = VersionInfo.loadVersionInfo("org.apache.http.client",
Thread.currentThread().getContextClassLoader());
@@ -180,7 +164,7 @@ public class TestHttpClient4 implements
((vinfo != null) ? vinfo.getRelease() : VersionInfo.UNAVAILABLE) + ")";
}
- 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);
@@ -192,7 +176,7 @@ public class TestHttpClient4 implements
c = Integer.parseInt(args[2]);
}
- TestHttpClient4 test = new TestHttpClient4();
+ TestApacheHttpClient test = new TestApacheHttpClient();
test.init();
try {
long startTime = System.currentTimeMillis();
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=1466810&r1=1466809&r2=1466810&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 Apr 11 09:20:20 2013
@@ -94,7 +94,7 @@ public class TestNingHttpClient implemen
}
public String getClientName() {
- return "Ning async HTTP client 1.7.4";
+ return "Ning async HTTP client 1.7.12";
}
static class SimpleAsyncHandler implements AsyncHandler<Object> {