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 2012/09/30 00:26:59 UTC
svn commit: r1391911 - in /httpcomponents/benchmark/httpcore/trunk: ./
src/main/java/org/apache/http/benchmark/httpcore/
src/main/java/org/apache/http/benchmark/jetty/
Author: olegk
Date: Sat Sep 29 22:26:59 2012
New Revision: 1391911
URL: http://svn.apache.org/viewvc?rev=1391911&view=rev
Log:
Upgraded Jetty to version 8.1.7.v20120910; upgraded HttpCore NIO server to the latest API
Modified:
httpcomponents/benchmark/httpcore/trunk/pom.xml
httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreNIOServer.java
httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpListener.java
httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpWorker.java
httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpWorkerCallback.java
httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/NRandomDataHandler.java
httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/RandomDataHandler.java
httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/StdHttpWorkerCallback.java
httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/jetty/RandomDataHandler.java
Modified: httpcomponents/benchmark/httpcore/trunk/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/pom.xml?rev=1391911&r1=1391910&r2=1391911&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/pom.xml (original)
+++ httpcomponents/benchmark/httpcore/trunk/pom.xml Sat Sep 29 22:26:59 2012
@@ -69,7 +69,7 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
- <version>7.0.1.v20091125</version>
+ <version>8.1.7.v20120910</version>
<scope>compile</scope>
</dependency>
<dependency>
Modified: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreNIOServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreNIOServer.java?rev=1391911&r1=1391910&r2=1391911&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreNIOServer.java (original)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpCoreNIOServer.java Sat Sep 29 22:26:59 2012
@@ -32,11 +32,10 @@ import java.net.InetSocketAddress;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.benchmark.HttpServer;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.impl.DefaultHttpResponseFactory;
-import org.apache.http.impl.nio.DefaultServerIOEventDispatch;
+import org.apache.http.impl.nio.DefaultHttpServerIODispatch;
import org.apache.http.impl.nio.reactor.DefaultListeningIOReactor;
-import org.apache.http.nio.protocol.AsyncNHttpServiceHandler;
-import org.apache.http.nio.protocol.NHttpRequestHandlerRegistry;
+import org.apache.http.nio.protocol.HttpAsyncRequestHandlerRegistry;
+import org.apache.http.nio.protocol.HttpAsyncService;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.ListeningIOReactor;
import org.apache.http.params.CoreConnectionPNames;
@@ -76,18 +75,15 @@ public class HttpCoreNIOServer implement
new ResponseConnControl()
});
- AsyncNHttpServiceHandler handler = new AsyncNHttpServiceHandler(
- httpproc,
- new DefaultHttpResponseFactory(),
- new DefaultConnectionReuseStrategy(),
- params);
-
- NHttpRequestHandlerRegistry reqistry = new NHttpRequestHandlerRegistry();
+ HttpAsyncRequestHandlerRegistry reqistry = new HttpAsyncRequestHandlerRegistry();
reqistry.register("/rnd", new NRandomDataHandler());
- handler.setHandlerResolver(reqistry);
- ListeningIOReactor ioreactor = new DefaultListeningIOReactor(2, params);
- IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params);
+ HttpAsyncService handler = new HttpAsyncService(
+ httpproc, new DefaultConnectionReuseStrategy(), reqistry, params);
+
+ ListeningIOReactor ioreactor = new DefaultListeningIOReactor();
+ IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(handler, params);
+
this.listener = new NHttpListener(ioreactor, ioEventDispatch);
}
Modified: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpListener.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpListener.java?rev=1391911&r1=1391910&r2=1391911&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpListener.java (original)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpListener.java Sat Sep 29 22:26:59 2012
@@ -77,7 +77,9 @@ class HttpListener extends Thread {
} catch (InterruptedIOException ex) {
terminate();
} catch (IOException ex) {
- this.exception = ex;
+ if (!this.shutdown) {
+ this.exception = ex;
+ }
terminate();
}
}
@@ -101,4 +103,4 @@ class HttpListener extends Thread {
this.join(millis);
}
-}
\ No newline at end of file
+}
Modified: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpWorker.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpWorker.java?rev=1391911&r1=1391910&r2=1391911&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpWorker.java (original)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpWorker.java Sat Sep 29 22:26:59 2012
@@ -65,7 +65,7 @@ class HttpWorker extends Thread {
this.workercallback.started(this);
try {
HttpContext context = new BasicHttpContext();
- while (!Thread.interrupted() && !this.shutdown) {
+ while (!Thread.interrupted() && !this.shutdown && this.conn.isOpen()) {
this.httpservice.handleRequest(this.conn, context);
}
} catch (Exception ex) {
@@ -94,4 +94,4 @@ class HttpWorker extends Thread {
this.join(millis);
}
-}
\ No newline at end of file
+}
Modified: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpWorkerCallback.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpWorkerCallback.java?rev=1391911&r1=1391910&r2=1391911&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpWorkerCallback.java (original)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/HttpWorkerCallback.java Sat Sep 29 22:26:59 2012
@@ -32,4 +32,4 @@ interface HttpWorkerCallback {
void shutdown(HttpWorker worker);
-}
\ No newline at end of file
+}
Modified: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/NRandomDataHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/NRandomDataHandler.java?rev=1391911&r1=1391910&r2=1391911&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/NRandomDataHandler.java (original)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/NRandomDataHandler.java Sat Sep 29 22:26:59 2012
@@ -27,96 +27,48 @@
package org.apache.http.benchmark.httpcore;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.Locale;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
import org.apache.http.MethodNotSupportedException;
-import org.apache.http.entity.AbstractHttpEntity;
+import org.apache.http.entity.BasicHttpEntity;
+import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
+import org.apache.http.message.BasicHttpResponse;
import org.apache.http.nio.ContentEncoder;
import org.apache.http.nio.IOControl;
-import org.apache.http.nio.entity.BufferingNHttpEntity;
-import org.apache.http.nio.entity.ConsumingNHttpEntity;
-import org.apache.http.nio.entity.ProducingNHttpEntity;
-import org.apache.http.nio.protocol.NHttpRequestHandler;
-import org.apache.http.nio.protocol.NHttpResponseTrigger;
-import org.apache.http.nio.util.HeapByteBufferAllocator;
+import org.apache.http.nio.protocol.BasicAsyncRequestConsumer;
+import org.apache.http.nio.protocol.HttpAsyncExchange;
+import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
+import org.apache.http.nio.protocol.HttpAsyncRequestHandler;
+import org.apache.http.nio.protocol.HttpAsyncResponseProducer;
import org.apache.http.protocol.HttpContext;
-import org.apache.http.util.EntityUtils;
-class NRandomDataHandler implements NHttpRequestHandler {
+class NRandomDataHandler implements HttpAsyncRequestHandler<HttpRequest> {
public NRandomDataHandler() {
super();
}
- public ConsumingNHttpEntity entityRequest(
- final HttpEntityEnclosingRequest request,
- final HttpContext context) throws HttpException, IOException {
- // Use buffering entity for simplicity
- return new BufferingNHttpEntity(request.getEntity(), new HeapByteBufferAllocator());
- }
-
- public void handle(
+ public HttpAsyncRequestConsumer<HttpRequest> processRequest(
final HttpRequest request,
- final HttpResponse response,
- final NHttpResponseTrigger trigger,
final HttpContext context) throws HttpException, IOException {
- String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
- if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) {
- throw new MethodNotSupportedException(method + " method not supported");
- }
- if (request instanceof HttpEntityEnclosingRequest) {
- HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
- EntityUtils.consume(entity);
- }
- String target = request.getRequestLine().getUri();
-
- int count = 100;
-
- int idx = target.indexOf('?');
- if (idx != -1) {
- String s = target.substring(idx + 1);
- if (s.startsWith("c=")) {
- s = s.substring(2);
- try {
- count = Integer.parseInt(s);
- } catch (NumberFormatException ex) {
- response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
- response.setEntity(new StringEntity("Invalid query format: " + s,
- "text/plain", "ASCII"));
- return;
- }
- }
- }
- response.setStatusCode(HttpStatus.SC_OK);
- RandomEntity body = new RandomEntity(count);
- response.setEntity(body);
- trigger.submitResponse(response);
+ return new BasicAsyncRequestConsumer();
}
-
-
public void handle(
final HttpRequest request,
- final HttpResponse response,
+ final HttpAsyncExchange httpexchange,
final HttpContext context) throws HttpException, IOException {
String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) {
throw new MethodNotSupportedException(method + " method not supported");
}
- if (request instanceof HttpEntityEnclosingRequest) {
- HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
- EntityUtils.consume(entity);
- }
String target = request.getRequestLine().getUri();
int count = 100;
@@ -129,51 +81,47 @@ class NRandomDataHandler implements NHtt
try {
count = Integer.parseInt(s);
} catch (NumberFormatException ex) {
+ HttpResponse response = httpexchange.getResponse();
response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
- response.setEntity(new StringEntity("Invalid query format: " + s,
- "text/plain", "ASCII"));
+ response.setEntity(new StringEntity("Invalid query format: " + s, ContentType.TEXT_PLAIN));
+ httpexchange.submitResponse();
return;
}
}
}
- response.setStatusCode(HttpStatus.SC_OK);
- RandomEntity body = new RandomEntity(count);
- response.setEntity(body);
+ httpexchange.submitResponse(new RandomAsyncResponseProducer(count));
}
- static class RandomEntity extends AbstractHttpEntity implements ProducingNHttpEntity {
+ static class RandomAsyncResponseProducer implements HttpAsyncResponseProducer {
- private final int count;
private final ByteBuffer buf;
+ private final int count;
private int remaining;
- public RandomEntity(int count) {
+ public RandomAsyncResponseProducer(int count) {
super();
this.count = count;
- this.remaining = count;
this.buf = ByteBuffer.allocate(1024);
- setContentType("text/plain");
- }
-
- public InputStream getContent() throws IOException, IllegalStateException {
- throw new IllegalStateException("Method not supported");
}
- public long getContentLength() {
- return this.count;
+ public void close() throws IOException {
}
- public boolean isRepeatable() {
- return true;
+ public void failed(final Exception ex) {
}
- public boolean isStreaming() {
- return false;
+ public HttpResponse generateResponse() {
+ HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
+ BasicHttpEntity entity = new BasicHttpEntity();
+ entity.setContentLength(this.count);
+ entity.setContentType(ContentType.TEXT_PLAIN.toString());
+ response.setEntity(entity);
+ this.remaining = this.count;
+ return response;
}
- public void writeTo(final OutputStream outstream) throws IOException {
- throw new IllegalStateException("Method not supported");
+ public void responseCompleted(final HttpContext context) {
}
public void produceContent(
@@ -195,10 +143,6 @@ class NRandomDataHandler implements NHtt
this.buf.compact();
}
- public void finish() throws IOException {
- this.remaining = this.count;
- }
-
}
-}
\ No newline at end of file
+}
Modified: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/RandomDataHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/RandomDataHandler.java?rev=1391911&r1=1391910&r2=1391911&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/RandomDataHandler.java (original)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/RandomDataHandler.java Sat Sep 29 22:26:59 2012
@@ -39,6 +39,7 @@ import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.MethodNotSupportedException;
import org.apache.http.entity.AbstractHttpEntity;
+import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler;
@@ -75,8 +76,7 @@ class RandomDataHandler implements HttpR
count = Integer.parseInt(s);
} catch (NumberFormatException ex) {
response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
- response.setEntity(new StringEntity("Invalid query format: " + s,
- "text/plain", "ASCII"));
+ response.setEntity(new StringEntity("Invalid query format: " + s, ContentType.TEXT_PLAIN));
return;
}
}
@@ -129,4 +129,4 @@ class RandomDataHandler implements HttpR
}
-}
\ No newline at end of file
+}
Modified: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/StdHttpWorkerCallback.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/StdHttpWorkerCallback.java?rev=1391911&r1=1391910&r2=1391911&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/StdHttpWorkerCallback.java (original)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/httpcore/StdHttpWorkerCallback.java Sat Sep 29 22:26:59 2012
@@ -64,4 +64,4 @@ class StdHttpWorkerCallback implements H
}
}
-}
\ No newline at end of file
+}
Modified: httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/jetty/RandomDataHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/jetty/RandomDataHandler.java?rev=1391911&r1=1391910&r2=1391911&view=diff
==============================================================================
--- httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/jetty/RandomDataHandler.java (original)
+++ httpcomponents/benchmark/httpcore/trunk/src/main/java/org/apache/http/benchmark/jetty/RandomDataHandler.java Sat Sep 29 22:26:59 2012
@@ -53,6 +53,7 @@ class RandomDataHandler extends Abstract
rnd(request, response);
} else {
response.setStatus(HttpStatus.NOT_FOUND_404);
+ response.setContentType("text/plain");
Writer writer = response.getWriter();
writer.write("Target not found: " + target);
writer.flush();
@@ -75,6 +76,7 @@ class RandomDataHandler extends Abstract
}
response.setStatus(200);
+ response.setContentType("text/plain");
response.setContentLength(count);
OutputStream outstream = response.getOutputStream();
@@ -92,4 +94,4 @@ class RandomDataHandler extends Abstract
outstream.flush();
}
-}
\ No newline at end of file
+}