Skip to content

Commit

Permalink
update IdleStateHandlerReadWriteTimer (#13576)
Browse files Browse the repository at this point in the history
Co-authored-by: Annie Liang <[email protected]>
  • Loading branch information
xinlian12 and Annie Liang authored Jul 28, 2020
1 parent 6e27b14 commit b8f57ff
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ public static final class Options {
@JsonProperty()
private final Duration idleChannelTimeout;

@JsonProperty()
private final Duration idleChannelTimerResolution;

@JsonProperty()
private final Duration idleEndpointTimeout;

Expand Down Expand Up @@ -316,6 +319,7 @@ private Options(final Builder builder) {
this.bufferPageSize = builder.bufferPageSize;
this.connectionAcquisitionTimeout = builder.connectionAcquisitionTimeout;
this.idleChannelTimeout = builder.idleChannelTimeout;
this.idleChannelTimerResolution = builder.idleChannelTimerResolution;
this.idleEndpointTimeout = builder.idleEndpointTimeout;
this.maxBufferCapacity = builder.maxBufferCapacity;
this.maxChannelsPerEndpoint = builder.maxChannelsPerEndpoint;
Expand All @@ -339,6 +343,7 @@ private Options(final ConnectionPolicy connectionPolicy) {
this.connectionAcquisitionTimeout = Duration.ZERO;
this.connectTimeout = connectionPolicy.getConnectTimeout();
this.idleChannelTimeout = connectionPolicy.getIdleTcpConnectionTimeout();
this.idleChannelTimerResolution = Duration.ofMillis(100);
this.idleEndpointTimeout = connectionPolicy.getIdleEndpointTimeout();
this.maxBufferCapacity = 8192 << 10;
this.maxChannelsPerEndpoint = connectionPolicy.getMaxConnectionsPerEndpoint();
Expand Down Expand Up @@ -373,6 +378,8 @@ public Duration idleChannelTimeout() {
return this.idleChannelTimeout;
}

public Duration idleChannelTimerResolution() { return this.idleChannelTimerResolution; }

public Duration idleEndpointTimeout() {
return this.idleEndpointTimeout;
}
Expand Down Expand Up @@ -546,6 +553,7 @@ public static class Builder {
private Duration connectionAcquisitionTimeout;
private Duration connectTimeout;
private Duration idleChannelTimeout;
private Duration idleChannelTimerResolution;
private Duration idleEndpointTimeout;
private int maxBufferCapacity;
private int maxChannelsPerEndpoint;
Expand All @@ -569,6 +577,7 @@ public Builder(ConnectionPolicy connectionPolicy) {
this.connectionAcquisitionTimeout = DEFAULT_OPTIONS.connectionAcquisitionTimeout;
this.connectTimeout = connectionPolicy.getConnectTimeout();
this.idleChannelTimeout = connectionPolicy.getIdleTcpConnectionTimeout();
this.idleChannelTimerResolution = DEFAULT_OPTIONS.idleChannelTimerResolution;
this.idleEndpointTimeout = DEFAULT_OPTIONS.idleEndpointTimeout;
this.maxBufferCapacity = DEFAULT_OPTIONS.maxBufferCapacity;
this.maxChannelsPerEndpoint = connectionPolicy.getMaxConnectionsPerEndpoint();
Expand Down Expand Up @@ -623,6 +632,12 @@ public Builder idleChannelTimeout(final Duration value) {
return this;
}

public Builder idleChannelTimerResolution(final Duration value) {
checkNotNull(value, "expected non-null value");
this.idleChannelTimerResolution = value;
return this;
}

public Builder idleEndpointTimeout(final Duration value) {
checkArgument(value != null && value.compareTo(Duration.ZERO) > 0,
"expected positive value, not %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ protected void initChannel(final Channel channel) {

checkNotNull(channel);

final RntbdRequestManager requestManager = new RntbdRequestManager(this.healthChecker, this.config.maxRequestsPerChannel());
final long readerIdleTime = this.config.receiveHangDetectionTimeInNanos();
final long writerIdleTime = this.config.sendHangDetectionTimeInNanos();
final long allIdleTime = this.config.idleConnectionTimeoutInNanos();
final RntbdRequestManager requestManager = new RntbdRequestManager(
this.healthChecker,
this.config.maxRequestsPerChannel());
final long idleConnectionTimerResolutionInNanos = config.idleConnectionTimerResolutionInNanos();
final ChannelPipeline pipeline = channel.pipeline();

pipeline.addFirst(
Expand All @@ -114,8 +114,11 @@ protected void initChannel(final Channel channel) {

pipeline.addFirst(
this.config.sslContext().newHandler(channel.alloc()),
new IdleStateHandler(readerIdleTime, writerIdleTime, allIdleTime, TimeUnit.NANOSECONDS)
);
new IdleStateHandler(
idleConnectionTimerResolutionInNanos,
idleConnectionTimerResolutionInNanos,
0,
TimeUnit.NANOSECONDS));

channel.attr(REQUEST_MANAGER).set(requestManager);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public long idleConnectionTimeoutInNanos() {
return this.options.idleChannelTimeout().toNanos();
}

@JsonProperty
public long idleConnectionTimerResolutionInNanos() {
return this.options.idleChannelTimerResolution().toNanos();
}

@JsonProperty
public long idleEndpointTimeoutInNanos() {
return this.options.idleEndpointTimeout().toNanos();
Expand Down

0 comments on commit b8f57ff

Please sign in to comment.