Skip to content

Commit

Permalink
Immediately scale up autoscaler for cold-start
Browse files Browse the repository at this point in the history
When the autoscaler gets a stat to scale a service up from 0 we should
act on this immediately in order to decrease cold-start time.

Closes #2961
  • Loading branch information
Gregory Haynes committed Jan 23, 2019
1 parent b51a370 commit 4be0da9
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/autoscaler/multiscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type UniScalerFactory func(*Metric, *DynamicConfig) (UniScaler, error)
type scalerRunner struct {
scaler UniScaler
stopCh chan struct{}
pokeCh chan struct{}

// mux guards access to metric
mux sync.RWMutex
Expand Down Expand Up @@ -229,6 +230,7 @@ func (m *MultiScaler) createScaler(ctx context.Context, metric *Metric) (*scaler
scaler: scaler,
stopCh: stopCh,
metric: *metric,
pokeCh: make(chan struct{}),
}
runner.metric.Status.DesiredScale = -1

Expand All @@ -247,6 +249,8 @@ func (m *MultiScaler) createScaler(ctx context.Context, metric *Metric) (*scaler
return
case <-ticker.C:
m.tickScaler(ctx, scaler, scaleChan)
case <-runner.pokeCh:
m.tickScaler(ctx, scaler, scaleChan)
}
}
}()
Expand Down Expand Up @@ -300,6 +304,10 @@ func (m *MultiScaler) RecordStat(key string, stat Stat) {
if exists {
logger := m.logger.With(zap.String(logkey.Key, key))
ctx := logging.WithLogger(context.TODO(), logger)

scaler.scaler.Record(ctx, stat)
if scaler.metric.Status.DesiredScale == 0 && stat.PodName == ActivatorPodName {
scaler.pokeCh <- struct{}{}
}
}
}

0 comments on commit 4be0da9

Please sign in to comment.