def calculate_vm_dist_decay()

in hostfactory/host_provider/src/allocation_strategy.py [0:0]


def calculate_vm_dist_decay(vm_types, total_slot_count):
    '''
    Calculate Slots by applying a decreasing distribution : 
    weighted_increment_per_sku = [ num_skus / (1 + idx)  for idx in range(num_skus) ]

    This method is more appropriate for scaling to relatively large slot counts.
    If the incremental slot count increase is small, it will be indistinguishable 
    from the price based allocation.

    vm_types: list of skus to consider for allocation
    total_slot_count: total number of slots to allocate across the vm_types under consideration
    '''
    num_skus = len(vm_types)
    vm_dist = {sku: 0 for sku in vm_types.keys()}

    remaining = total_slot_count
    max_core_count = max(vm_types.values())
    weighted_increment_per_sku = [num_skus / (1 + idx) for idx in range(num_skus)]
    while remaining > 0:
        for idx, p in enumerate(vm_types.items()):
            sku, symphony_slot_weight = p
            unrounded_increment = min(remaining, max_core_count * weighted_increment_per_sku[idx])
            increment = round_down_to_nearest_multiple(unrounded_increment, symphony_slot_weight)
            # Allow 1 instance for the last pass through the list
            if increment == 0 and remaining <= symphony_slot_weight:
                increment += symphony_slot_weight
            remaining -= int(increment)
            vm_dist[sku] += int(increment)
            if remaining <= 0:
                break

    logging.info("New (decay) VM SKU distribution targets: %s", vm_dist)
    return vm_dist