diff --git a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java index c421acac6de..b5438057e7f 100644 --- a/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java +++ b/jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Connection.java @@ -397,7 +397,7 @@ public Runnable produce() int filled = fill(getEndPoint(), networkBuffer.getByteBuffer(), compact); if (LOG.isDebugEnabled()) - LOG.debug("Filled {} bytes compacted {} in {}", filled, compact, networkBuffer); + LOG.debug("Filled {} bytes compacted {} {} in {}", filled, compact, networkBuffer, HTTP2Connection.this); if (filled > 0) { @@ -439,10 +439,11 @@ else if (filled == 0) private RetainableByteBuffer.Mutable acquireBuffer() { RetainableByteBuffer.Mutable buffer = heldBuffer.getAndSet(null); + RetainableByteBuffer.Mutable held = buffer; if (buffer == null) buffer = bufferPool.acquire(bufferSize, isUseInputDirectByteBuffers()).asMutable(); if (LOG.isDebugEnabled()) - LOG.debug("Acquired {}", buffer); + LOG.debug("Acquired {} {} in {}", held == null ? "new" : "held", buffer, HTTP2Connection.this); return buffer; } @@ -451,7 +452,7 @@ private void holdBuffer(RetainableByteBuffer.Mutable buffer) if (heldBuffer.compareAndSet(null, buffer)) { if (LOG.isDebugEnabled()) - LOG.debug("Held {}", buffer); + LOG.debug("Held {} in {}", buffer, HTTP2Connection.this); } else { diff --git a/jetty-core/jetty-tests/jetty-test-client-transports/src/test/java/org/eclipse/jetty/test/client/transport/HttpClientLoadTest.java b/jetty-core/jetty-tests/jetty-test-client-transports/src/test/java/org/eclipse/jetty/test/client/transport/HttpClientLoadTest.java index d167d0081fe..24053257e25 100644 --- a/jetty-core/jetty-tests/jetty-test-client-transports/src/test/java/org/eclipse/jetty/test/client/transport/HttpClientLoadTest.java +++ b/jetty-core/jetty-tests/jetty-test-client-transports/src/test/java/org/eclipse/jetty/test/client/transport/HttpClientLoadTest.java @@ -25,7 +25,9 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.stream.IntStream; +import org.awaitility.Awaitility; import org.eclipse.jetty.client.BytesRequestContent; +import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.Request; import org.eclipse.jetty.client.Response; import org.eclipse.jetty.client.Result; @@ -40,7 +42,6 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.NanoTime; import org.eclipse.jetty.util.thread.Scheduler; -import org.hamcrest.Matchers; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -48,6 +49,7 @@ import org.slf4j.LoggerFactory; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertTrue; public class HttpClientLoadTest extends AbstractTest @@ -68,24 +70,26 @@ public void testIterative(TransportType transportType) throws Exception client.setMaxConnectionsPerDestination(32768); client.setMaxRequestsQueuedPerDestination(1024 * 1024); client.setIdleTimeout(120000); - client.start(); - - // At least 25k requests to warmup properly (use -XX:+PrintCompilation to verify JIT activity) - int runs = 1; - int iterations = 100; - for (int i = 0; i < runs; ++i) + try (HttpClient httpClient = client) { - run(transportType, iterations); - } + httpClient.start(); - // Re-run after warmup - iterations = 250; - for (int i = 0; i < runs; ++i) - { - run(transportType, iterations); - } + // At least 25k requests to warmup properly (use -XX:+PrintCompilation to verify JIT activity) + int runs = 1; + int iterations = 100; + for (int i = 0; i < runs; ++i) + { + run(transportType, iterations); + } - assertThat("Leaks: " + byteBufferPool.dumpLeaks(), byteBufferPool.getLeaks().size(), Matchers.is(0)); + // Re-run after warmup + iterations = 250; + for (int i = 0; i < runs; ++i) + { + run(transportType, iterations); + } + } + Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> assertThat("Leaks: " + byteBufferPool.dumpLeaks(), byteBufferPool.getLeaks().size(), is(0))); } @ParameterizedTest @@ -101,15 +105,17 @@ public void testConcurrent(TransportType transportType) throws Exception client.setByteBufferPool(byteBufferPool); client.setMaxConnectionsPerDestination(32768); client.setMaxRequestsQueuedPerDestination(1024 * 1024); - client.start(); + try (HttpClient httpClient = client) + { + httpClient.start(); - int runs = 1; - int iterations = 128; - IntStream.range(0, 16).parallel().forEach(i -> + int runs = 1; + int iterations = 128; + IntStream.range(0, 16).parallel().forEach(i -> IntStream.range(0, runs).forEach(j -> - run(transportType, iterations))); - - assertThat("Connection Leaks: " + byteBufferPool.getLeaks(), byteBufferPool.getLeaks().size(), Matchers.is(0)); + run(transportType, iterations))); + } + Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> assertThat("Leaks: " + byteBufferPool.dumpLeaks(), byteBufferPool.getLeaks().size(), is(0))); } private void run(TransportType transportType, int iterations)