add duty cycle config flag

This commit is contained in:
Samir Patel 2021-06-14 10:48:52 -05:00
parent 011291f19b
commit 8bf472bb75
4 changed files with 18 additions and 3 deletions

10
api.go
View file

@ -1061,15 +1061,21 @@ func (api *API) calculateUsage() {
}
// Periodically calculates disk usage
func (api *API) RefreshUsageCache() {
func (api *API) RefreshUsageCache(dutyCycle float64) {
trigger := make(chan bool)
defer close(trigger)
if dutyCycle <= 0 {
dutyCycle = 20
}
multiplier := int(math.Ceil(100/dutyCycle)) - 1
api.usageCache = &usageCache{
data: make(map[string]NodeUsage),
refreshInterval: time.Hour,
resetTrigger: trigger,
lastCalcDuration: 0,
waitMultiplier: time.Duration(5),
waitMultiplier: time.Duration(multiplier),
}
for {
start := time.Now()

View file

@ -110,4 +110,7 @@ func BuildServerFlags(cmd *cobra.Command, srv *server.Command) {
flags.DurationVar((*time.Duration)(&srv.Config.Postgres.WriteTimeout), "postgres.write-timeout", time.Duration(srv.Config.Postgres.WriteTimeout), "Timeout for writes on a postgres connection. (set 0 to disable)")
flags.Uint32Var(&srv.Config.Postgres.MaxStartupSize, "postgres.max-startup-size", srv.Config.Postgres.MaxStartupSize, "Maximum acceptable size of a postgres startup packet, in bytes. (set 0 to disable)")
flags.Uint16Var(&srv.Config.Postgres.ConnectionLimit, "postgres.connection-limit", srv.Config.Postgres.ConnectionLimit, "Maximum number of simultaneous postgres connections to allow. (set 0 to disable)")
// Disk and Memory usage cache for ui/usage endpoint
flags.Float64Var(&srv.Config.UsageDutyCycle, "usage-duty-cycle", srv.Config.UsageDutyCycle, "Sets the percentage of time that is spent recalculating the disk and memory usage cache. 100.0 for always-running, must be > 0.")
}

View file

@ -224,6 +224,9 @@ type Config struct {
// LookupDBDSN is an external database to connect to for `ExternalLookup` queries.
LookupDBDSN string `toml:"lookup-db-dsn"`
// The percentage of time spent recalculating the disk and memory usage cache.
UsageDutyCycle float64 `toml:"usage-duty-cycle"`
}
// MustValidate checks that all ports in a Config are unique and not zero.
@ -359,6 +362,9 @@ func NewConfig() *Config {
c.Etcd.PeerCertFile = ""
c.Etcd.PeerKeyFile = ""
// Disk and Memory Usage
c.UsageDutyCycle = 20.0
return c
}

View file

@ -277,7 +277,7 @@ func (m *Command) Start() (err error) {
}
}
go m.API.RefreshUsageCache()
go m.API.RefreshUsageCache(m.Config.UsageDutyCycle)
_ = testhook.Opened(pilosa.NewAuditor(), m, nil)
close(m.Started)