1

运行和使用云分析器

这是如何应用循环调度的代码

public class RoundRobinVmLoadBalancer extends VmLoadBalancer 

{

    private Map<Integer, VirtualMachineState> vmStatesList;

    private int currVm = -1;

    public RoundRobinVmLoadBalancer(Map<Integer, VirtualMachineState> vmStatesList)

    {

        super();
        this.vmStatesList = vmStatesList;
    }

    /* (non-Javadoc)
     * @see cloudsim.ext.VMLoadBalancer#getVM()
     */
    public int getNextAvailableVm(){
        currVm++;

        if (currVm >= vmStatesList.size()){
            currVm = 0;
        }

        allocatedVm(currVm);

        return currVm;

    }
}

虚拟负载均衡器

import java.util.Map;

import java.util.HashMap;

/**
 * This is the base class defining the behaviour of a Virtual Machine load 

balancer

 * used by a {@link DatacenterController}. The main method all load balancers 

should implement


 * is <c
ode>public int getNextAvailableVm()</code>.
 * 
 * This class provides a basic load balancing statistic collection that can be used by 
 * implementing classes. The implementing classes should call the  <code>void allocatedVM(int currVm)</code>
 *  method to use the statisitics collection feature.
 * 
 */
abstract public class VmLoadBalancer 
{

/** Holds the count of allocations for each VM */

protected Map<Integer, Integer> vmAllocationCounts;

    /** No args contructor */

    public VmLoadBalancer(){

    vmAllocationCounts = new HashMap<Integer, Integer>();

    }

    /**
     * The main contract of {@link VmLoadBalancer}. All load balancers should implement
     * this method according to their specific load balancing policy.
     * 
     * @return id of the next available Virtual Machine to which the next task should be
     *          allocated 
     */

    abstract public int getNextAvailableVm();

    /**
     * Used internally to update VM allocation statistics. Should be called by all impelementing
     * classes to notify when a new VM is allocated.
     * 
     * @param currVm
     */

    protected void allocatedVm(int currVm){


    Integer currCount = vmAllocationCounts.get(currVm);

    if (currCount == null){

        currCount = 0;

    }

        vmAllocationCounts.put(currVm, currCount + 1);      

}

    /**
     * Returns a {@link Map} indexed by VM id and having the number of allocations for each VM.
     * @return
     */

public Map<Integer, Integer> getVmAllocationCounts()

{

    return vmAllocationCounts;

}

}

像 Round Robin 一样,我想将 Ant Colony 优化应用为负载平衡策略。但目前尚不清楚如何实施 Round Robin 在 cloud_analyst cloudsim 项目中没有看到 Round Robin 的代码,那么我该如何应用 ACO,请分享在 cloudsim 中应用的 ACO 代码片段

4

2 回答 2

1

以我在 CloudSim 的一点经验,我认为你应该尝试创建一个新的VmAllocationPolicy而不是VmLoadBalancer. 因此,如果您尝试使用 Ant Colony 优化,那么您的类应该看起来像这样。

public final class MyPolicyNew extends VmAllocationPolicy {

    private Map<String, Host> vmTable;//vm table
    private Map<String, Integer> usedPes;//used pes
    private List<Integer> freePes;//free pes

    public MyPolicyNew(List<? extends Host> list) {
        ....
    }

    @Override
    public boolean allocateHostForVm(Vm vm) {

        **Your code for ACO goes here**
        **You do all the processing here and at the end allocate the vm to a host**
        **using host.vmCreate(vm) which returns a boolean on success of allocation, which you return from the function**
    }

    ....

}

您必须尝试查看VmAllocationPolicy.javacloudsim 中包含的 Cloudsim 模拟类和示例,这将对您有所帮助。

PS我知道你问了一个多月,但以防万一它可以帮助你,我会很高兴!

于 2015-12-04T19:45:26.157 回答
0

如果您将 TimeShareScheduling 用于 Vm/Cloudlet,它的作用类似于循环算法。VM/cloudlet调度器的不同组合可以制定不同的调度策略。图 4可能对您有所帮助。

于 2017-02-07T11:58:26.340 回答