diff --git a/src/main/java/com/alipay/remoting/rpc/RpcConnectionFactory.java b/src/main/java/com/alipay/remoting/rpc/RpcConnectionFactory.java index b8a747aa..78e90445 100644 --- a/src/main/java/com/alipay/remoting/rpc/RpcConnectionFactory.java +++ b/src/main/java/com/alipay/remoting/rpc/RpcConnectionFactory.java @@ -20,6 +20,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import io.netty.buffer.UnpooledByteBufAllocator; import org.slf4j.Logger; import com.alipay.remoting.Connection; @@ -87,14 +88,14 @@ public void init(final ConnectionEventHandler connectionEventHandler) { .option(ChannelOption.SO_REUSEADDR, SystemProperties.tcp_so_reuseaddr()) .option(ChannelOption.SO_KEEPALIVE, SystemProperties.tcp_so_keepalive()); - /** - * init netty write buffer water mark - */ + // init netty write buffer water mark initWriteBufferWaterMark(); - boolean pooledBuffer = SystemProperties.netty_buffer_pooled(); - if (pooledBuffer) { - bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); + // init byte buf allocator + if (SystemProperties.netty_buffer_pooled()) { + this.bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); + } else { + this.bootstrap.option(ChannelOption.ALLOCATOR, UnpooledByteBufAllocator.DEFAULT); } final boolean idleSwitch = SystemProperties.tcp_idle_switch(); diff --git a/src/main/java/com/alipay/remoting/rpc/RpcServer.java b/src/main/java/com/alipay/remoting/rpc/RpcServer.java index 40cf8ffb..be831aec 100644 --- a/src/main/java/com/alipay/remoting/rpc/RpcServer.java +++ b/src/main/java/com/alipay/remoting/rpc/RpcServer.java @@ -49,12 +49,13 @@ import com.alipay.remoting.rpc.protocol.RpcProtocolManager; import com.alipay.remoting.rpc.protocol.RpcProtocolV2; import com.alipay.remoting.rpc.protocol.UserProcessor; +import com.alipay.remoting.util.GlobalSwitch; import com.alipay.remoting.util.RemotingUtil; import com.alipay.remoting.util.StringUtils; -import com.alipay.remoting.util.GlobalSwitch; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.PooledByteBufAllocator; +import io.netty.buffer.UnpooledByteBufAllocator; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelInitializer; @@ -78,7 +79,6 @@ public class RpcServer extends RemotingServer { /** logger */ private static final Logger logger = BoltLoggerFactory .getLogger("RpcRemoting"); - /** server bootstrap */ private ServerBootstrap bootstrap; @@ -200,10 +200,13 @@ protected void doInit() { // set write buffer water mark initWriteBufferWaterMark(); - boolean pooledBuffer = SystemProperties.netty_buffer_pooled(); - if (pooledBuffer) { + // init byte buf allocator + if (SystemProperties.netty_buffer_pooled()) { this.bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); + } else { + this.bootstrap.option(ChannelOption.ALLOCATOR, UnpooledByteBufAllocator.DEFAULT) + .childOption(ChannelOption.ALLOCATOR, UnpooledByteBufAllocator.DEFAULT); } final boolean idleSwitch = SystemProperties.tcp_idle_switch();