allow to disable application layer heartbeat to reduce traffic cost (#2758)

fix #2754
This commit is contained in:
fatedier
2022-01-13 14:26:07 +08:00
committed by GitHub
parent 4bfc89d988
commit 293003fcdb
11 changed files with 228 additions and 146 deletions

View File

@@ -400,12 +400,19 @@ func (ctl *Control) manager() {
defer ctl.allShutdown.Start()
defer ctl.managerShutdown.Done()
heartbeat := time.NewTicker(time.Second)
defer heartbeat.Stop()
var heartbeatCh <-chan time.Time
if ctl.serverCfg.TCPMux || ctl.serverCfg.HeartbeatTimeout <= 0 {
// Don't need application heartbeat here.
// yamux will do same thing.
} else {
heartbeat := time.NewTicker(time.Second)
defer heartbeat.Stop()
heartbeatCh = heartbeat.C
}
for {
select {
case <-heartbeat.C:
case <-heartbeatCh:
if time.Since(ctl.lastPing) > time.Duration(ctl.serverCfg.HeartbeatTimeout)*time.Second {
xl.Warn("heartbeat timeout")
return