Skip to content

Commit

Permalink
(tuning) modify buffer allocator type
Browse files Browse the repository at this point in the history
 fix #9 (#23)
  • Loading branch information
xmtsui authored May 17, 2018
1 parent 36b1326 commit 1f28079
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/alipay/remoting/rpc/RpcConnectionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/alipay/remoting/rpc/RpcServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -78,7 +79,6 @@ public class RpcServer extends RemotingServer {
/** logger */
private static final Logger logger = BoltLoggerFactory
.getLogger("RpcRemoting");

/** server bootstrap */
private ServerBootstrap bootstrap;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 1f28079

Please sign in to comment.