在调用CloudSim.startSimulation()之后,我们如何在cloudsim中动态创建VM和Cloudlets?

时间:2018-09-11 12:25:05

标签: cloud cloudsim

在调用CloudSim.startSimulation()之后,如何在cloudsim中动态创建VM和Cloudlets? 我正在尝试在模拟过程中动态地将vms和cloudlet添加到现有的代理中。 我尝试过:

CloudSim.startSimulation();
vm_list = create_vm(brokerId, 1, 6); //creating 1 vms,ID=6  
cloudlet_list = create_cloudlet(brokerId, 1, 6); // creating 1 cloudlet,CloudletId=6

broker.submitVmList(vm_list);
broker.submitCloudletList(cloudlet_list);

但是此代码无法正常工作,CloudSim并未考虑cloudlets。有人可以提出某种方法让我在模拟开始后添加虚拟机并动态调度cloudlets吗?

1 个答案:

答案 0 :(得分:0)

在CloudSim中,启动模拟后,您无法创建新对象,而无需添加新线程,暂停模拟然后添加所需的对象。

CloudSim Plus中,您可以通过2种不同的方式轻松地做到这一点。

1)您可以定义提交Cloudlet或VM的延迟时间:

broker.submitCloudletList(cloudletList, delay);
broker.submitVmList(vmList, delay);

2)您可以使用某些CloudSim Plus事件侦听器(例如跟踪模拟时钟何时更改的事件侦听器),然后将新的Cloudlet或VM提交给现有的代理。为此,您首先需要将以下方法添加到模拟类中:

/**
 * Event listener which is called every time the simulation clock advances.
 * @param info information about the event happened.
*/
private void clockTickListener(final EventInfo info) {
    //at the desired time, submit new cloudlets
    if(info.getTime() == 10) {
        //@todo create your new cloudlets here 
        //submits another list of new created Cloudlets
        broker.submitCloudletList(newCloudletList, delay);
    }
}

并在simulation.addOnClockTickListener(this::clockTickListener)之前致电simulation.start()

有一组完整的示例here

如果答案有帮助,请在http://github.com/manoelcampos/cloudsim-plus上投票并给CloudSim Plus加星号

相关问题