Skip to content

Commit

Permalink
Reduce GC overhead by call address.toString() in case of timeout only (
Browse files Browse the repository at this point in the history
  • Loading branch information
plokhotnyuk authored and slandelle committed Apr 23, 2017
1 parent e00c35b commit d86d481
Showing 1 changed file with 4 additions and 5 deletions.
Expand Up @@ -39,7 +39,7 @@ public class TimeoutsHolder {
private volatile NettyResponseFuture<?> nettyResponseFuture; private volatile NettyResponseFuture<?> nettyResponseFuture;
public final Timeout requestTimeout; public final Timeout requestTimeout;
public volatile Timeout readTimeout; public volatile Timeout readTimeout;
private volatile String remoteAddress = "not-connected"; private volatile InetSocketAddress remoteAddress;


public TimeoutsHolder(Timer nettyTimer, NettyResponseFuture<?> nettyResponseFuture, NettyRequestSender requestSender, AsyncHttpClientConfig config) { public TimeoutsHolder(Timer nettyTimer, NettyResponseFuture<?> nettyResponseFuture, NettyRequestSender requestSender, AsyncHttpClientConfig config) {
this.nettyTimer = nettyTimer; this.nettyTimer = nettyTimer;
Expand All @@ -66,7 +66,7 @@ public TimeoutsHolder(Timer nettyTimer, NettyResponseFuture<?> nettyResponseFutu
} }


public void initRemoteAddress(InetSocketAddress address) { public void initRemoteAddress(InetSocketAddress address) {
remoteAddress = address.toString(); remoteAddress = address;
} }


public void startReadTimeout() { public void startReadTimeout() {
Expand All @@ -82,8 +82,7 @@ void startReadTimeout(ReadTimeoutTimerTask task) {
// first call triggered from outside (else is read timeout is re-scheduling itself) // first call triggered from outside (else is read timeout is re-scheduling itself)
task = new ReadTimeoutTimerTask(nettyResponseFuture, requestSender, this, readTimeoutValue); task = new ReadTimeoutTimerTask(nettyResponseFuture, requestSender, this, readTimeoutValue);
} }
Timeout readTimeout = newTimeout(task, readTimeoutValue); this.readTimeout = newTimeout(task, readTimeoutValue);
this.readTimeout = readTimeout;


} else if (task != null) { } else if (task != null) {
// read timeout couldn't re-scheduling itself, clean up // read timeout couldn't re-scheduling itself, clean up
Expand All @@ -109,6 +108,6 @@ private Timeout newTimeout(TimerTask task, long delay) {
} }


String remoteAddress() { String remoteAddress() {
return remoteAddress; return remoteAddress == null ? "not-connected" : remoteAddress.toString();
} }
} }

0 comments on commit d86d481

Please sign in to comment.