Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop usage of partial byte buf allocator. #5386

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ public abstract class VertxByteBufAllocator extends AbstractByteBufAllocator {
POOLED_ALLOCATOR = pooledAllocator;
}

/**
* Vert.x shared un-pooled allocator.
*/
public static final ByteBufAllocator UNPOOLED_ALLOCATOR = new UnpooledByteBufAllocator(false);

private static final VertxByteBufAllocator UNSAFE_IMPL = new VertxByteBufAllocator() {
@Override
protected ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity) {
Expand All @@ -53,7 +48,7 @@ protected ByteBuf newHeapBuffer(int initialCapacity, int maxCapacity) {

@Override
protected ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity) {
return UNPOOLED_ALLOCATOR.directBuffer(initialCapacity, maxCapacity);
return UnpooledByteBufAllocator.DEFAULT.directBuffer(initialCapacity, maxCapacity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import io.netty.handler.traffic.GlobalTrafficShapingHandler;
import io.netty.util.concurrent.GenericFutureListener;
import io.vertx.core.*;
import io.vertx.core.buffer.impl.PartialPooledByteBufAllocator;
import io.vertx.core.http.ClientAuth;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.impl.HttpUtils;
Expand Down Expand Up @@ -507,13 +506,8 @@ private void bind(
channelBalancer.addWorker(eventLoop, worker);
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(vertx.getAcceptorEventLoopGroup(), channelBalancer.workers());
if (options.isSsl()) {
bootstrap.childOption(ChannelOption.ALLOCATOR, PartialPooledByteBufAllocator.INSTANCE);
} else {
bootstrap.childOption(ChannelOption.ALLOCATOR, VertxByteBufAllocator.POOLED_ALLOCATOR);
}

bootstrap.childHandler(channelBalancer);
bootstrap.childOption(ChannelOption.ALLOCATOR, VertxByteBufAllocator.POOLED_ALLOCATOR);
vietj marked this conversation as resolved.
Show resolved Hide resolved
vietj marked this conversation as resolved.
Show resolved Hide resolved
applyConnectionOptions(localAddress.isDomainSocket(), bootstrap);

// Actual bind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.vertx.core.datagram.DatagramSocketOptions;
import io.vertx.core.net.ClientOptionsBase;
import io.vertx.core.net.NetServerOptions;
import io.vertx.core.buffer.impl.PartialPooledByteBufAllocator;
import io.vertx.core.net.impl.SocketAddressImpl;
import io.vertx.core.impl.transports.NioTransport;

Expand Down Expand Up @@ -121,7 +120,6 @@ default EventLoopGroup eventLoopGroup(int type, int nThreads, ThreadFactory thre
ChannelFactory<? extends ServerChannel> serverChannelFactory(boolean domainSocket);

default void configure(DatagramChannel channel, DatagramSocketOptions options) {
channel.config().setAllocator(PartialPooledByteBufAllocator.INSTANCE);
if (options.getSendBufferSize() != -1) {
channel.config().setSendBufferSize(options.getSendBufferSize());
}
Expand Down
49 changes: 39 additions & 10 deletions vertx-core/src/test/java/io/vertx/it/buffer/TcpAllocationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,40 @@
package io.vertx.it.buffer;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.util.ReferenceCountUtil;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.buffer.impl.BufferImpl;
import io.vertx.core.impl.buffer.VertxByteBufAllocator;
import io.vertx.core.internal.net.NetSocketInternal;
import io.vertx.core.net.NetClient;
import io.vertx.core.net.NetServer;
import io.vertx.core.net.NetSocket;
import io.vertx.core.net.*;
import io.vertx.test.core.VertxTestBase;
import io.vertx.test.tls.Cert;
import org.junit.Assume;
import org.junit.Test;

public class TcpAllocationTest extends VertxTestBase {

@Test
public void testByteBufOriginateFromDefaultByteBufAllocator() {
NetServer server = vertx.createNetServer();
testByteBufOriginateFromDefaultByteBufAllocator(null);
}

@Test
public void testByteBufOriginateFromDefaultByteBufAllocatorWithJdkSsl() {
testByteBufOriginateFromDefaultByteBufAllocator(new JdkSSLEngineOptions());
}

@Test
public void testByteBufOriginateFromDefaultByteBufAllocatorWithOpenSsl() {
Assume.assumeTrue(OpenSSLEngineOptions.isAvailable());
testByteBufOriginateFromDefaultByteBufAllocator(new OpenSSLEngineOptions());
}

private void testByteBufOriginateFromDefaultByteBufAllocator(SSLEngineOptions sslEngineOptions) {
NetServer server = vertx.createNetServer(new NetServerOptions()
.setSsl(sslEngineOptions != null)
.setSslEngineOptions(sslEngineOptions)
.setKeyCertOptions(Cert.SERVER_JKS.get()));
server.connectHandler(so -> {
NetSocketInternal soi = (NetSocketInternal) so;
soi.messageHandler(msg -> {
Expand All @@ -38,13 +54,26 @@ public void testByteBufOriginateFromDefaultByteBufAllocator() {
} finally {
ReferenceCountUtil.release(msg);
}
testComplete();
soi.write(Buffer.buffer("pong"));
});
});
server.listen(1234, "localhost").await();
NetClient client = vertx.createNetClient();
NetSocket so = client.connect(1234, "localhost").await();
so.write(Buffer.buffer("ping"));
NetClient client = vertx.createNetClient(new NetClientOptions()
.setSsl(sslEngineOptions != null)
.setTrustAll(true)
.setHostnameVerificationAlgorithm("")
);
NetSocketInternal soi = (NetSocketInternal) client.connect(1234, "localhost").await();
soi.messageHandler(msg -> {
try {
ByteBuf bbuf = (ByteBuf) msg;
assertSame(VertxByteBufAllocator.POOLED_ALLOCATOR, bbuf.alloc());
} finally {
ReferenceCountUtil.release(msg);
}
testComplete();
});
soi.write(Buffer.buffer("ping"));
await();
}

Expand Down
Loading