Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance tuning: keep heartbeat updated in io thread to avoid race condition. #4246

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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