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

Office Address

Social List

How to Find Available Resources in Each Host?

How to Find Available Resources in Each Host

Rendition for Find Available Resources in Each Host

  • Description:
    In CloudSim, finding the available resources for each host involves checking the current usage of various resources such as CPU, RAM, bandwidth, and storage. CloudSim provides methods to retrieve the resources from each host, but you need to track the resource usage as well, because the available resources are the difference between total resources and the resources that are currently being utilized.
Sample Code
  • import org.cloudbus.cloudsim.*;
    import org.cloudbus.cloudsim.provisioners.*;
    import java.util.*;
    import org.cloudbus.cloudsim.core.CloudSim;
    public class MultipleHostsWithDifferentMips {
    public static void main(String[] args) {
    try {
    // Initialize CloudSim
    int numUsers = 1; // Number of cloud users
    Calendar calendar = Calendar.getInstance();
    boolean traceFlag = false; // trace events
    CloudSim.init(numUsers, calendar, traceFlag);
    // Create a list to hold all hosts
    List hostList = new ArrayList<>();
    // Define MIPS values for each host
    int[] mipsValues = {1000, 2000, 1500}; // Different MIPS values for each host
    // Create 3 hosts with different MIPS values
    for (int hostId = 0; hostId < 3; hostId++) {
    List peList = new ArrayList<>();
    // Create PEs with different MIPS values for each host
    PeProvisioner peProvisioner = new PeProvisionerSimple(mipsValues[hostId]);
    Pe pe = new Pe(0, peProvisioner); // Add a single PE for each host with corresponding
    MIPS value
    peList.add(pe);
    // Create a Host with the PE list and other resources
    Host host = new Host(
    hostId,
    new RamProvisionerSimple(8192), // 8 GB RAM
    new BwProvisionerSimple(10000), // 10 GB Bandwidth
    1000000, // 1 TB Storage
    peList, // List of PEs
    new VmSchedulerTimeShared(peList) // VM Scheduler
    );
    hostList.add(host);
    }
    // Create Datacenter with the list of hosts
    DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
    "x86", "Linux", "Xen", hostList, 10.0, 3.0, 0.05, 0.001, 0.0);
    Datacenter datacenter = new Datacenter("Datacenter_1", characteristics,
    new VmAllocationPolicySimple(hostList), new LinkedList<>(), 0);
    // Print out the details of each host
    for (Host host : hostList) {
    System.out.println("Host ID: " + host.getId());
    for (Pe pe : host.getPeList()) {
    System.out.println(" PE MIPS: " + pe.getMips());
    }
    System.out.println(" Total RAM: " + host.getRam());
    System.out.println(" Total Bandwidth: " + host.getBw());
    System.out.println(" Total Storage: " + host.getStorage());
    System.out.println("-------------------------------------------------");
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
ScreenShots
  • find-the-available-resources-in-each-host.png