You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Apache Wiki <wi...@apache.org> on 2008/01/20 17:14:35 UTC
[Jakarta-httpclient Wiki] Update of "HttpClient3vsHttpClient4vsHttpCore" by
RolandWeber
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Jakarta-httpclient Wiki" for change notification.
The following page has been changed by RolandWeber:
http://wiki.apache.org/jakarta-httpclient/HttpClient3vsHttpClient4vsHttpCore
------------------------------------------------------------------------------
- = Client side HTTP performance benchmarks =
+ #DEPRECATED
- '''BIG FAT DISCLAIMER''': These benchmarks are NOT based on any scientific methodology so the numbers are likely to be non-precise
+ This page has been [http://wiki.apache.org/HttpComponents/HttpClient3vsHttpClient4vsHttpCore moved]
+ to the new [http://wiki.apache.org/HttpComponents/ HttpComponents Wiki].
- == HttpClient 3.x code ==
-
- {{{
- 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)");
- }
-
- }}}
-
- == HttpClient 4.x code ==
-
- {{{
- 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,
- 2 * 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)");
- }
-
- }}}
-
- == HttpCore 4.x code ==
-
- {{{
- 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,
- 2 * 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 HttpExecutionContext(null);
-
- 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(HttpExecutionContext.HTTP_CONNECTION, conn);
- context.setAttribute(HttpExecutionContext.HTTP_TARGET_HOST, targetHost);
- context.setAttribute(HttpExecutionContext.HTTP_REQUEST, httpget);
- httpexecutor.preProcess(httpget, httpproc, context);
-
- HttpResponse response = httpexecutor.execute(httpget, conn, context);
-
- context.setAttribute(HttpExecutionContext.HTTP_RESPONSE, response);
- 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)");
- }
-
- }}}
-
- == Results ==
-
- === Platform: Ubuntu Linux 7.04 (i686, 2.6.20-16-generic); java version "1.5.0_11" ===
-
- ==== 200,000 HTTP GETs, keep alive, content length: 22 bytes ====
-
- * !HttpClient 3.x
-
- {{{
- java -cp bin:/opt/libjava/commons-httpclient.jar:/opt/libjava/commons-logging.jar:/opt/libjava/commons-codec.jar \
- test.perf.HttpClient3PerfTest http://localhost/msg.txt 200000
- }}}
-
- {{{
- Server Software: Apache/2.2.3 (Ubuntu) mod_ssl/2.2.3 OpenSSL/0.9.8c
-
- Document URI: http://localhost/msg.txt
- Document Length: 22 bytes
-
- Time taken for tests: 29.144 seconds
- Complete requests: 200000
- Failed requests: 0
- Content transferred: 4400000 bytes
- Requests per second: 6862.476 [#/sec] (mean)
- Time per request: 0.14572 [ms] (mean)
- }}}
-
- * !HttpClient 4.x
-
- {{{
- java -cp bin:/opt/libjava/commons-logging.jar:/opt/libjava/commons-codec.jar:lib/httpcore-4.0-alpha5.jar:
- lib/httpclient-4.0-alpha1-SNAPSHOT.jar \
- test.perf.HttpClient4PerfTest http://localhost/msg.txt 200000
- }}}
-
- {{{
- Server Software: Apache/2.2.3 (Ubuntu) mod_ssl/2.2.3 OpenSSL/0.9.8c
-
- Document URI: http://localhost/msg.txt
- Document Length: 22 bytes
-
- Time taken for tests: 24.408 seconds
- Complete requests: 200000
- Failed requests: 0
- Content transferred: 4400000 bytes
- Requests per second: 8194.034 [#/sec] (mean)
- Time per request: 0.12204 [ms] (mean)
- }}}
-
- * !HttpCore 4.x
-
- {{{
- java -cp bin:lib/httpcore-4.0-alpha5.jar \
- test.perf.HttpCorePerfTest http://localhost/msg.txt 200000
- }}}
-
- {{{
- Server Software: Apache/2.2.3 (Ubuntu) mod_ssl/2.2.3 OpenSSL/0.9.8c
-
- Document URI: http://localhost/msg.txt
- Document Length: 22 bytes
-
- Time taken for tests: 19.567 seconds
- Complete requests: 200000
- Failed requests: 0
- Content transferred: 4400000 bytes
- Requests per second: 10221.291 [#/sec] (mean)
- Time per request: 0.097835 [ms] (mean)
- }}}
-
- ==== 200,000 HTTP GETs, keep alive, content length: 20,000 bytes ====
-
- * !HttpClient 3.x
-
- {{{
- java -cp bin:/opt/libjava/commons-httpclient.jar:/opt/libjava/commons-logging.jar:/opt/libjava/commons-codec.jar \
- test.perf.HttpClient3PerfTest http://localhost/blob 200000
- }}}
-
- {{{
- Server Software: Apache/2.2.3 (Ubuntu) mod_ssl/2.2.3 OpenSSL/0.9.8c
-
- Document URI: http://localhost/blob
- Document Length: 20000 bytes
-
- Time taken for tests: 35.809 seconds
- Complete requests: 200000
- Failed requests: 0
- Content transferred: 4000000000 bytes
- Requests per second: 5585.1885 [#/sec] (mean)
- Time per request: 0.179045 [ms] (mean)
- }}}
-
- * !HttpClient 4.x
-
- {{{
- java -cp bin:/opt/libjava/commons-logging.jar:/opt/libjava/commons-codec.jar:lib/httpcore-4.0-alpha5.jar:
- lib/httpclient-4.0-alpha1-SNAPSHOT.jar \
- test.perf.HttpClient4PerfTest http://localhost/blob 200000
- }}}
-
- {{{
- Server Software: Apache/2.2.3 (Ubuntu) mod_ssl/2.2.3 OpenSSL/0.9.8c
-
- Document URI: http://localhost/blob
- Document Length: 20000 bytes
-
- Time taken for tests: 33.398 seconds
- Complete requests: 200000
- Failed requests: 0
- Content transferred: 4000000000 bytes
- Requests per second: 5988.383 [#/sec] (mean)
- Time per request: 0.16699 [ms] (mean)
- }}}
-
- * !HttpCore 4.x
-
- {{{
- java -cp bin:lib/httpcore-4.0-alpha5.jar \
- test.perf.HttpCorePerfTest http://localhost/blob 200000
- }}}
-
- {{{
- Server Software: Apache/2.2.3 (Ubuntu) mod_ssl/2.2.3 OpenSSL/0.9.8c
-
- Document URI: http://localhost/blob
- Document Length: 20000 bytes
-
- Time taken for tests: 28.584 seconds
- Complete requests: 200000
- Failed requests: 0
- Content transferred: 4000000000 bytes
- Requests per second: 6996.9214 [#/sec] (mean)
- Time per request: 0.14292 [ms] (mean)
- }}}
-
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org