com.netflix.fenzo.plugins.BalancedScaleDownConstraintEvaluator Maven / Gradle / Ivy
/*
* Copyright 2017 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.netflix.fenzo.plugins;
import com.netflix.fenzo.ScaleDownConstraintEvaluator;
import com.netflix.fenzo.VirtualMachineLease;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
/**
* Evaluator that tries to keep the same number of idle instances in each zone/region.
* As the number of instances may be large, and for each subsequent instance within a group we need to increase the
* score, we add exponentially increasing increments to the initial scoring.
*
* Example
* Lets assume that:
*
* - There are two zones Za and Zb
* - Zone Za has five idle instances, and zone Zb three
* - The initial score is 0.5, and the initial step is 0.1
*
* The subsequent scores for a single zone will be: 0.5, 0.6, 0.65, 0.675, 0.6875, etc.
* Int the given example we will get:
*
* - Za(1)=0.5, Za(2)=0.6, Za(3)=0.65, Za(4)=0.675, Za(5)=0.6875
* - Zb(1)=0.5, Zb(2)=0.6, Zb(3)=0.65
*
* Assuming the zone balancing is the only evaluation criteria, the termination order (according to the highest score)
* for four instances will be: Za(5), Za(4), Za(3), Zb(3). In the end zones Za and Zb will be left with the same
* number of instances.
*/
public class BalancedScaleDownConstraintEvaluator implements ScaleDownConstraintEvaluator