Research breakthrough possible @S-Logix pro@slogix.in

Office Address

Social List

How it's Possible to Send Cloudlets in Specific Time?

How it's Possible to Send Cloudlets in Specific Time

Condition for Send Cloudlets in Specific Time

  • Description:
    To send cloudlets (tasks) at specific times in CloudSim, you'll have to manage their submission times and ensure they are dispatched to the corresponding virtual machine (VM) based on the desired time. The CloudSim framework does not natively support direct scheduling of cloudlets at specific times.
Sample Code
  • package javaexercise;
    import org.cloudbus.cloudsim.*;
    import org.cloudbus.cloudsim.core.CloudSim;
    import java.util.*;
    import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
    import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
    import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
    public class CloudletStartTimeExample {
    public static void main(String[] args) {
    try {
    int numUser = 1; // Number of cloud users
    Calendar calendar = Calendar.getInstance();
    boolean traceFlag = false;
    // Initialize the CloudSim library
    CloudSim.init(numUser, calendar, traceFlag);
    // Create Datacenter
    Datacenter datacenter = createDatacenter("Datacenter_1");
    // Create Broker
    DatacenterBroker broker = createBroker();
    int brokerId = broker.getId();
    // Create virtual machines
    List vmList = createVMs(brokerId, 3); // Create 3 VMs
    broker.submitVmList(vmList);
    // Create cloudlets with specific start times
    List cloudlets = new ArrayList<>();
    int numCloudlets = 5;
    for (int i = 0; i < numCloudlets; i++) {
    Cloudlet cloudlet = new Cloudlet(i, 40000, 1, 300, 300,
    new UtilizationModelFull(), new UtilizationModelFull(), new
    UtilizationModelFull());
    cloudlet.setUserId(brokerId);
    // Set the cloudlet's start time (staggered at specific times like 0, 1000, 2000 ms)
    cloudlet.setExecStartTime(i * 1000.0); // Start at times 0, 1000, 2000, etc.
    cloudlets.add(cloudlet);
    }
    broker.submitCloudletList(cloudlets);
    // Start the simulation
    double lastClock = CloudSim.startSimulation();
    CloudSim.stopSimulation();
    // Print results
    List newList = broker.getCloudletReceivedList();
    printCloudletList(newList);
    System.out.println("Simulation finished at time: " + lastClock);
    } catch (Exception e) {
    e.printStackTrace();
    System.out.println("An unexpected error occurred.");
    }
    }
    private static Datacenter createDatacenter(String name) {
    List hostList = new ArrayList<>();
    // Create a host with specific properties
    int hostId = 0;
    int ram = 2048; // Host memory (MB)
    long storage = 1000000; // Host storage (MB)
    int bw = 10000; // Host bandwidth (Mbps)
    List peList = new ArrayList<>();
    int mips = 1000; // Host's CPU power
    peList.add(new Pe(0, new PeProvisionerSimple(mips))); // Adding a CPU core
    hostList.add(new Host(
    hostId,
    new RamProvisionerSimple(ram),
    new BwProvisionerSimple(bw),
    storage,
    peList,
    new VmSchedulerTimeShared(peList)
    ));
    String arch = "x86"; // System architecture
    String os = "Linux"; // Operating system
    String vmm = "Xen"; // Virtual machine monitor
    double time_zone = 10.0; // Time zone
    double cost = 3.0; // Cost per second
    double costPerMem = 0.05; // Cost per MB
    double costPerStorage = 0.1; // Cost per MB
    double costPerBw = 0.1; // Cost per Mbps
    LinkedList storageList = new LinkedList<>(); // Storage list
    Datacenter datacenter = null;
    try {
    datacenter = new Datacenter(name, new DatacenterCharacteristics(
    arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw),
    new VmAllocationPolicySimple(hostList), storageList, 0);
    } catch (Exception ex) {
    ex.printStackTrace();
    }
    return datacenter;
    }
    private static DatacenterBroker createBroker() {
    DatacenterBroker broker = null;
    try {
    broker = new DatacenterBroker("Broker");
    } catch (Exception e) {
    e.printStackTrace();
    }
    return broker;
    }
    private static List createVMs(int brokerId, int numVMs) {
    List vmList = new ArrayList<>();
    for (int i = 0; i < numVMs; i++) {
    int vmId = i;
    int mips = 1000;
    long size = 10000; // Image size (MB)
    int ram = 512; // RAM (MB)
    long bw = 1000; // Bandwidth (Mbps)
    int pesNumber = 1; // Number of CPUs
    String vmm = "Xen"; // VMM name
    Vm vm = new Vm(vmId, brokerId, mips, pesNumber, ram, bw, size, vmm, new
    CloudletSchedulerTimeShared());
    vmList.add(vm);
    }
    return vmList;
    }
    private static void printCloudletList(List list) {
    String indent = " ";
    System.out.println("========== OUTPUT ==========");
    System.out.println("Cloudlet ID" + indent + "STATUS" + indent +
    "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent
    + "Finish Time");
    for (Cloudlet cloudlet : list) {
    if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
    System.out.println(cloudlet.getCloudletId() + indent + "SUCCESS" + indent +
    cloudlet.getResourceId() +
    indent + cloudlet.getVmId() + indent + cloudlet.getActualCPUTime() + indent +
    cloudlet.getExecStartTime() + indent + cloudlet.getFinishTime());
    }
    }
    }
    }
ScreenShots
  • CloudSim1