aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Becker2013-09-19 09:43:07 (EDT)
committerThomas Becker2013-09-19 09:43:07 (EDT)
commit5346e06d4a73e6c3ed7af1c4eee5a5ccb5565417 (patch)
treed567a602ba90a6361fe9584a9c8da996dca90df9
parent5499a5f726315f663a35c89b8d9619fe30ace149 (diff)
downloadorg.eclipse.jetty.project-5346e06d4a73e6c3ed7af1c4eee5a5ccb5565417.zip
org.eclipse.jetty.project-5346e06d4a73e6c3ed7af1c4eee5a5ccb5565417.tar.gz
org.eclipse.jetty.project-5346e06d4a73e6c3ed7af1c4eee5a5ccb5565417.tar.bz2
417289 SPDY replace use of direct buffers with indirect buffers or make it configurable
-rw-r--r--jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYConnection.java2
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/CredentialGenerator.java2
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/DataFrameGenerator.java2
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/Generator.java1
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/GoAwayGenerator.java2
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersGenerator.java2
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/NoOpGenerator.java2
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/PingGenerator.java2
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/RstStreamGenerator.java2
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SettingsGenerator.java2
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SynReplyGenerator.java2
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SynStreamGenerator.java2
-rw-r--r--jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/WindowUpdateGenerator.java2
-rw-r--r--jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/SimpleHTTPBenchmarkTest.java158
14 files changed, 171 insertions, 12 deletions
diff --git a/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYConnection.java b/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYConnection.java
index c56210f..372d169 100644
--- a/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYConnection.java
+++ b/jetty-spdy/spdy-client/src/main/java/org/eclipse/jetty/spdy/client/SPDYConnection.java
@@ -80,7 +80,7 @@ public class SPDYConnection extends AbstractConnection implements Controller, Id
@Override
public void onFillable()
{
- ByteBuffer buffer = bufferPool.acquire(bufferSize, true);
+ ByteBuffer buffer = bufferPool.acquire(bufferSize, false);
boolean readMore = read(buffer) == 0;
bufferPool.release(buffer);
if (readMore)
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/CredentialGenerator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/CredentialGenerator.java
index 478c23e..1451bcc 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/CredentialGenerator.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/CredentialGenerator.java
@@ -53,7 +53,7 @@ public class CredentialGenerator extends ControlFrameGenerator
int frameBodyLength = 2 + 4 + proof.length + certificates.size() * 4 + certificatesLength;
int totalLength = ControlFrame.HEADER_LENGTH + frameBodyLength;
- ByteBuffer buffer = getByteBufferPool().acquire(totalLength, true);
+ ByteBuffer buffer = getByteBufferPool().acquire(totalLength, Generator.useDirectBuffers);
BufferUtil.clearToFill(buffer);
generateControlFrameHeader(credential, frameBodyLength, buffer);
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/DataFrameGenerator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/DataFrameGenerator.java
index d033e29..ac8ede0 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/DataFrameGenerator.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/DataFrameGenerator.java
@@ -36,7 +36,7 @@ public class DataFrameGenerator
public ByteBuffer generate(int streamId, int length, DataInfo dataInfo)
{
- ByteBuffer buffer = bufferPool.acquire(DataFrame.HEADER_LENGTH + length, true);
+ ByteBuffer buffer = bufferPool.acquire(DataFrame.HEADER_LENGTH + length, Generator.useDirectBuffers);
BufferUtil.clearToFill(buffer);
buffer.limit(length + DataFrame.HEADER_LENGTH);
buffer.position(DataFrame.HEADER_LENGTH);
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/Generator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/Generator.java
index 45e0550..84630f1 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/Generator.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/Generator.java
@@ -29,6 +29,7 @@ import org.eclipse.jetty.spdy.frames.ControlFrameType;
public class Generator
{
+ final static boolean useDirectBuffers=false;
private final EnumMap<ControlFrameType, ControlFrameGenerator> generators = new EnumMap<>(ControlFrameType.class);
private final DataFrameGenerator dataFrameGenerator;
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/GoAwayGenerator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/GoAwayGenerator.java
index cdfb4f6..6ab0f95 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/GoAwayGenerator.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/GoAwayGenerator.java
@@ -40,7 +40,7 @@ public class GoAwayGenerator extends ControlFrameGenerator
int frameBodyLength = 8;
int totalLength = ControlFrame.HEADER_LENGTH + frameBodyLength;
- ByteBuffer buffer = getByteBufferPool().acquire(totalLength, true);
+ ByteBuffer buffer = getByteBufferPool().acquire(totalLength, Generator.useDirectBuffers);
BufferUtil.clearToFill(buffer);
generateControlFrameHeader(goAway, frameBodyLength, buffer);
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersGenerator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersGenerator.java
index b036852..ed1cf9f 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersGenerator.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/HeadersGenerator.java
@@ -60,7 +60,7 @@ public class HeadersGenerator extends ControlFrameGenerator
int totalLength = ControlFrame.HEADER_LENGTH + frameLength;
- ByteBuffer buffer = getByteBufferPool().acquire(totalLength, true);
+ ByteBuffer buffer = getByteBufferPool().acquire(totalLength, Generator.useDirectBuffers);
BufferUtil.clearToFill(buffer);
generateControlFrameHeader(headers, frameLength, buffer);
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/NoOpGenerator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/NoOpGenerator.java
index 6d9689d..10bda6b 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/NoOpGenerator.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/NoOpGenerator.java
@@ -39,7 +39,7 @@ public class NoOpGenerator extends ControlFrameGenerator
int frameBodyLength = 0;
int totalLength = ControlFrame.HEADER_LENGTH + frameBodyLength;
- ByteBuffer buffer = getByteBufferPool().acquire(totalLength, true);
+ ByteBuffer buffer = getByteBufferPool().acquire(totalLength, Generator.useDirectBuffers);
BufferUtil.clearToFill(buffer);
generateControlFrameHeader(noOp, frameBodyLength, buffer);
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/PingGenerator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/PingGenerator.java
index ef7579a..6751f0c 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/PingGenerator.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/PingGenerator.java
@@ -39,7 +39,7 @@ public class PingGenerator extends ControlFrameGenerator
int frameBodyLength = 4;
int totalLength = ControlFrame.HEADER_LENGTH + frameBodyLength;
- ByteBuffer buffer = getByteBufferPool().acquire(totalLength, true);
+ ByteBuffer buffer = getByteBufferPool().acquire(totalLength, Generator.useDirectBuffers);
BufferUtil.clearToFill(buffer);
generateControlFrameHeader(ping, frameBodyLength, buffer);
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/RstStreamGenerator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/RstStreamGenerator.java
index 4ad2dd3..4a25cab 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/RstStreamGenerator.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/RstStreamGenerator.java
@@ -39,7 +39,7 @@ public class RstStreamGenerator extends ControlFrameGenerator
int frameBodyLength = 8;
int totalLength = ControlFrame.HEADER_LENGTH + frameBodyLength;
- ByteBuffer buffer = getByteBufferPool().acquire(totalLength, true);
+ ByteBuffer buffer = getByteBufferPool().acquire(totalLength, Generator.useDirectBuffers);
BufferUtil.clearToFill(buffer);
generateControlFrameHeader(rstStream, frameBodyLength, buffer);
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SettingsGenerator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SettingsGenerator.java
index 04aeaa8..83a0d1d 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SettingsGenerator.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SettingsGenerator.java
@@ -43,7 +43,7 @@ public class SettingsGenerator extends ControlFrameGenerator
int size = settings.size();
int frameBodyLength = 4 + 8 * size;
int totalLength = ControlFrame.HEADER_LENGTH + frameBodyLength;
- ByteBuffer buffer = getByteBufferPool().acquire(totalLength, true);
+ ByteBuffer buffer = getByteBufferPool().acquire(totalLength, Generator.useDirectBuffers);
BufferUtil.clearToFill(buffer);
generateControlFrameHeader(settingsFrame, frameBodyLength, buffer);
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SynReplyGenerator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SynReplyGenerator.java
index 266df9a..c5d4fff 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SynReplyGenerator.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SynReplyGenerator.java
@@ -58,7 +58,7 @@ public class SynReplyGenerator extends ControlFrameGenerator
int totalLength = ControlFrame.HEADER_LENGTH + frameLength;
- ByteBuffer buffer = getByteBufferPool().acquire(totalLength, true);
+ ByteBuffer buffer = getByteBufferPool().acquire(totalLength, Generator.useDirectBuffers);
BufferUtil.clearToFill(buffer);
generateControlFrameHeader(synReply, frameLength, buffer);
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SynStreamGenerator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SynStreamGenerator.java
index eb55a39..2b49843 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SynStreamGenerator.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/SynStreamGenerator.java
@@ -60,7 +60,7 @@ public class SynStreamGenerator extends ControlFrameGenerator
int totalLength = ControlFrame.HEADER_LENGTH + frameLength;
- ByteBuffer buffer = getByteBufferPool().acquire(totalLength, true);
+ ByteBuffer buffer = getByteBufferPool().acquire(totalLength, Generator.useDirectBuffers);
BufferUtil.clearToFill(buffer);
generateControlFrameHeader(synStream, frameLength, buffer);
diff --git a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/WindowUpdateGenerator.java b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/WindowUpdateGenerator.java
index 786b326..5e97aac 100644
--- a/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/WindowUpdateGenerator.java
+++ b/jetty-spdy/spdy-core/src/main/java/org/eclipse/jetty/spdy/generator/WindowUpdateGenerator.java
@@ -39,7 +39,7 @@ public class WindowUpdateGenerator extends ControlFrameGenerator
int frameBodyLength = 8;
int totalLength = ControlFrame.HEADER_LENGTH + frameBodyLength;
- ByteBuffer buffer = getByteBufferPool().acquire(totalLength, true);
+ ByteBuffer buffer = getByteBufferPool().acquire(totalLength, Generator.useDirectBuffers);
BufferUtil.clearToFill(buffer);
generateControlFrameHeader(windowUpdate, frameBodyLength, buffer);
diff --git a/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/SimpleHTTPBenchmarkTest.java b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/SimpleHTTPBenchmarkTest.java
new file mode 100644
index 0000000..df4c69d
--- /dev/null
+++ b/jetty-spdy/spdy-http-server/src/test/java/org/eclipse/jetty/spdy/server/http/SimpleHTTPBenchmarkTest.java
@@ -0,0 +1,158 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.spdy.server.http;
+
+import java.io.IOException;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.eclipse.jetty.http.HttpHeader;
+import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.handler.AbstractHandler;
+import org.eclipse.jetty.spdy.api.DataInfo;
+import org.eclipse.jetty.spdy.api.ReplyInfo;
+import org.eclipse.jetty.spdy.api.Session;
+import org.eclipse.jetty.spdy.api.Stream;
+import org.eclipse.jetty.spdy.api.StreamFrameListener;
+import org.eclipse.jetty.spdy.api.SynInfo;
+import org.eclipse.jetty.util.Fields;
+import org.eclipse.jetty.util.log.Log;
+import org.eclipse.jetty.util.log.Logger;
+import org.hamcrest.CoreMatchers;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+@Ignore("So far only used for testing performance tweaks. So no need to run it in a build")
+public class SimpleHTTPBenchmarkTest extends AbstractHTTPSPDYTest
+{
+ private static final Logger LOG = Log.getLogger(SimpleHTTPBenchmarkTest.class);
+ private final int dataSize = 4096*100;
+ private Session session;
+ private int requestCount = 100;
+
+ public SimpleHTTPBenchmarkTest(short version)
+ {
+ super(version);
+ }
+
+ @Before
+ public void setUp() throws Exception
+ {
+ final byte[] data = new byte[dataSize];
+ new Random().nextBytes(data);
+ session = startClient(version, startHTTPServer(version, new AbstractHandler()
+ {
+ @Override
+ public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
+ throws IOException, ServletException
+ {
+ request.setHandled(true);
+ assertEquals("GET", httpRequest.getMethod());
+ assertThat("accept-encoding is set to gzip, even if client didn't set it",
+ httpRequest.getHeader("accept-encoding"), containsString("gzip"));
+ assertThat(httpRequest.getHeader("host"), is("localhost:" + connector.getLocalPort()));
+ httpResponse.getOutputStream().write(data);
+ }
+ }), null);
+ }
+
+ @Test
+ public void testRunBenchmark() throws Exception
+ {
+ long overallStart = System.nanoTime();
+ int iterations = 20;
+ for (int j = 0; j < iterations; j++)
+ {
+ long start = System.nanoTime();
+ for (int i = 0; i < requestCount; i++)
+ sendGetRequestWithData();
+ long timeElapsed = System.nanoTime() - start;
+ LOG.info("Requests with {}b response took: {}ms", dataSize, timeElapsed / 1000 / 1000);
+ }
+ long timeElapsedOverall = (System.nanoTime() - overallStart)/1000/1000;
+ LOG.info("Time elapsed overall: {}ms avg: {}ms", timeElapsedOverall, timeElapsedOverall/iterations);
+ }
+
+ private void sendGetRequest() throws Exception
+ {
+ final CountDownLatch replyLatch = new CountDownLatch(1);
+ final String path = "/foo";
+
+ Fields headers = SPDYTestUtils.createHeaders("localhost", connector.getLocalPort(), version, "GET", path);
+ session.syn(new SynInfo(headers, true), new StreamFrameListener.Adapter()
+ {
+ @Override
+ public void onReply(Stream stream, ReplyInfo replyInfo)
+ {
+ assertTrue(replyInfo.isClose());
+ Fields replyHeaders = replyInfo.getHeaders();
+ assertThat(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"), CoreMatchers.is(true));
+ assertThat(replyHeaders.get(HttpHeader.SERVER.asString()), CoreMatchers.is(notNullValue()));
+ assertThat(replyHeaders.get(HttpHeader.X_POWERED_BY.asString()), CoreMatchers.is(notNullValue()));
+ replyLatch.countDown();
+ }
+ });
+
+ assertThat("reply has been received", replyLatch.await(5, TimeUnit.SECONDS), is(true));
+ }
+
+ private void sendGetRequestWithData() throws Exception
+ {
+ final CountDownLatch replyLatch = new CountDownLatch(1);
+ final CountDownLatch dataLatch = new CountDownLatch(1);
+ final String path = "/foo";
+
+ Fields headers = SPDYTestUtils.createHeaders("localhost", connector.getLocalPort(), version, "GET", path);
+ session.syn(new SynInfo(headers, true), new StreamFrameListener.Adapter()
+ {
+ @Override
+ public void onReply(Stream stream, ReplyInfo replyInfo)
+ {
+ Fields replyHeaders = replyInfo.getHeaders();
+ assertThat(replyHeaders.get(HTTPSPDYHeader.STATUS.name(version)).value().contains("200"), CoreMatchers.is(true));
+ assertThat(replyHeaders.get(HttpHeader.SERVER.asString()), CoreMatchers.is(notNullValue()));
+ assertThat(replyHeaders.get(HttpHeader.X_POWERED_BY.asString()), CoreMatchers.is(notNullValue()));
+ replyLatch.countDown();
+ }
+
+ @Override
+ public void onData(Stream stream, DataInfo dataInfo)
+ {
+ dataInfo.consume(dataInfo.available());
+ if (dataInfo.isClose())
+ dataLatch.countDown();
+ }
+ });
+
+ assertThat("reply has been received", replyLatch.await(5, TimeUnit.SECONDS), is(true));
+ assertThat("data has been received", dataLatch.await(5, TimeUnit.SECONDS), is(true));
+ }
+}