Search in sources :

Example 36 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project jetty.project by eclipse.

the class SettingsGenerateParseTest method testGenerateParseOneByteAtATime.

@Test
public void testGenerateParseOneByteAtATime() throws Exception {
    SettingsGenerator generator = new SettingsGenerator(new HeaderGenerator());
    final List<SettingsFrame> frames = new ArrayList<>();
    Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter() {

        @Override
        public void onSettings(SettingsFrame frame) {
            frames.add(frame);
        }
    }, 4096, 8192);
    Map<Integer, Integer> settings1 = new HashMap<>();
    int key = 13;
    Integer value = 17;
    settings1.put(key, value);
    // Iterate a few times to be sure generator and parser are properly reset.
    for (int i = 0; i < 2; ++i) {
        ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
        generator.generateSettings(lease, settings1, true);
        frames.clear();
        for (ByteBuffer buffer : lease.getByteBuffers()) {
            while (buffer.hasRemaining()) {
                parser.parse(ByteBuffer.wrap(new byte[] { buffer.get() }));
            }
        }
        Assert.assertEquals(1, frames.size());
        SettingsFrame frame = frames.get(0);
        Map<Integer, Integer> settings2 = frame.getSettings();
        Assert.assertEquals(1, settings2.size());
        Assert.assertEquals(value, settings2.get(key));
        Assert.assertTrue(frame.isReply());
    }
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.http2.parser.Parser) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HeaderGenerator(org.eclipse.jetty.http2.generator.HeaderGenerator) SettingsGenerator(org.eclipse.jetty.http2.generator.SettingsGenerator) Test(org.junit.Test)

Example 37 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project jetty.project by eclipse.

the class SettingsGenerateParseTest method testGenerateParse.

private List<SettingsFrame> testGenerateParse(Map<Integer, Integer> settings) {
    SettingsGenerator generator = new SettingsGenerator(new HeaderGenerator());
    final List<SettingsFrame> frames = new ArrayList<>();
    Parser parser = new Parser(byteBufferPool, new Parser.Listener.Adapter() {

        @Override
        public void onSettings(SettingsFrame frame) {
            frames.add(frame);
        }
    }, 4096, 8192);
    // Iterate a few times to be sure generator and parser are properly reset.
    for (int i = 0; i < 2; ++i) {
        ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
        generator.generateSettings(lease, settings, true);
        frames.clear();
        for (ByteBuffer buffer : lease.getByteBuffers()) {
            while (buffer.hasRemaining()) {
                parser.parse(buffer);
            }
        }
    }
    return frames;
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.http2.parser.Parser) HeaderGenerator(org.eclipse.jetty.http2.generator.HeaderGenerator) SettingsGenerator(org.eclipse.jetty.http2.generator.SettingsGenerator)

Example 38 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project jetty.project by eclipse.

the class HttpClientLoadTest method testIterative.

@Test
public void testIterative() throws Exception {
    start(new LoadHandler());
    client.setByteBufferPool(new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()));
    client.setMaxConnectionsPerDestination(32768);
    client.setMaxRequestsQueuedPerDestination(1024 * 1024);
    // At least 25k requests to warmup properly (use -XX:+PrintCompilation to verify JIT activity)
    int runs = 1;
    int iterations = 500;
    for (int i = 0; i < runs; ++i) run(iterations);
    // Re-run after warmup
    iterations = 5_000;
    for (int i = 0; i < runs; ++i) run(iterations);
    System.gc();
    ByteBufferPool byteBufferPool = connector.getByteBufferPool();
    if (byteBufferPool instanceof LeakTrackingByteBufferPool) {
        LeakTrackingByteBufferPool serverBufferPool = (LeakTrackingByteBufferPool) byteBufferPool;
        assertThat("Server BufferPool - leaked acquires", serverBufferPool.getLeakedAcquires(), Matchers.is(0L));
        assertThat("Server BufferPool - leaked releases", serverBufferPool.getLeakedReleases(), Matchers.is(0L));
        assertThat("Server BufferPool - unreleased", serverBufferPool.getLeakedResources(), Matchers.is(0L));
    }
    byteBufferPool = client.getByteBufferPool();
    if (byteBufferPool instanceof LeakTrackingByteBufferPool) {
        LeakTrackingByteBufferPool clientBufferPool = (LeakTrackingByteBufferPool) byteBufferPool;
        assertThat("Client BufferPool - leaked acquires", clientBufferPool.getLeakedAcquires(), Matchers.is(0L));
        assertThat("Client BufferPool - leaked releases", clientBufferPool.getLeakedReleases(), Matchers.is(0L));
        assertThat("Client BufferPool - unreleased", clientBufferPool.getLeakedResources(), Matchers.is(0L));
    }
    assertThat("Connection Leaks", connectionLeaks.get(), Matchers.is(0L));
}
Also used : LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) Test(org.junit.Test)

Example 39 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project dropwizard by dropwizard.

the class HttpConnectorFactory method build.

@Override
public Connector build(Server server, MetricRegistry metrics, String name, ThreadPool threadPool) {
    final HttpConfiguration httpConfig = buildHttpConfiguration();
    final HttpConnectionFactory httpConnectionFactory = buildHttpConnectionFactory(httpConfig);
    final Scheduler scheduler = new ScheduledExecutorScheduler();
    final ByteBufferPool bufferPool = buildBufferPool();
    return buildConnector(server, scheduler, bufferPool, name, threadPool, new Jetty93InstrumentedConnectionFactory(httpConnectionFactory, metrics.timer(httpConnections())));
}
Also used : ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Scheduler(org.eclipse.jetty.util.thread.Scheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) ScheduledExecutorScheduler(org.eclipse.jetty.util.thread.ScheduledExecutorScheduler) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration)

Example 40 with ByteBufferPool

use of org.eclipse.jetty.io.ByteBufferPool in project jetty.project by eclipse.

the class HttpReceiverOverHTTP method acquireBuffer.

private void acquireBuffer() {
    HttpClient client = getHttpDestination().getHttpClient();
    ByteBufferPool bufferPool = client.getByteBufferPool();
    buffer = bufferPool.acquire(client.getResponseBufferSize(), true);
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) HttpClient(org.eclipse.jetty.client.HttpClient)

Aggregations

ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)72 ByteBuffer (java.nio.ByteBuffer)53 Test (org.junit.Test)51 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)40 Parser (org.eclipse.jetty.http2.parser.Parser)37 HttpFields (org.eclipse.jetty.http.HttpFields)29 MetaData (org.eclipse.jetty.http.MetaData)24 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)21 HeaderGenerator (org.eclipse.jetty.http2.generator.HeaderGenerator)21 PrefaceFrame (org.eclipse.jetty.http2.frames.PrefaceFrame)20 SettingsFrame (org.eclipse.jetty.http2.frames.SettingsFrame)20 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)19 OutputStream (java.io.OutputStream)16 Socket (java.net.Socket)16 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)14 IOException (java.io.IOException)13 CountDownLatch (java.util.concurrent.CountDownLatch)13 EndPoint (org.eclipse.jetty.io.EndPoint)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8