How to make changes in Scheduling algorithm and Resource allocation algorithm

Make changes in Scheduling algorithm and Resource allocation algorithm

Go to “cloudsim-2.1.1\sources\org\cloudbus\cloudsim\” this is the java program where the scheduling is been performed . here 3 functions are executed for each request /cludlet in sequence
Here the request is taken and is been given to a datacenter to check whether it can be fulfilled or not and “createVmsInDatacenter()” function is called .

protected void processResourceCharacteristics(SimEvent ev) { DatacenterCharacteristics characteristics = (DatacenterCharacteristics) ev.getData(); getDatacenterCharacteristicsList().put(characteristics.getId(), characteristics);

if (getDatacenterCharacteristicsList().size() == getDatacenterIdsList().size()) { setDatacenterRequestedIdsList(new ArrayList<Integer>()); createVmsInDatacenter(getDatacenterIdsList().get(0)); } } }


Here the dataceneter check whether request can be fulfilled or not . and if can be fulfilled “CloudSimTags” is set to true which says that request is fulfilled.

protected void createVmsInDatacenter(int datacenterId) {

/* send as much vms as possible for this datacenter before trying the next one*/

int requestedVms = 0;

String datacenterName = CloudSim.getEntityName(datacenterId);

for (Vm vm : getVmList()) {

if (!getVmsToDatacentersMap().containsKey(vm.getId()))

Log.printLine(CloudSim.clock() + “: ” + getName() + “: Trying to Create VM #” + vm.getId() + ” in ” + datacenterName); sendNow(datacenterId, CloudSimTags.VM_CREATE_ACK, vm);

requestedVms++; } }

getDatacenterRequestedIdsList().add(datacenterId); setVmsRequested(requestedVms); setVmsAcks(0);


In this class if the tag is true it is set to be fulfilled else it is been tried to be allocated to different datacenter.

protected void processVmCreate(SimEvent ev) {

int[] data = (int[]) ev.getData();

int datacenterId = data[0];

int vmId = data[1];

int result = data[2];

if (result == CloudSimTags.TRUE) {

getVmsToDatacentersMap().put(vmId, datacenterId); getVmsCreatedList().add(VmList.getById(getVmList(), vmId)); Log.printLine(CloudSim.clock()+”: “+getName()+ “: VM #”+vmId+” has been created in Datacenter #” + datacenterId + “, Host #” + VmList.getById(getVmsCreatedList(), vmId).getHost().getId()); } else { Log.printLine(CloudSim.clock()+”: “+getName()+ “: Creation of VM #”+vmId+” failed in Datacenter #” + datacenterId); } incrementVmsAcks();

//if not fulfilled then it is given for check to other datacenter.

if (getVmsCreatedList().size() == getVmList().size() – getVmsDestroyed()) { // all the requested VMs have been created

submitCloudlets(); }

else {

if (getVmsRequested() == getVmsAcks()) {

// all the acks received, but some VMs were not created

// find id of the next datacenter that has not been tried for (int nextDatacenterId : getDatacenterIdsList()) {

if (!getDatacenterRequestedIdsList().contains(nextDatacenterId)) { createVmsInDatacenter(nextDatacenterId); return; } }

//all datacenters already queried if (getVmsCreatedList().size() > 0) { //if some vm were created
submitCloudlets(); }

else {

//no vms created.

abort Log.printLine(CloudSim.clock() + “: ” + getName() + “: none of the required VMs could be created. Aborting”); finishExecution(); } } } }


finaly the request is been submitted with the datacenter id to which it has been allocated .

protected void processCloudletReturn(SimEvent ev) {

Cloudlet cloudlet = (Cloudlet) ev.getData(); getCloudletReceivedList().add(cloudlet); Log.printLine(CloudSim.clock()+”: “+getName()+ “: Cloudlet “+cloudlet.getCloudletId()+” received”);


if (getCloudletList().size()==0&&cloudletsSubmitted==0) {

//all cloudlets executed Log.printLine(CloudSim.clock()+”: “+getName()+ “: All Cloudlets executed. Finishing…”);

clearDatacenters(); finishExecution();

} else {

//some cloudlets haven’t finished yet

if (getCloudletList().size()>0 && cloudletsSubmitted==0) {

//all the cloudlets sent finished. It means that some bount

//cloudlet is waiting its VM be created clearDatacenters(); createVmsInDatacenter(0); }



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s