mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
make a better array cyc-queue
This commit is contained in:
parent
f75c309d26
commit
10cdaea059
@ -8,9 +8,18 @@ import (
|
|||||||
"github.com/coreos/go-raft"
|
"github.com/coreos/go-raft"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
queueCapacity = 200
|
||||||
|
)
|
||||||
|
|
||||||
type runtimeStats struct {
|
type runtimeStats struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type packageStats struct {
|
||||||
|
sendingTime time.Time
|
||||||
|
size uint64
|
||||||
|
}
|
||||||
|
|
||||||
type raftServerStats struct {
|
type raftServerStats struct {
|
||||||
State string
|
State string
|
||||||
StartTime time.Time
|
StartTime time.Time
|
||||||
@ -21,6 +30,7 @@ type raftServerStats struct {
|
|||||||
SendAppendRequestCnt uint64
|
SendAppendRequestCnt uint64
|
||||||
SendAppendReqeustRate uint64
|
SendAppendReqeustRate uint64
|
||||||
sendRateQueue *list.List
|
sendRateQueue *list.List
|
||||||
|
recvRateQueue *list.List
|
||||||
SendingRate float64
|
SendingRate float64
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,3 +100,38 @@ func (ps *raftPeerStats) Succ(d time.Duration) {
|
|||||||
// sdv = sqrt(avg(x^2) - avg(x)^2)
|
// sdv = sqrt(avg(x^2) - avg(x)^2)
|
||||||
ps.SdvLatency = math.Sqrt(ps.avgLatencySquare - ps.AvgLatency*ps.AvgLatency)
|
ps.SdvLatency = math.Sqrt(ps.avgLatencySquare - ps.AvgLatency*ps.AvgLatency)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type statsQueue struct {
|
||||||
|
items [queueCapacity]*packageStats
|
||||||
|
size int
|
||||||
|
front int
|
||||||
|
back int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *statsQueue) Len() int {
|
||||||
|
return q.size
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *statsQueue) Front() *packageStats {
|
||||||
|
if q.size != 0 {
|
||||||
|
return q.items[q.front]
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *statsQueue) Back() *packageStats {
|
||||||
|
if q.size != 0 {
|
||||||
|
return q.items[q.back]
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *statsQueue) Insert(p *packageStats) {
|
||||||
|
q.back = (q.back + 1) % queueCapacity
|
||||||
|
q.items[q.back] = p
|
||||||
|
if q.size == queueCapacity {
|
||||||
|
q.front = (q.back + 1) % queueCapacity
|
||||||
|
} else {
|
||||||
|
q.size++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user