List of Topics:
Research Breakthrough Possible @S-Logix pro@slogix.in

Office Address

Social List

How to Get the Remaining Length of the Cloudlet to be Executed in VM?

Get the Remaining Length of the Cloudlet to be Executed in VM

Condition for Get the Remaining Length of the Cloudlet to be Executed in VM

  • Description:
    To get the remaining length of a cloudlet in a Virtual Machine (VM) in CloudSim, use the getRemainingCloudletLength() method from the Cloudlet class. This method returns the number of instructions or processing time still required for the cloudlet to finish. As the VM executes the cloudlet, the remaining length decreases based on available resources like CPU and memory. Periodic calls to this method allow monitoring of cloudlet progress and determination of remaining work, which helps in dynamic resource allocation, load balancing, or performance monitoring within cloud simulations.
Sample Code
  • import org.cloudbus.cloudsim.*;
    import org.cloudbus.cloudsim.core.CloudSim;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Calendar;
    import org.cloudbus.cloudsim.provisioners.*;
    public class CloudletRemainingLengthExample {
    public static void main(String[] args) {
    try {
    // Step 1: Initialize CloudSim
    int numUsers = 1; // Number of cloud users
    Calendar calendar = Calendar.getInstance();
    boolean traceFlag = false; // No event tracing
    CloudSim.init(numUsers, calendar, traceFlag);
    // Step 2: Create a Datacenter and a Broker
    Datacenter datacenter = createDatacenter("Datacenter_0");
    DatacenterBroker broker = new DatacenterBroker("Broker_0");
    // Step 3: Create and submit VMs and Cloudlets
    List vmList = createVM(broker.getId(), 1);
    broker.submitVmList(vmList);
    List cloudletList = createCloudlet(broker.getId(), 1);
    broker.submitCloudletList(cloudletList);
    // Step 4: Start the simulation
    CloudSim.startSimulation();
    // Step 5: Stop the simulation after the simulation time ends
    CloudSim.stopSimulation();
    // After simulation, print remaining length for each cloudlet
    for (Cloudlet cloudlet : cloudletList) {
    System.out.println("Remaining length of Cloudlet " + cloudlet.getCloudletId() + ": " +
    cloudlet.getCloudletLength());
    }
    System.out.println("Simulation Finished");
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    // Method to create a Datacenter with specified resources
    private static Datacenter createDatacenter(String name) throws Exception {
    List hostList = new ArrayList<>();
    // Host configuration
    int hostId = 0;
    int ram = 20480; // 20 GB RAM
    long storage = 1000000; // 1 TB Storage
    int bw = 10000; // 10 GB Bandwidth
    int cores = 4; // Number of cores
    int mips = 10000; // MIPS
    List peList = new ArrayList<>();
    for (int i = 0; i < cores; i++) {
    peList.add(new Pe(i, new PeProvisionerSimple(mips))); // Create processing elements
    }
    hostList.add(new Host(
    hostId,
    new RamProvisionerSimple(ram),
    new BwProvisionerSimple(bw),
    storage,
    peList,
    new VmSchedulerTimeShared(peList)
    ));
    String arch = "x86";
    String os = "Linux";
    String vmm = "Xen";
    DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
    arch, os, vmm, hostList, 10.0, 3.0, 0.05, 0.001, 0.0
    );
    return new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), new
    ArrayList<>(), 0);
    }
    // Method to create a list of VMs
    private static List createVM(int brokerId, int vmCount) {
    List vmList = new ArrayList<>();
    int mips = 1000;
    int size = 10000; // 10 GB Storage
    int ram = 2048; // 2 GB RAM
    long bw = 1000; // 1 GB Bandwidth
    int pesNumber = 1; // Number of cores
    String vmm = "Xen";
    for (int i = 0; i < vmCount; i++) {
    Vm vm = new Vm(i, brokerId, mips, pesNumber, ram, bw, size, vmm, new
    CloudletSchedulerTimeShared());
    vmList.add(vm);
    }
    return vmList;
    }
    // Method to create a list of Cloudlets
    private static List createCloudlet(int brokerId, int cloudletCount) {
    List cloudletList = new ArrayList<>();
    long length = 40000; // Cloudlet length (number of instructions)
    long fileSize = 300; // File size
    long outputSize = 300; // Output size
    int pesNumber = 1; // Number of cores
    UtilizationModel utilizationModel = new UtilizationModelFull();
    for (int i = 0; i < cloudletCount; i++) {
    Cloudlet cloudlet = new Cloudlet(i, length, pesNumber, fileSize, outputSize,
    utilizationModel, utilizationModel, utilizationModel);
    cloudlet.setUserId(brokerId);
    cloudletList.add(cloudlet);
    }
    return cloudletList;
    }
    }
ScreenShots
  • Get the Remaining Length of the Cloudlet