What are the VM allocation policies

  • To change the default allocation policy, have to extend the VmAllocationPolicySimple class and have to implement our own idea to allocate the VMs on each Host.
  • While creating the Datacenter use our extended Allocation class.Let “NewAllocationPolicy” be the extended VmAllocationPolicysimple class.Now ,

    NewAllocationPolicy vmAllocationPolicy = new NewAllocationPolicy();

    Datacenter dc = new Datacenter (String name, DatacenterCharacteristics characteristics, vmAllocationPolicy(hostList), List<Storage> storageList, double schedulingInterval)

  • In VmAllocationPolicySimple class, a method “allocateHostForVm(Vm vm)” is used for allocating the Host for each VM. To change the default allocation policy one has to extend the VmAllocationPolicySimple class and have to implement the idea of VM allocation on Host in the “allocateHostForVm(Vm vm)” method.
    Example.: Vm is allocated to the host which has low average CPU utilization.
  • public boolean allocateHostForVm(Vm vm) {
    try{
    boolean result=false;
    getHostList();
    int size                          = getHostList().size();
    double[] avgCPU           = new double[size];
    double[] avgBandwidth = new double[size];
    double[] avgStorage      = new double[size];
    for(int i=0; i<size;i++){
    host = getHostList().get(j); // get each Host from the list
    int hid=host.getId();
    double availmip=host.getAvailableMips(); //retrieves the available Cpu capacity
    avgCPU[i] = ((mips-availmip)/mips) * 100
    }
    double minCPU=min(avgCPU[]); // apply any operation to find the minimum cpu value.
    Host hs= the host which has low avgUtilized CPU value;
    ……
    result = hs.vmCreate(vm); //the low cpu utilized Host "hs" is allocated to vm
    if (result) { // if vm were succesfully created in the host
    getVmTable().put(vm.getUid(), p);
    getUsedPes().put(vm.getUid(), requiredPes);
    getFreePes().set(idx, getFreePes().get(idx) – requiredPes);
    result = true;
    break;
    } else {
    freePesTmp.set(idx, Integer.MIN_VALUE);
    }
    }
    Catch(Exception e){
    }
    return result;
    }