Skip to content

Commit

Permalink
optimize the evict parameter of channel pool at netty remoting client
Browse files Browse the repository at this point in the history
  • Loading branch information
huabao.fang committed Sep 5, 2022
1 parent 89cc09f commit 6f557d3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public long getChannelPoolTimeBetweenEvictionRunsMillis() {
return nettyClientConfig.getChannelPoolTimeBetweenEvictionRunsMillis();
}

@Override
public long getChannelPoolSoftMinEvictableIdleTimeMillis() {
return nettyClientConfig.getChannelPoolSoftMinEvictableIdleTimeMillis();
}

@Override
public int getNumTestsPerEvictionRun() {
return nettyClientConfig.getNumTestsPerEvictionRun();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class NettyClientProperties extends NettyProperties implements NettyClien
private int channelPoolMinIdlePerKey = 1;
private long channelPoolMaxWaitMillis = 300L;
private long channelPoolTimeBetweenEvictionRunsMillis = 10 * 1000L;
private long channelPoolSoftMinEvictableIdleTimeMillis = 30 * 60 * 1000L;
private int numTestsPerEvictionRun = 2;
//check the max idle time of client channel, if exceed, then send heartbeat message to keepalive the channel,
//need < channelIdleTimeoutSeconds(60) in ServerConfig
Expand Down Expand Up @@ -111,4 +112,13 @@ public int getReconnectIntervalSeconds() {
public void setReconnectIntervalSeconds(int reconnectIntervalSeconds) {
this.reconnectIntervalSeconds = reconnectIntervalSeconds;
}

@Override
public long getChannelPoolSoftMinEvictableIdleTimeMillis() {
return channelPoolSoftMinEvictableIdleTimeMillis;
}

public void setChannelPoolSoftMinEvictableIdleTimeMillis(long channelPoolSoftMinEvictableIdleTimeMillis) {
this.channelPoolSoftMinEvictableIdleTimeMillis = channelPoolSoftMinEvictableIdleTimeMillis;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public interface NettyClientConfig extends NettyConfig {

long getChannelPoolTimeBetweenEvictionRunsMillis();

long getChannelPoolSoftMinEvictableIdleTimeMillis();

int getNumTestsPerEvictionRun();

int getChannelMaxIdleTimeSeconds();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void invokeOneway(String address, RemotingCommand request, long timeoutMi
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
if (!channelFuture.isSuccess()) {
logger.warn("send a request command to channel <{}> failed.",NetUtils.parseSocketAddress(socketAddress));
logger.warn("send a request command to channel <{}> failed.", NetUtils.parseSocketAddress(socketAddress));
}
}
});
Expand Down Expand Up @@ -322,6 +322,8 @@ private GenericKeyedObjectPoolConfig<Channel> getChannelPoolConfig(NettyClientCo
config.setMaxWaitMillis(nettyClientConfig.getChannelPoolMaxWaitMillis());
config.setBlockWhenExhausted(true);

config.setMinEvictableIdleTimeMillis(-1);
config.setSoftMinEvictableIdleTimeMillis(nettyClientConfig.getChannelPoolSoftMinEvictableIdleTimeMillis());

return config;
}
Expand All @@ -335,4 +337,4 @@ protected void channelRead0(ChannelHandlerContext ctx, RemotingCommand cmd) thro
}


}
}

0 comments on commit 6f557d3

Please sign in to comment.