Skip to content

Commit

Permalink
make maxreplicas configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-lombardi committed Oct 30, 2024
1 parent dadcdfb commit f2a991d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
5 changes: 2 additions & 3 deletions pkg/abstractions/common/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ type IAutoscaler interface {
}

const (
MaxReplicas uint = 10 // Maximum number of desired replicas that can be returned
windowSize int = 60 // Number of samples in the sampling window
sampleRate time.Duration = time.Duration(1000) * time.Millisecond // Time between samples
windowSize int = 60 // Number of samples in the sampling window
sampleRate time.Duration = time.Duration(1000) * time.Millisecond // Time between samples
)

type AutoscalerSample interface{}
Expand Down
4 changes: 2 additions & 2 deletions pkg/abstractions/endpoint/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func endpointDeploymentScaleFunc(i *endpointInstance, s *endpointAutoscalerSampl
desiredContainers += 1
}

// Limit max replicas to either what was set in autoscaler config, or our default of MaxReplicas (whichever is lower)
maxReplicas := math.Min(float64(i.StubConfig.Autoscaler.MaxContainers), float64(abstractions.MaxReplicas))
// Limit max replicas to either what was set in autoscaler config, or the limit specified on the gateway config (whichever is lower)
maxReplicas := math.Min(float64(i.StubConfig.Autoscaler.MaxContainers), float64(i.AppConfig.GatewayService.StubLimits.MaxReplicas))
desiredContainers = int(math.Min(maxReplicas, float64(desiredContainers)))
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/abstractions/taskqueue/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func taskQueueScaleFunc(i *taskQueueInstance, s *taskQueueAutoscalerSample) *abs
desiredContainers += 1
}

// Limit max replicas to either what was set in autoscaler config, or our default of MaxReplicas (whichever is lower)
maxReplicas := math.Min(float64(i.StubConfig.Autoscaler.MaxContainers), float64(abstractions.MaxReplicas))
// Limit max replicas to either what was set in autoscaler config, or the limit specified on the gateway config (whichever is lower)
maxReplicas := math.Min(float64(i.StubConfig.Autoscaler.MaxContainers), float64(i.AppConfig.GatewayService.StubLimits.MaxReplicas))
desiredContainers = int(math.Min(maxReplicas, float64(desiredContainers)))
}

Expand Down
1 change: 1 addition & 0 deletions pkg/common/config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ gateway:
shutdownTimeout: 180s
stubLimits:
memory: 32768
maxReplicas: 10
imageService:
localCacheEnabled: true
registryStore: local
Expand Down
3 changes: 2 additions & 1 deletion pkg/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ type CORSConfig struct {
}

type StubLimits struct {
Memory uint64 `key:"memory" json:"memory"`
Memory uint64 `key:"memory" json:"memory"`
MaxReplicas uint64 `key:"maxReplicas" json:"max_replicas"`
}

type GatewayServiceConfig struct {
Expand Down

0 comments on commit f2a991d

Please sign in to comment.