-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstats.go
More file actions
40 lines (35 loc) · 899 Bytes
/
stats.go
File metadata and controls
40 lines (35 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package hedge
import "sync/atomic"
type Stats struct {
TotalRequests atomic.Int64
HedgedRequests atomic.Int64
HedgeWins atomic.Int64
PrimaryWins atomic.Int64
BudgetExhausted atomic.Int64
WarmupRequests atomic.Int64
}
type StatsSnapshot struct {
TotalRequests int64
HedgedRequests int64
HedgeWins int64
PrimaryWins int64
BudgetExhausted int64
WarmupRequests int64
}
func (s *Stats) Snapshot() StatsSnapshot {
return StatsSnapshot{
TotalRequests: s.TotalRequests.Load(),
HedgedRequests: s.HedgedRequests.Load(),
HedgeWins: s.HedgeWins.Load(),
PrimaryWins: s.PrimaryWins.Load(),
BudgetExhausted: s.BudgetExhausted.Load(),
WarmupRequests: s.WarmupRequests.Load(),
}
}
func (s *Stats) HedgeRate() float64 {
total := s.TotalRequests.Load()
if total == 0 {
return 0
}
return float64(s.HedgedRequests.Load()) / float64(total)
}