Skip to content

Commit

Permalink
fix(appengine): capacity values for automatic scaling (#1568)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeach committed Apr 12, 2017
1 parent 8ad8f29 commit 6f0010d
Showing 1 changed file with 22 additions and 4 deletions.
Expand Up @@ -88,10 +88,8 @@ class AppengineServerGroup implements ServerGroup, Serializable {
* For the flexible environment, a version using automatic scaling can be stopped.
* A stopped version scales down to zero instances and ignores its scaling policy.
* */
def min = servingStatus == ServingStatus.SERVING ?
[scalingPolicy.minTotalInstances, scalingPolicy.minIdleInstances].max() : 0
def max = servingStatus == ServingStatus.SERVING ?
[scalingPolicy.maxTotalInstances, scalingPolicy.maxIdleInstances, instanceCount].max() : instanceCount
def min = computeMinForAutomaticScaling(scalingPolicy)
def max = computeMaxForAutomaticScaling(scalingPolicy)
return new ServerGroup.Capacity(min: min,
max: max,
desired: min)
Expand All @@ -114,6 +112,26 @@ class AppengineServerGroup implements ServerGroup, Serializable {
}
}

Integer computeMinForAutomaticScaling(AppengineScalingPolicy scalingPolicy) {
Integer instanceCount = instances?.size() ?: 0
if (servingStatus == ServingStatus.SERVING) {
def candidateMinValues = [scalingPolicy.minIdleInstances, scalingPolicy.minTotalInstances, instanceCount].findAll { it != null }
return candidateMinValues.min()
} else {
return 0
}
}

Integer computeMaxForAutomaticScaling(AppengineScalingPolicy scalingPolicy) {
Integer instanceCount = instances?.size() ?: 0
if (servingStatus == ServingStatus.SERVING) {
def candidateMaxValues = [scalingPolicy.maxIdleInstances, scalingPolicy.maxTotalInstances, instanceCount].findAll { it != null }
return candidateMaxValues.max()
} else {
return instanceCount
}
}

static Boolean versionAllowsGradualTrafficMigration(Version version) {
// Versions do not always have an env property if they are in the standard environment.
def inStandardEnvironment = version.getEnv()?.toUpperCase() != "FLEXIBLE"
Expand Down

0 comments on commit 6f0010d

Please sign in to comment.