Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combine statics goroutines into one #1012

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 12 additions & 27 deletions consumer/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,39 +172,23 @@ func newStatsItemSet(statsName string) *statsItemSet {

func (sis *statsItemSet) init() {
go primitive.WithRecover(func() {
ticker := time.NewTicker(10 * time.Second)
defer ticker.Stop()
secticker := time.NewTicker(10 * time.Second)
minticker := time.NewTicker(10 * time.Minute)
hourticker := time.NewTicker(time.Hour)
defer func() {
secticker.Stop()
minticker.Stop()
hourticker.Stop()
}()
for {
select {
case <-sis.closed:
return
case <-ticker.C:
case <-secticker.C:
sis.samplingInSeconds()
}
}
})

go primitive.WithRecover(func() {
ticker := time.NewTicker(10 * time.Minute)
defer ticker.Stop()
for {
select {
case <-sis.closed:
return
case <-ticker.C:
case <-minticker.C:
sis.samplingInMinutes()
}
}
})

go primitive.WithRecover(func() {
ticker := time.NewTicker(time.Hour)
defer ticker.Stop()
for {
select {
case <-sis.closed:
return
case <-ticker.C:
case <-hourticker.C:
sis.samplingInHour()
}
}
Expand All @@ -213,6 +197,7 @@ func (sis *statsItemSet) init() {
go primitive.WithRecover(func() {
time.Sleep(nextMinutesTime().Sub(time.Now()))
ticker := time.NewTicker(time.Minute)

defer ticker.Stop()
for {
select {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ require (
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0
stathat.com/c/consistent v1.0.0
)
)