TABS -> SPACES

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1032680 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2010-11-08 19:53:44 +00:00
parent 64e60c989f
commit f3aa86396f
8 changed files with 45 additions and 44 deletions

View File

@ -47,20 +47,21 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
public class Benchmark {
public static void main(String[] args) throws Exception {
String ns = System.getProperty("hc.benchmark.n-requests", "200000");
String nc = System.getProperty("hc.benchmark.concurrent", "100");
String cls = System.getProperty("hc.benchmark.content-len", "2048");
int n = Integer.parseInt(ns);
int c = Integer.parseInt(nc);
int contentLen = Integer.parseInt(cls);
SocketConnector connector = new SocketConnector();
connector.setPort(0);
connector.setRequestBufferSize(12 * 1024);
connector.setResponseBufferSize(12 * 1024);
connector.setAcceptors(2);
connector.setAcceptQueueSize(c);
QueuedThreadPool threadpool = new QueuedThreadPool();
threadpool.setMinThreads(c);
@ -76,7 +77,7 @@ public class Benchmark {
// Sleep a little
Thread.sleep(2000);
TestHttpAgent[] agents = new TestHttpAgent[] {
new TestHttpClient3(),
new TestHttpJRE(),

View File

@ -31,7 +31,7 @@ public class Stats {
private final int expectedCount;
private final int concurrency;
private int successCount = 0;
private int failureCount = 0;
private long contentLen = 0;
@ -48,7 +48,7 @@ public class Stats {
}
public synchronized void success(long contentLen) {
if (isComplete()) return;
if (isComplete()) return;
this.successCount++;
this.contentLen = contentLen;
this.totalContentLen += contentLen;
@ -56,7 +56,7 @@ public class Stats {
}
public synchronized void failure(long contentLen) {
if (isComplete()) return;
if (isComplete()) return;
this.failureCount++;
this.contentLen = contentLen;
this.totalContentLen += contentLen;
@ -66,7 +66,7 @@ public class Stats {
public int getConcurrency() {
return this.concurrency;
}
public synchronized int getSuccessCount() {
return successCount;
}
@ -86,7 +86,7 @@ public class Stats {
public synchronized long getTotalContentLen() {
return totalContentLen;
}
public synchronized void waitFor() throws InterruptedException {
while (!isComplete()) {
wait();

View File

@ -46,7 +46,7 @@ public class TestHttpClient3 implements TestHttpAgent {
public TestHttpClient3() {
super();
this.mgr = new MultiThreadedHttpConnectionManager();
this.mgr = new MultiThreadedHttpConnectionManager();
this.httpclient = new HttpClient(this.mgr);
this.httpclient.getParams().setVersion(
HttpVersion.HTTP_1_1);
@ -55,13 +55,13 @@ public class TestHttpClient3 implements TestHttpAgent {
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); }
@ -88,20 +88,20 @@ public class TestHttpClient3 implements TestHttpAgent {
}
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];
@ -133,7 +133,7 @@ public class TestHttpClient3 implements TestHttpAgent {
}
}
}
}
public Stats get(final URI target, int n, int c) throws Exception {

View File

@ -66,7 +66,7 @@ public class TestHttpClient4 implements TestHttpAgent {
false);
params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE,
8 * 1024);
params.setIntParameter(HttpConnectionParams.SO_TIMEOUT,
params.setIntParameter(HttpConnectionParams.SO_TIMEOUT,
15000);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
@ -74,12 +74,12 @@ public class TestHttpClient4 implements TestHttpAgent {
this.mgr = new ThreadSafeClientConnManager(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;
}
});
}
@ -106,20 +106,20 @@ public class TestHttpClient4 implements TestHttpAgent {
}
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];
@ -158,9 +158,9 @@ public class TestHttpClient4 implements TestHttpAgent {
}
}
}
}
public Stats get(final URI target, int n, int c) throws Exception {
return execute(target, null, n ,c);
}

View File

@ -78,7 +78,7 @@ public class TestHttpCore implements TestHttpAgent {
false);
this.params.setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE,
8 * 1024);
this.params.setIntParameter(HttpConnectionParams.SO_TIMEOUT,
this.params.setIntParameter(HttpConnectionParams.SO_TIMEOUT,
15000);
this.httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
@ -108,7 +108,7 @@ public class TestHttpCore implements TestHttpAgent {
buffer.append(target.getQuery());
}
String requestUri = buffer.toString();
Stats stats = new Stats(n, c);
WorkerThread[] workers = new WorkerThread[c];
for (int i = 0; i < workers.length; i++) {
@ -129,8 +129,8 @@ public class TestHttpCore implements TestHttpAgent {
private final HttpHost targetHost;
private final String requestUri;
private final byte[] content;
WorkerThread(final Stats stats,
WorkerThread(final Stats stats,
final HttpHost targetHost, final String requestUri, final byte[] content) {
super();
this.stats = stats;
@ -138,7 +138,7 @@ public class TestHttpCore implements TestHttpAgent {
this.requestUri = requestUri;
this.content = content;
}
@Override
public void run() {
byte[] buffer = new byte[4096];
@ -165,7 +165,7 @@ public class TestHttpCore implements TestHttpAgent {
this.targetHost.getPort() > 0 ? this.targetHost.getPort() : 80);
conn.bind(socket, params);
}
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, targetHost);
@ -208,9 +208,9 @@ public class TestHttpCore implements TestHttpAgent {
} catch (IOException ignore) {}
}
}
}
public Stats get(final URI target, int n, int c) throws Exception {
return execute(target, null, n, c);
}

View File

@ -66,14 +66,14 @@ public class TestHttpJRE implements TestHttpAgent {
private final Stats stats;
private final URL target;
private final byte[] content;
WorkerThread(final Stats stats, final URL target, final byte[] content) {
super();
this.stats = stats;
this.target = target;
this.content = content;
}
@Override
public void run() {
byte[] buffer = new byte[4096];
@ -119,7 +119,7 @@ public class TestHttpJRE implements TestHttpAgent {
}
}
}
public Stats get(final URI target, int n, int c) throws Exception {
return execute(target, null, n, c);
}

View File

@ -98,7 +98,7 @@ public class TestJettyHttpClient implements TestHttpAgent {
super();
this.stats = stats;
}
protected void onResponseStatus(
final Buffer version, int status, final Buffer reason) throws IOException {
this.status = status;
@ -132,7 +132,7 @@ public class TestJettyHttpClient implements TestHttpAgent {
this.stats.failure(this.contentLen);
super.onException(x);
}
};
public static void main(String[] args) throws Exception {
@ -146,7 +146,7 @@ public class TestJettyHttpClient implements TestHttpAgent {
if (args.length > 2) {
c = Integer.parseInt(args[2]);
}
TestJettyHttpClient test = new TestJettyHttpClient();
test.init();
try {

View File

@ -61,7 +61,7 @@ public class TestNingHttpClient implements TestHttpAgent {
.setMaximumConnectionsPerHost(c)
.setMaximumConnectionsTotal(2000)
.setRequestTimeoutInMs(15000)
.build();
.build();
this.client = new AsyncHttpClient(config);
Stats stats = new Stats(n, c);
@ -70,11 +70,11 @@ public class TestNingHttpClient implements TestHttpAgent {
Request request;
if (content == null) {
request = this.client.prepareGet(targetURI.toASCIIString())
.build();
.build();
} else {
request = this.client.preparePost(targetURI.toASCIIString())
.setBody(content)
.build();
.build();
}
try {
this.client.executeRequest(request, new SimpleAsyncHandler(stats));
@ -94,7 +94,7 @@ public class TestNingHttpClient implements TestHttpAgent {
}
public String getClientName() {
return "Ning Async HTTP client 1.3";
return "Ning Async HTTP client 1.3";
}
static class SimpleAsyncHandler implements AsyncHandler<Object> {
@ -107,7 +107,7 @@ public class TestNingHttpClient implements TestHttpAgent {
super();
this.stats = stats;
}
public STATE onStatusReceived(final HttpResponseStatus responseStatus) throws Exception {
this.status = responseStatus.getStatusCode();
return STATE.CONTINUE;
@ -148,7 +148,7 @@ public class TestNingHttpClient implements TestHttpAgent {
if (args.length > 2) {
c = Integer.parseInt(args[2]);
}
TestNingHttpClient test = new TestNingHttpClient();
test.init();
try {