13 Star 50 Fork 0

Gitee 极速下载/etcd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/coreos/etcd
克隆/下载
status.go 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
XiangLi 提交于 2015-08-03 09:06 . Godeps: add probing dependency
package probing
import (
"sync"
"time"
)
var (
// weight factor
α = 0.125
)
type Status interface {
Total() int64
Loss() int64
Health() bool
// Estimated smoothed round trip time
SRTT() time.Duration
// Estimated clock difference
ClockDiff() time.Duration
StopNotify() <-chan struct{}
}
type status struct {
mu sync.Mutex
srtt time.Duration
total int64
loss int64
health bool
clockdiff time.Duration
stopC chan struct{}
}
// SRTT = (1-α) * SRTT + α * RTT
func (s *status) SRTT() time.Duration {
s.mu.Lock()
defer s.mu.Unlock()
return s.srtt
}
func (s *status) Total() int64 {
s.mu.Lock()
defer s.mu.Unlock()
return s.total
}
func (s *status) Loss() int64 {
s.mu.Lock()
defer s.mu.Unlock()
return s.loss
}
func (s *status) Health() bool {
s.mu.Lock()
defer s.mu.Unlock()
return s.health
}
func (s *status) ClockDiff() time.Duration {
s.mu.Lock()
defer s.mu.Unlock()
return s.clockdiff
}
func (s *status) StopNotify() <-chan struct{} {
return s.stopC
}
func (s *status) record(rtt time.Duration, when time.Time) {
s.mu.Lock()
defer s.mu.Unlock()
s.total += 1
s.health = true
s.srtt = time.Duration((1-α)*float64(s.srtt) + α*float64(rtt))
s.clockdiff = time.Now().Sub(when) - s.srtt/2
}
func (s *status) recordFailure() {
s.mu.Lock()
defer s.mu.Unlock()
s.total++
s.health = false
s.loss += 1
}
func (s *status) reset() {
s.mu.Lock()
defer s.mu.Unlock()
s.srtt = 0
s.total = 0
s.health = false
s.clockdiff = 0
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/etcd.git
git@gitee.com:mirrors/etcd.git
mirrors
etcd
etcd
v2.3.3

搜索帮助