1

How can we create VM and Cloudlets dynamically in cloudsim afterCloudSim.startSimulation() is being called? I am trying to add vms and cloudlets, to an already existing broker, dynamically as the simulation progresses. I tried this:

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);

But this code is not working, cloudlets are not taken into account by the CloudSim.Can anyone suggest some way that i would be able to add vms and schedule cloudlets dynamically after the simulation starts?

user007
  • 2,156
  • 2
  • 20
  • 35

1 Answers1

0

In CloudSim, after you start the simulation, you can't create new objects without requiring you to add a new thread, pause the simulation and then add the objects you want.

In CloudSim Plus you can do this easily in 2 different ways.

1) You can define a delay when submitting Cloudlets or VMs:

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

2) You can use some of the CloudSim Plus event listener (such as the one that tracks when the simulation clock changes) and then submit new Cloudlets or VMs to an already existing broker. For that, you first need to add the method below to your simulation class:

/**
 * 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);
    }
}

and call simulation.addOnClockTickListener(this::clockTickListener) before simulation.start().

There is a set of complete examples here.

halfer
  • 19,824
  • 17
  • 99
  • 186
Manoel Campos
  • 933
  • 9
  • 12