les: fixed totalRecharge calculation

This commit is contained in:
Zsolt Felfoldi 2019-05-03 19:39:24 +02:00
parent 94e1d9c739
commit ca8d218344

View file

@ -88,7 +88,7 @@ const (
gfMaxWeight = time.Second * 1000 gfMaxWeight = time.Second * 1000
gfUsageThreshold = 0.5 gfUsageThreshold = 0.5
gfUsageTC = time.Second gfUsageTC = time.Second
gfDbKey = "__globalCostFactor" gfDbKey = "_globalCostFactorV2"
) )
// costTracker is responsible for calculating costs and cost estimates on the // costTracker is responsible for calculating costs and cost estimates on the
@ -220,6 +220,7 @@ func (ct *costTracker) gfLoop() {
} }
gf := gfSum / gfWeight gf := gfSum / gfWeight
ct.gf = gf ct.gf = gf
totalRecharge := ct.utilTarget * gf
ct.gfUpdateCh = make(chan gfUpdate, 100) ct.gfUpdateCh = make(chan gfUpdate, 100)
go func() { go func() {
@ -244,15 +245,13 @@ func (ct *costTracker) gfLoop() {
dt := float64(now - expUpdate) dt := float64(now - expUpdate)
expUpdate = now expUpdate = now
gfUsage = gfUsage*math.Exp(-dt/float64(gfUsageTC)) + max*1000000/float64(gfUsageTC) gfUsage = gfUsage*math.Exp(-dt/float64(gfUsageTC)) + max*1000000/float64(gfUsageTC)
totalRecharge := ct.utilTarget * gf
ct.logRecentUsage.Update(gfUsage)
ct.logTotalRecharge.Update(totalRecharge)
if gfUsage >= gfUsageThreshold*totalRecharge { if gfUsage >= gfUsageThreshold*totalRecharge {
gfSum += r.avgTime gfSum += r.avgTime
gfWeight += r.servingTime gfWeight += r.servingTime
if time.Duration(now-lastUpdate) > time.Second { if time.Duration(now-lastUpdate) > time.Second {
gf = gfSum / gfWeight gf = gfSum / gfWeight
totalRecharge = ct.utilTarget * gf
if gfWeight >= float64(gfMaxWeight) { if gfWeight >= float64(gfMaxWeight) {
gfSum = gf * float64(gfMaxWeight) gfSum = gf * float64(gfMaxWeight)
gfWeight = float64(gfMaxWeight) gfWeight = float64(gfMaxWeight)
@ -271,6 +270,9 @@ func (ct *costTracker) gfLoop() {
log.Debug("global cost factor updated", "gf", gf, "weight", time.Duration(gfWeight)) log.Debug("global cost factor updated", "gf", gf, "weight", time.Duration(gfWeight))
} }
} }
ct.logRecentUsage.Update(gfUsage)
ct.logTotalRecharge.Update(totalRecharge)
case stopCh := <-ct.stopCh: case stopCh := <-ct.stopCh:
var data [16]byte var data [16]byte
binary.BigEndian.PutUint64(data[0:8], math.Float64bits(gfSum)) binary.BigEndian.PutUint64(data[0:8], math.Float64bits(gfSum))