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());
}
}
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;
}
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));
}
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())));
}
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);
}
Aggregations