Randomize period of ComputeInternalStateColumnStats to avoid CPU peaks
This commit is contained in:
parent
c723ba92e5
commit
a4e5418f50
11
blockbook.go
11
blockbook.go
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
"strings"
|
||||||
@ -123,6 +124,8 @@ func main() {
|
|||||||
|
|
||||||
defer glog.Flush()
|
defer glog.Flush()
|
||||||
|
|
||||||
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
|
|
||||||
chanOsSignal = make(chan os.Signal, 1)
|
chanOsSignal = make(chan os.Signal, 1)
|
||||||
signal.Notify(chanOsSignal, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
|
signal.Notify(chanOsSignal, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
|
||||||
|
|
||||||
@ -417,11 +420,13 @@ func storeInternalStateLoop() {
|
|||||||
close(stopCompute)
|
close(stopCompute)
|
||||||
close(chanStoreInternalStateDone)
|
close(chanStoreInternalStateDone)
|
||||||
}()
|
}()
|
||||||
glog.Info("storeInternalStateLoop starting")
|
|
||||||
lastCompute := time.Now()
|
|
||||||
var computeRunning bool
|
var computeRunning bool
|
||||||
|
lastCompute := time.Now()
|
||||||
|
// randomize the duration between ComputeInternalStateColumnStats to avoid peeks after reboot of machine with multiple blockbooks
|
||||||
|
computePeriod := 9*time.Hour + time.Duration(rand.Float64()*float64((2*time.Hour).Nanoseconds()))
|
||||||
|
glog.Info("storeInternalStateLoop starting with internal state compute period ", computePeriod)
|
||||||
tickAndDebounce(storeInternalStatePeriodMs*time.Millisecond, (storeInternalStatePeriodMs-1)*time.Millisecond, chanStoreInternalState, func() {
|
tickAndDebounce(storeInternalStatePeriodMs*time.Millisecond, (storeInternalStatePeriodMs-1)*time.Millisecond, chanStoreInternalState, func() {
|
||||||
if !computeRunning && lastCompute.Add(10*time.Hour).Before(time.Now()) {
|
if !computeRunning && lastCompute.Add(computePeriod).Before(time.Now()) {
|
||||||
computeRunning = true
|
computeRunning = true
|
||||||
go func() {
|
go func() {
|
||||||
err := index.ComputeInternalStateColumnStats(stopCompute)
|
err := index.ComputeInternalStateColumnStats(stopCompute)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user