-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Optimize heartbeat #3299
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
Optimize heartbeat #3299
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,9 @@ | |
| import org.apache.dubbo.common.Constants; | ||
| import org.apache.dubbo.common.URL; | ||
| import org.apache.dubbo.common.timer.HashedWheelTimer; | ||
| import org.apache.dubbo.common.timer.Timeout; | ||
| import org.apache.dubbo.common.utils.Assert; | ||
| import org.apache.dubbo.common.utils.CollectionUtils; | ||
| import org.apache.dubbo.common.utils.NamedThreadFactory; | ||
| import org.apache.dubbo.remoting.ChannelHandler; | ||
| import org.apache.dubbo.remoting.Client; | ||
|
|
@@ -30,7 +32,9 @@ | |
| import org.apache.dubbo.remoting.exchange.ResponseFuture; | ||
|
|
||
| import java.net.InetSocketAddress; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| /** | ||
|
|
@@ -43,9 +47,11 @@ public class HeaderExchangeClient implements ExchangeClient { | |
| private int heartbeat; | ||
| private int idleTimeout; | ||
|
|
||
| private static HashedWheelTimer idleCheckTimer = new HashedWheelTimer(new NamedThreadFactory("dubbo-client-idleCheck", true), 1, | ||
| private static final HashedWheelTimer IDLE_CHECK_TIMER = new HashedWheelTimer(new NamedThreadFactory("dubbo-client-idleCheck", true), 1, | ||
| TimeUnit.SECONDS, Constants.TICKS_PER_WHEEL); | ||
|
|
||
| private List<Timeout> tasks = new ArrayList<>(); | ||
|
|
||
| public HeaderExchangeClient(Client client, boolean needHeartbeat) { | ||
| Assert.notNull(client, "Client can't be null"); | ||
| this.client = client; | ||
|
|
@@ -183,11 +189,20 @@ private void startIdleCheckTask() { | |
| ReconnectTimerTask reconnectTimerTask = new ReconnectTimerTask(cp, heartbeatTimeoutTick, idleTimeout); | ||
|
|
||
| // init task and start timer. | ||
| idleCheckTimer.newTimeout(heartBeatTimerTask, heartbeatTick, TimeUnit.MILLISECONDS); | ||
| idleCheckTimer.newTimeout(reconnectTimerTask, heartbeatTimeoutTick, TimeUnit.MILLISECONDS); | ||
| Timeout heartBeatTimeout = IDLE_CHECK_TIMER.newTimeout(heartBeatTimerTask, heartbeatTick, TimeUnit.MILLISECONDS); | ||
| Timeout reconnectTimeout = IDLE_CHECK_TIMER.newTimeout(reconnectTimerTask, heartbeatTimeoutTick, TimeUnit.MILLISECONDS); | ||
|
|
||
| tasks.add(heartBeatTimeout); | ||
| tasks.add(reconnectTimeout); | ||
| } | ||
|
|
||
| private void doClose() { | ||
| if (CollectionUtils.isNotEmpty(tasks)) { | ||
| for (Timeout timeout : tasks) { | ||
| timeout.cancel(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. timeout.cancel will never success when the task has expired once,because in this case it's status will be ST_EXPIRED , and in this case, based on org.apache.dubbo.common.timer.HashedWheelTimer.HashedWheelTimeout#cancel method code as following compareAndSetState will always reture false. Am I right? |
||
| } | ||
| tasks.clear(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.