Skip to content

Commit 8497e4f

Browse files
committed
Allow scaling parameters to be changed from command-line
1 parent 1056d09 commit 8497e4f

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

pkg/chunk/aws/metrics_autoscaling.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ import (
1919
const (
2020
cachePromDataFor = 30 * time.Second
2121
queueObservationPeriod = 2 * time.Minute
22-
queueLengthScaledown = 10000 // consider scaling down if queue smaller than this
23-
queueLengthAcceptable = 100000 // we don't mind queues smaller than this
24-
queueLengthMax = 1000000 // always scale up if queue bigger than this
22+
targetScaledown = 0.1 // consider scaling down if queue smaller than this times target
23+
targetMax = 10 // always scale up if queue bigger than this times target
2524
errorFractionScaledown = 0.1
2625
scaledown = 0.9
2726
scaleup = 1.2
2827
)
2928

3029
type metricsData struct {
31-
promAPI promV1.API
32-
lastUpdated time.Time
33-
queueLengths []float64
34-
errorRates map[string]float64
30+
queueLengthTarget int64
31+
promAPI promV1.API
32+
lastUpdated time.Time
33+
queueLengths []float64
34+
errorRates map[string]float64
3535
}
3636

3737
func (d dynamoTableClient) metricsAutoScale(ctx context.Context, current, expected *chunk.TableDesc) error {
@@ -49,14 +49,14 @@ func (d dynamoTableClient) metricsAutoScale(ctx context.Context, current, expect
4949

5050
switch {
5151
case errorRate < errorFractionScaledown*float64(current.ProvisionedWrite) &&
52-
m.queueLengths[2] < queueLengthScaledown:
52+
m.queueLengths[2] < float64(m.queueLengthTarget)*targetScaledown:
5353
// No big queue, low errors -> scale down
5454
scaleDownWrite(current, expected, int64(float64(current.ProvisionedWrite)*scaledown), "metrics scale-down")
55-
case errorRate > 0 && m.queueLengths[2] > queueLengthMax:
55+
case errorRate > 0 && m.queueLengths[2] > float64(m.queueLengthTarget)*targetMax:
5656
// Too big queue, some errors -> scale up
5757
scaleUpWrite(current, expected, int64(float64(current.ProvisionedWrite)*scaleup), "metrics max queue scale-up")
5858
case errorRate > 0 &&
59-
m.queueLengths[2] > queueLengthAcceptable &&
59+
m.queueLengths[2] > float64(m.queueLengthTarget) &&
6060
m.queueLengths[2] > m.queueLengths[1] && m.queueLengths[1] > m.queueLengths[0]:
6161
// Growing queue, some errors -> scale up
6262
scaleUpWrite(current, expected, int64(float64(current.ProvisionedWrite)*scaleup), "metrics queue growing scale-up")
@@ -93,7 +93,10 @@ func newMetrics(cfg DynamoDBConfig) (*metricsData, error) {
9393
}
9494
promAPI = promV1.NewAPI(client)
9595
}
96-
return &metricsData{promAPI: promAPI}, nil
96+
return &metricsData{
97+
promAPI: promAPI,
98+
queueLengthTarget: cfg.MetricsTargetQueueLen,
99+
}, nil
97100
}
98101

99102
func (m *metricsData) update(ctx context.Context) error {

pkg/chunk/aws/metrics_autoscaling_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestTableManagerMetricsAutoScaling(t *testing.T) {
2424

2525
client := dynamoTableClient{
2626
DynamoDB: dynamoDB,
27-
metrics: &metricsData{promAPI: &mockProm},
27+
metrics: &metricsData{promAPI: &mockProm, queueLengthTarget: 100000},
2828
}
2929

3030
// Set up table-manager config

pkg/chunk/aws/storage_client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ type DynamoDBConfig struct {
104104
APILimit float64
105105
ApplicationAutoScaling util.URLValue
106106
MetricsURL string
107+
MetricsTargetQueueLen int64
107108
ChunkGangSize int
108109
ChunkGetMaxParallelism int
109110
backoffConfig util.BackoffConfig
@@ -116,6 +117,7 @@ func (cfg *DynamoDBConfig) RegisterFlags(f *flag.FlagSet) {
116117
f.Float64Var(&cfg.APILimit, "dynamodb.api-limit", 2.0, "DynamoDB table management requests per second limit.")
117118
f.Var(&cfg.ApplicationAutoScaling, "applicationautoscaling.url", "ApplicationAutoscaling endpoint URL with escaped Key and Secret encoded.")
118119
f.StringVar(&cfg.MetricsURL, "metrics.url", "", "Use metrics-based autoscaling, via this query URL")
120+
f.Int64Var(&cfg.MetricsTargetQueueLen, "metrics.target-queue-length", 100000, "Queue length above which we will scale up capacity")
119121
f.IntVar(&cfg.ChunkGangSize, "dynamodb.chunk.gang.size", 10, "Number of chunks to group together to parallelise fetches (zero to disable)")
120122
f.IntVar(&cfg.ChunkGetMaxParallelism, "dynamodb.chunk.get.max.parallelism", 32, "Max number of chunk-get operations to start in parallel")
121123
f.DurationVar(&cfg.backoffConfig.MinBackoff, "dynamodb.min-backoff", 100*time.Millisecond, "Minimum backoff time")

0 commit comments

Comments
 (0)