Skip to content

Commit e08a286

Browse files
chore: added logger warning and simplified ewma calculation
Signed-off-by: Theis Randeris Mathiassen <[email protected]>
1 parent 18e63b7 commit e08a286

File tree

1 file changed

+7
-9
lines changed
  • service/sharddistributor/store/etcd/executorstore

1 file changed

+7
-9
lines changed

service/sharddistributor/store/etcd/executorstore/etcdstore.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ func (s *executorStoreImpl) updateShardStatisticsFromHeartbeat(ctx context.Conte
178178

179179
for shardID, report := range reported {
180180
if report == nil {
181+
s.logger.Warn("empty report; skipping EWMA update",
182+
tag.ShardNamespace(namespace),
183+
tag.ShardExecutor(executorID),
184+
tag.ShardKey(shardID),
185+
)
181186
continue
182187
}
183188

@@ -820,19 +825,12 @@ func (s *executorStoreImpl) applyShardStatisticsUpdates(ctx context.Context, nam
820825
}
821826
}
822827

823-
// ewmaSmoothedLoad computes an EWMA for shard load.
824828
func ewmaSmoothedLoad(prev, current float64, lastUpdate, now int64) float64 {
825829
const tauSeconds = 30.0 // smaller = more responsive, larger = smoother, slower
826-
if lastUpdate <= 0 {
827-
return current
828-
}
829-
dt := now - lastUpdate
830-
if dt < 0 {
831-
dt = 0
832-
}
833-
if tauSeconds <= 0 {
830+
if lastUpdate <= 0 || tauSeconds <= 0 {
834831
return current
835832
}
833+
dt := max(now-lastUpdate, 0)
836834
alpha := 1 - math.Exp(-float64(dt)/tauSeconds)
837835
return (1-alpha)*prev + alpha*current
838836
}

0 commit comments

Comments
 (0)