mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 00:22:41 +08:00
cache
This commit is contained in:
43
cache/qps.go
vendored
Normal file
43
cache/qps.go
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
type qps struct {
|
||||
all qpsContent
|
||||
memoryTotal qpsContent
|
||||
memoryHit qpsContent
|
||||
redisTotal qpsContent
|
||||
redisHit qpsContent
|
||||
sourceTotal qpsContent
|
||||
}
|
||||
|
||||
type qpsContent struct {
|
||||
viewTotal int64
|
||||
total int64
|
||||
}
|
||||
|
||||
func NewQps() *qps {
|
||||
qps := &qps{}
|
||||
go qps.statisticsTotal()
|
||||
return qps
|
||||
}
|
||||
|
||||
func (q *qps) statisticsTotal() {
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
}
|
||||
}()
|
||||
|
||||
ticker := time.NewTicker(time.Second)
|
||||
for range ticker.C {
|
||||
q.all.viewTotal = atomic.SwapInt64(&q.all.total, 0)
|
||||
q.memoryTotal.viewTotal = atomic.SwapInt64(&q.memoryTotal.total, 0)
|
||||
q.memoryHit.viewTotal = atomic.SwapInt64(&q.memoryHit.total, 0)
|
||||
q.redisTotal.viewTotal = atomic.SwapInt64(&q.redisTotal.total, 0)
|
||||
q.redisHit.viewTotal = atomic.SwapInt64(&q.redisHit.total, 0)
|
||||
q.sourceTotal.viewTotal = atomic.SwapInt64(&q.sourceTotal.total, 0)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user