我正在尝试使用CLOUDSIM在单个VM上运行500个Cloudlets,但是在每种情况下,每个Cloudlets的开始时间都相同。因此,我认为当一个作业正在执行时,另一个作业将等待,但是这里每个小云都一起开始。我不明白。请帮助我理解。我的角色不在,因此无法显示全部500个cloudlets,但这是示例。

package org.cloudbus.cloudsim.examples;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;

import sun.font.CreatedFontTracker;
    /** Here Cloudlet number = 2 & VM Number = 1 **/

public class MyExample2 {

    private static List<Cloudlet> cloudletList;
    private static List<Vm> vmlist;

    public static void main(String args[]) {

        Log.printLine("Starting MyExample2");
        try {

            int user_no = 1; // here we have 2 user so we will use 2 cloudlets
            Calendar cal = Calendar.getInstance();
            boolean traceFlag = false;

            //Initialize cloudsim library
            CloudSim.init(user_no, cal, traceFlag);

            //datacenter creation
            Datacenter center_0 = create_Datacenter("center_0");//creat_Datacenter("") is user defined method

            //creat broker
            DatacenterBroker broker = create_Broker();//creat_Broker() is user defined
            int brokerid = broker.getId();

            //creation of VM
            vmlist = new ArrayList<Vm>();

            // VM description
                        int vmid = 0;
                        int mips = 1000;
                        long size = 10000; // image size (MB)
                        int ram = 512; // vm memory (MB)
                        long bw = 1000;
                        int pesNumber = 1; // number of cpus
                        String vmm = "Xen"; // VMM name

                        /*int vmid2 = 1;
                        int mips2 = 1000;
                        long size2 = 10000; // image size (MB)
                        int ram2 = 512; // vm memory (MB)
                        long bw2 = 1000;
                        int pesNumber2 = 1; // number of cpus
                        String vmm2 = "Xen"; // VMM name*/

                        // create VM
                        Vm vm = new Vm(vmid, brokerid, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
                        //Vm vm2 = new Vm(vmid2, brokerid, mips2, pesNumber2, ram2, bw2, size2, vmm2, new CloudletSchedulerTimeShared());

            //add the VM in VM list
            vmlist.add(vm);
            //vmlist.add(vm2);

            //submit the VM list to the broker
            broker.submitVmList(vmlist);//<-----------WHY WE DOING THIS-------------<<<<<


            //description of 2 cloudlets

            //creation of CloudLet1
            int id1 = 0;
            long length1 = 40000;//Time varies with cloudlet length
            long filesize1 = 300;
            long outputsize1 = 300;
            UtilizationModel UM1 = new UtilizationModelFull();//

            //creation of CloudLet2
            int id2 = 1;
            long length2 = 1500;
            long filesize2 = 100;
            long outputsize2 = 300;
            UtilizationModel UM2 = new UtilizationModelFull();//

            //finalizing above to cloudlets
            Cloudlet cloudlet1 = new Cloudlet(id1, length1, pesNumber, filesize1, outputsize1, UM1, UM1, UM1);
            cloudlet1.setUserId(brokerid);

            Cloudlet cloudlet2 = new Cloudlet(id2, length2, pesNumber, filesize2, outputsize2, UM2, UM2, UM2);
            cloudlet2.setUserId(brokerid);

            ArrayList<Cloudlet> clet = new ArrayList<Cloudlet>();//Listing the cloudlets in a List to creat more cloudlets
            id2++;
            for(int i=id2; i<=500; i++){

                Cloudlet cloudlet = new Cloudlet(i, length2, pesNumber, filesize2, outputsize2, UM2, UM2, UM2);
                cloudlet.setUserId(brokerid);
                clet.add(cloudlet);
            }

            cloudletList = new ArrayList<Cloudlet>();

            //adding cloudlets to cloudletlist
            cloudletList.add(cloudlet1);
            cloudletList.add(cloudlet2);

            Iterator<Cloudlet> ctr = clet.iterator();

            while(ctr.hasNext()) {

                cloudletList.add(ctr.next());
            }

            //submit cloudlet to broker
            broker.submitCloudletList(cloudletList);

            //bind the cloudlets to the vms. This way, the broker
            // will submit the bound cloudlets only to the specific VM

            broker.bindCloudletToVm(cloudlet1.getCloudletId(),vm.getId());


            //broker.bindCloudletToVm(cloudlet2.getCloudletId(),vm2.getId());


            Iterator<Cloudlet> itr = cloudletList.iterator();

            //getting file size
            while(itr.hasNext()){
                System.out.println("***************Size*************");
                System.out.println(itr.next().getCloudletFileSize());
                System.out.println("***************Size*************");
            }


            //start SIMULATION
            CloudSim.startSimulation();

            //Final step: Print results when simulation is over
            List<Cloudlet> newList = broker.getCloudletReceivedList();//check this method

            CloudSim.stopSimulation();


            printCloudletList(newList);



        }
        catch(Exception e) {
            e.printStackTrace();
            Log.printLine("Unwanted errors happen");
        }
    }

    /**
     * Creates the datacenter.
     *
     * @param name the name
     *
     * @return the datacenter
     */
    private static Datacenter create_Datacenter(String name) {

        // Here are the steps needed to create a PowerDatacenter:
        // 1. We need to create a list to store
        // our machine
        List<Host> hostList = new ArrayList<Host>();

        // 2. A Machine contains one or more PEs or CPUs/Cores.
        // In this example, it will have only one core.
        List<Pe> peList = new ArrayList<Pe>();

        int mips = 2000;

        // 3. Create PEs and add these into a list.
        peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating

        // 4. Create Host with its id and list of PEs and add them to the list
        // of machines
        int hostId = 0;
        int ram = 2048; // host memory (MB)
        long storage = 1000000; // host storage
        int bw = 10000;

        hostList.add(
            new Host(
                hostId,
                new RamProvisionerSimple(ram),
                new BwProvisionerSimple(bw),
                storage,
                peList,
                new VmSchedulerTimeShared(peList)
            )
        ); // This is our machine

        // 5. Create a DatacenterCharacteristics object that stores the
        // properties of a data center: architecture, OS, list of
        // Machines, allocation policy: time- or space-shared, time zone
        // and its price (G$/Pe time unit).
        String arch = "x86"; // system architecture
        String os = "Linux"; // operating system
        String vmm = "Xen";
        double time_zone = 10.0; // time zone this resource located
        double cost = 3.0; // the cost of using processing in this resource
        double costPerMem = 0.05; // the cost of using memory in this resource
        double costPerStorage = 0.001; // the cost of using storage in this
                                        // resource
        double costPerBw = 0.0; // the cost of using bw in this resource
        LinkedList<Storage> storageList = new LinkedList<Storage>(); // we are not adding SAN
                                                    // devices by now

        DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
                arch, os, vmm, hostList, time_zone, cost, costPerMem,
                costPerStorage, costPerBw);

        // 6. Finally, we need to create a PowerDatacenter object.
        Datacenter datacenter = null;
        try {
            datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return datacenter;
    }
    // We strongly encourage users to develop their own broker policies, to
        // submit vms and cloudlets according
        // to the specific rules of the simulated scenario
        /**
         * Creates the broker.
         *
         * @return the datacenter broker
         */
        private static DatacenterBroker create_Broker() {
            DatacenterBroker broker = null;
            try {
                broker = new DatacenterBroker("Broker");
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
            return broker;
        }
        /**
         * Prints the Cloudlet objects.
         *
         * @param list list of Cloudlets
         */
        private static void printCloudletList(List<Cloudlet> list) {
            int size = list.size();
            Cloudlet cloudlet;

            String indent = "    ";
            Log.printLine();
            Log.printLine("========== OUTPUT ==========");
            Log.printLine("Cloudlet ID" + indent + "STATUS" + indent
                    + "Data center ID" + indent + "VM ID" + indent + "Time" + indent
                    + "Start Time" + indent + "Finish Time");

            DecimalFormat dft = new DecimalFormat("###.##");
            for (int i = 0; i < size; i++) {
                cloudlet = list.get(i);
                Log.print(indent + cloudlet.getCloudletId() + indent + indent);

                if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
                    Log.print("SUCCESS");

                    Log.printLine(indent + indent + cloudlet.getResourceId()
                            + indent + indent + indent + cloudlet.getVmId()
                            + indent + indent
                            + dft.format(cloudlet.getActualCPUTime()) + indent
                            + indent + dft.format(cloudlet.getExecStartTime())
                            + indent + indent
                            + dft.format(cloudlet.getFinishTime()) + indent + indent + indent + cloudlet.getWaitingTime() + indent + indent + cloudlet.getSubmissionTime());
                }
            }
        }
}



========== OUTPUT ==========
Cloudlet ID    STATUS    Data center ID    VM ID    Time    Start Time    Finish Time
    1        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    2        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    3        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    4        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    5        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    6        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    7        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    8        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    9        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    10        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    11        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    12        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    13        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    14        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    15        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    16        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    17        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    18        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    19        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    20        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    21        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    22        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    23        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    24        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    25        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    26        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    27        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    28        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    29        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    30        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    31        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    32        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    33        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    34        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    35        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    36        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    37        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    38        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    39        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    40        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    41        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    42        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    43        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    44        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    45        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    46        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    47        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    48        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    49        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    50        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    51        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    52        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    53        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    54        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    55        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    56        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    57        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    58        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    59        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    60        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    61        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    62        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    63        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    64        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    65        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    66        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    67        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    68        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    69        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    70        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    71        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    72        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    73        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    74        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    75        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    76        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    77        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    78        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    79        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    80        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    81        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    82        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    83        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    84        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    85        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    86        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    87        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    88        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    89        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    90        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    91        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    92        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    93        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    94        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    95        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    96        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    97        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    98        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    99        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    100        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    101        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    102        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    103        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    104        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    105        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    106        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    107        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    108        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    109        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    110        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    111        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    112        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    113        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    114        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    115        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    116        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    117        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    118        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    119        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    120        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    121        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    122        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    123        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    124        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    125        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    126        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    127        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    128        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    129        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    130        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    131        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    132        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    133        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    134        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    135        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    136        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    137        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    138        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    139        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    140        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    141        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    142        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    143        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    144        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    145        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    146        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    147        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    148        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    149        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    150        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    151        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    152        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    153        SUCCESS        2            0        751        0.1        751.1            0.0        0.1
    154        SUCCESS        2            0        751        0.1        751.1            0.0        0.1

最佳答案

创建CloudletSchedulerSpaceShared()时使用CloudletSchedulerTimeShared()代替VMs

07-26 06:32