Skip to content

Commit

Permalink
Performance tuning: keep heartbeat updated in io thread to avoid race…
Browse files Browse the repository at this point in the history
… condition. (#4246)
  • Loading branch information
chickenlj authored Jun 4, 2019
1 parent faec551 commit 4c35890
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public abstract class AbstractTimerTask implements TimerTask {
}

static Long lastRead(Channel channel) {
return (Long) channel.getAttribute(HeaderExchangeHandler.KEY_READ_TIMESTAMP);
return (Long) channel.getAttribute(HeartbeatHandler.KEY_READ_TIMESTAMP);
}

static Long lastWrite(Channel channel) {
return (Long) channel.getAttribute(HeaderExchangeHandler.KEY_WRITE_TIMESTAMP);
return (Long) channel.getAttribute(HeartbeatHandler.KEY_WRITE_TIMESTAMP);
}

static Long now() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ public class HeaderExchangeHandler implements ChannelHandlerDelegate {

protected static final Logger logger = LoggerFactory.getLogger(HeaderExchangeHandler.class);

public static final String KEY_READ_TIMESTAMP = HeartbeatHandler.KEY_READ_TIMESTAMP;

public static final String KEY_WRITE_TIMESTAMP = HeartbeatHandler.KEY_WRITE_TIMESTAMP;

private final ExchangeHandler handler;

public HeaderExchangeHandler(ExchangeHandler handler) {
Expand Down Expand Up @@ -125,8 +121,6 @@ void handleRequest(final ExchangeChannel channel, Request req) throws RemotingEx

@Override
public void connected(Channel channel) throws RemotingException {
channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
try {
handler.connected(exchangeChannel);
Expand All @@ -137,8 +131,6 @@ public void connected(Channel channel) throws RemotingException {

@Override
public void disconnected(Channel channel) throws RemotingException {
channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
try {
handler.disconnected(exchangeChannel);
Expand All @@ -152,7 +144,6 @@ public void disconnected(Channel channel) throws RemotingException {
public void sent(Channel channel, Object message) throws RemotingException {
Throwable exception = null;
try {
channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
try {
handler.sent(exchangeChannel, message);
Expand Down Expand Up @@ -180,7 +171,6 @@ public void sent(Channel channel, Object message) throws RemotingException {

@Override
public void received(Channel channel, Object message) throws RemotingException {
channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
final ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
try {
if (message instanceof Request) {
Expand Down

0 comments on commit 4c35890

Please sign in to comment.