23、CloudSim 示例:模拟云环境的实践探索

CloudSim 示例:模拟云环境的实践探索

1. CloudSim Example 3 概述

CloudSim Example 3 是一个基础的云模拟示例,展示了云环境中数据中心、代理、虚拟机和云任务的基本交互流程。

以下是该示例的主要执行步骤:
1. 初始化 :启动 CloudSim 版本 3.0,数据中心和代理开始启动。
2. 资源分配 :代理接收云资源列表,尝试在数据中心创建虚拟机。
3. 云任务调度 :虚拟机创建成功后,代理将云任务发送到相应的虚拟机执行。
4. 任务完成 :云任务执行完成后,代理销毁虚拟机并关闭。
5. 模拟结束 :所有事件处理完毕,数据中心和代理关闭,模拟完成。

以下是该示例的输出日志:

Output: CloudSimExample 3
Starting CloudSimExample3...
Initialising...
Starting CloudSim version 3.0
Datacenter 0 is starting...
Broker is starting...
Entities started.
0.0: Broker: Cloud Resource List received with 1 resource(s)
0.0: Broker: Trying to Create VM #0 in Datacenter 0
0.0: Broker: Trying to Create VM #1 in Datacenter 0
0.1: Broker: VM #0 has been created in Datacenter #2, Host #0
0.1: Broker: VM #1 has been created in Datacenter #2, Host #1
0.1: Broker: Sending Cloudlet 0 to VM #0
0.1: Broker: Sending Cloudlet 1 to VM #1
80.1: Broker: Cloudlet 1 received
160.1: Broker: Cloudlet 0 received
160.1: Broker: All Cloudlets executed. Finishing...
160.1: Broker: Destroying VM #0
160.1: Broker: Destroying VM #1
Broker is shutting down...
Simulation: No more future events
CloudInformationService: Notify all CloudSim entities for shutting down.
Datacenter 0 is shutting down...
Broker is shutting down...
Simulation completed.

该示例的执行结果可以用表格展示:
| Cloudlet ID | STATUS | Data Center ID | VM ID | Time | Start Time | Finish Time |
| — | — | — | — | — | — | — |
| 1 | SUCCESS | 2 | 1 | 80 | 0.1 | 80.1 |
| 0 | SUCCESS | 2 | 0 | 160 | 0.1 | 160.1 |

2. CloudSim Example 4:创建双数据中心并运行云任务

CloudSim Example 4 展示了如何创建两个数据中心,每个数据中心包含一个主机,并在这些主机上运行两个云任务。

以下是创建两个数据中心并运行两个云任务的算法步骤:
1. 初始化 CloudSim 包 :在创建任何实体之前调用。
2. 创建数据中心 :创建两个数据中心。
3. 创建代理 :创建一个代理来管理虚拟机和云任务。
4. 创建虚拟机 :创建两个虚拟机并添加到虚拟机列表。
5. 提交虚拟机列表 :将虚拟机列表提交给代理。
6. 创建云任务 :创建两个云任务并添加到云任务列表。
7. 提交云任务列表 :将云任务列表提交给代理。
8. 绑定云任务和虚拟机 :将云任务绑定到特定的虚拟机。
9. 启动模拟 :开始模拟云环境。
10. 输出结果 :模拟结束后打印结果。

以下是该示例的源代码:

public class CloudSimExample4 {
    /** The Cloudlet list. */
    private static List<Cloudlet> CloudletList;
    /** The vmlist. */
    private static List<Vm> vmlist;

    public static void main(String[] args) {
        Log.printLine("Starting CloudSimExample4...");
        try {
            // First step: Initialize the CloudSim package. It should be called
            // before creating any entities.
            int num_user = 1; // number of Cloud users
            Calendar calendar = Calendar.getInstance();
            boolean trace_flag = false; // mean trace events
            CloudSim.init(num_user, calendar, trace_flag);

            // Second step: Create Datacenters
            //Datacenters are the resource providers in CloudSim. We need at list one of
            //them to run a CloudSim simulation
            Datacenter datacenter0 = createDatacenter("Datacenter 0");
            Datacenter datacenter1 = createDatacenter("Datacenter 1");

            //Third step: Create Broker
            DatacenterBroker broker = createBroker();
            int brokerId = broker.getId();

            //Fourth step: Create one virtual machine
            vmlist = new ArrayList<Vm>();
            //VM description
            int vmid = 0;
            int mips = 250;
            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

            //create two VMs
            Vm vm1 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm,
                    new CloudletSchedulerTimeShared());
            vmid++;
            Vm vm2 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm,
                    new CloudletSchedulerTimeShared());

            //add the VMs to the vmList
            vmlist.add(vm1);
            vmlist.add(vm2);

            //submit vm list to the broker
            broker.submitVmList(vmlist);

            //Fifth step: Create two Cloudlets
            CloudletList = new ArrayList<Cloudlet>();

            //Cloudlet properties
            int id = 0;
            long length = 40000;
            long fileSize = 300;
            long outputSize = 300;
            UtilizationModel utilizationModel = new UtilizationModelFull();

            Cloudlet Cloudlet1 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel,
                    utilizationModel);
            Cloudlet1.setUserId(brokerId);
            id++;
            Cloudlet Cloudlet2 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel,
                    utilizationModel);
            Cloudlet2.setUserId(brokerId);

            //add the Cloudlets to the list
            CloudletList.add(Cloudlet1);
            CloudletList.add(Cloudlet2);

            //submit Cloudlet list to the 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(), vm1.getId());
            broker.bindCloudletToVm(Cloudlet2.getCloudletId(), vm2.getId());

            // Sixth step: Starts the simulation
            CloudSim.startSimulation();

            // Final step: Print results when simulation is over
            List<Cloudlet> newList = broker.getCloudletReceivedList();
            CloudSim.stopSimulation();
            printCloudletList(newList);

            Log.printLine("CloudSimExample4 finished!");
        } catch (Exception e) {
            e.printStackTrace();
            Log.printLine("The simulation has been terminated due to an unexpected error");
        }
    }

    private static Datacenter createDatacenter(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 = 1000;

        // 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;

        //in this example, the VMAllocatonPolicy in use is SpaceShared. It means
        //that only one VM
        //is allowed to run on each Pe. As each Host has only one Pe, only one VM
        //can run on each Host.
        hostList.add(
                new Host(
                        hostId,
                        new RamProvisionerSimple(ram),
                        new BwProvisionerSimple(bw),
                        storage,
                        peList,
                        new VmSchedulerSpaceShared(peList)
                )
        ); // This is our first 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;
    }

    private static DatacenterBroker createBroker() {
        DatacenterBroker broker = null;
        try {
            broker = new DatacenterBroker("Broker");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return broker;
    }

    /** Prints the Cloudlet objects */
    private static void printCloudletList(List<Cloudlet> list) {
        int size = list.size();
        Cloudlet Cloudlet;
        Log.printLine();
        Log.printLine("========== OUTPUT ==========");
        Log.printLine("Cloudlet ID" + "STATUS" + "Data center ID" + "VM ID"
                + "Time" + "Start Time" + "Finish Time");

        for (int i = 0; i < size; i++) {
            Cloudlet = list.get(i);
            Log.print(Cloudlet.getCloudletId());
            if (Cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
                Log.print("SUCCESS");
            }
            Log.printLine(Cloudlet.getResourceId() + Cloudlet.getVmId() + Cloudlet.getActualCPUTime() + Cloudlet.getExecStartTime() + Cloudlet.getFinishTime());
        }
    }
}

该示例的输出日志如下:

Output: CloudSim Example4
Starting CloudSimExample4...
Initialising...
Starting CloudSim version 3.0
Datacenter 0 is starting...
Datacenter 1 is starting...
Broker is starting...
Entities started.
0.0: Broker: Cloud Resource List received with 2 resource(s)
0.0: Broker: Trying to Create VM #0 in Datacenter 0
0.0: Broker: Trying to Create VM #1 in Datacenter 0
[VmScheduler.vmCreate] Allocation of VM #1 to Host #0 failed by MIPS
0.1: Broker: VM #0 has been created in Datacenter #2, Host #0
0.1: Broker: Creation of VM #1 failed in Datacenter #2
0.1: Broker: Trying to Create VM #1 in Datacenter 1
0.2: Broker: VM #1 has been created in Datacenter #3, Host #0
0.2: Broker: Sending Cloudlet 0 to VM #0
0.2: Broker: Sending Cloudlet 1 to VM #1
160.2: Broker: Cloudlet 0 received
160.2: Broker: Cloudlet 1 received
160.2: Broker: All Cloudlets executed. Finishing...
160.2: Broker: Destroying VM #0
160.2: Broker: Destroying VM #1
Broker is shutting down...
Simulation: No more future events
CloudInformationService: Notify all CloudSim entities for shutting down.
Datacenter 0 is shutting down...
Datacenter 1 is shutting down...
Broker is shutting down...
Simulation completed.

执行结果表格如下:
| Cloudlet ID | STATUS | Data Center ID | VM ID | Time | Start Time | Finish Time |
| — | — | — | — | — | — | — |
| 0 | SUCCESS | 2 | 0 | 160 | 0.2 | 160.2 |
| 1 | SUCCESS | 3 | 1 | 160 | 0.2 | 160.2 |

3. CloudSim Example 5:容器初始放置问题探索

CloudSim Example 5 主要探索了容器初始放置的问题,涉及虚拟机分配策略、容器选择策略等多个方面。

以下是该示例的主要步骤:
1. 获取工作负载路径 :获取 planet lab 工作负载的路径。
2. 创建输出文件夹 :创建用于存储日志的输出文件夹。
3. 定义策略 :定义虚拟机分配策略、容器选择策略、容器分配策略、主机选择策略和虚拟机选择策略。
4. 设置容器超订因子 :设置容器超订因子以实现资源超订。
5. 运行模拟 :重复运行模拟多次。

以下是该示例的源代码:

package org.cloudbus.cloudsim.examples.container;

public class ContainerInitialPlacementTest {
    public static void main(String[] args) throws IOException {
        /**
         * The experiments can be repeated for (repeat runtime +1) times.
         * Please set these values as the arguments of the main function or set them
         * bellow:
         */
        int runTime = Integer.parseInt(args[0]);
        int repeat = Integer.parseInt(args[1]);

        for (int i = runTime; i < repeat; ++i) {
            boolean enableOutput = true;
            boolean outputToFile = true;

            /**
             * Getting the path of the planet lab workload that is included in the cloudSim
             * Package
             */
            String inputFolder = ContainerOverbooking.class.getClassLoader().getResource("workload/planetlab").getPath();

            /**
             * The output folder for the logs. The log files would be located in this folder.
             */
            String outputFolder = " /Results";

            /**
             * The allocation policy for VMs.
             */
            String vmAllocationPolicy = "MSThreshold-Under 0.80 0.70";

            /**
             * The selection policy for containers where a container migration is triggered.
             */
            String containerSelectionPolicy = "MaxUsage";

            /**
             * The allocation policy used for allocating containers to VMs.
             */
            String containerAllocationPolicy = "MostFull";

            /**
             * The host selection policy determines which hosts should be selected as the
             * migration destination.
             */
            String hostSelectionPolicy = "FirstFit";

            /**
             * The VM Selection Policy is used for selecting VMs to migrate when a host
             * status is determined as
             * “Overloaded”
             */
            String vmSelectionPolicy = "VmMaxC";

            /**
             * The container overbooking factor is used for overbooking resources of the
             * VM. In this specific case
             * the overbooking is performed on CPU only.
             */
            int OverBookingFactor = 80;

            new RunnerInitiator(
                    enableOutput,
                    outputToFile,
                    inputFolder,
                    outputFolder,
                    vmAllocationPolicy,
                    containerAllocationPolicy,
                    vmSelectionPolicy,
                    containerSelectionPolicy,
                    hostSelectionPolicy,
                    OverBookingFactor, Integer.toString(i), outputFolder);
        }
    }
}

该示例的输出日志如下:

OUTPUT: CloudSim Example5
Starting CloudSimExample5...
Initialising...
Starting CloudSim version 3.0
Datacenter 0 is starting...
Datacenter 1 is starting...
Broker1 is starting...
Broker2 is starting...
Entities started.
0.0: Broker1: Cloud Resource List received with 2 resource(s)
0.0: Broker2: Cloud Resource List received with 2 resource(s)
0.0: Broker1: Trying to Create VM #0 in Datacenter 0
0.0: Broker2: Trying to Create VM #0 in Datacenter 0
[VmScheduler.vmCreate] Allocation of VM #0 to Host #0 failed by MIPS
0.1: Broker1: VM #0 has been created in Datacenter #2, Host #0
0.1: Broker1: Sending Cloudlet 0 to VM #0
0.1: Broker2: Creation of VM #0 failed in Datacenter #2
0.1: Broker2: Trying to Create VM #0 in Datacenter 1
0.2: Broker2: VM #0 has been created in Datacenter #3, Host #0
0.2: Broker2: Sending Cloudlet 0 to VM #0
160.1: Broker1: Cloudlet 0 received
160.1: Broker1: All Cloudlets executed. Finishing...
160.1: Broker1: Destroying VM #0
Broker1 is shutting down...
160.2: Broker2: Cloudlet 0 received
160.2: Broker2: All Cloudlets executed. Finishing...
160.2: Broker2: Destroying VM #0
Broker2 is shutting down...
Simulation: No more future events
CloudInformationService: Notify all CloudSim entities for shutting down.
Datacenter 0 is shutting down...
Datacenter 1 is shutting down...
Broker1 is shutting down...
Broker2 is shutting down...
Simulation completed.

执行结果表格如下:
| Cloudlet ID | STATUS | Data Center ID | VM ID | Time | Start Time | Finish Time |
| — | — | — | — | — | — | — |
| 0 | SUCCESS | 2 | 0 | 160 | 0.1 | 160.1 |
| 0 | SUCCESS | 3 | 0 | 160 | 0.2 | 160.2 |

通过以上三个示例,我们可以看到 CloudSim 在模拟云环境方面的强大功能。从简单的资源分配到复杂的容器放置问题,CloudSim 提供了丰富的工具和接口,帮助我们深入理解和研究云环境的运行机制。在后续的示例中,我们将继续探索如何创建可扩展的模拟以及更多高级功能。

4. CloudSim Example 6:创建可扩展的模拟

CloudSim Example 6 展示了如何创建可扩展的云模拟,该示例通过创建多个虚拟机和云任务,模拟大规模的云环境。

以下是创建可扩展模拟的算法步骤:
1. 创建虚拟机列表 :创建一个容器来存储虚拟机,并设置虚拟机的参数。
2. 创建云任务列表 :创建一个容器来存储云任务,并设置云任务的参数。
3. 初始化 CloudSim 包 :在创建任何实体之前调用,初始化 CloudSim 库。
4. 创建数据中心 :创建两个数据中心。
5. 创建代理 :创建一个代理来管理虚拟机和云任务。
6. 提交虚拟机和云任务列表 :将虚拟机和云任务列表提交给代理。
7. 启动模拟 :开始模拟云环境。
8. 输出结果 :模拟结束后打印结果。

以下是该示例的源代码:

public class CloudSimExample6 {
    /** The Cloudlet list. */
    private static List<Cloudlet> CloudletList;
    /** The vmlist. */
    private static List<Vm> vmlist;

    private static List<Vm> createVM(int userId, int vms) {
        //Creates a container to store VMs. This list is passed to the broker later
        LinkedList<Vm> list = new LinkedList<Vm>();
        //VM Parameters
        long size = 10000; //image size (MB)
        int ram = 512; //vm memory (MB)
        int mips = 1000;
        long bw = 1000;
        int pesNumber = 1; //number of cpus
        String vmm = "Xen"; //VMM name
        //create VMs
        Vm[] vm = new Vm[vms];
        for(int i = 0; i < vms; i++) {
            vm[i] = new Vm(i, userId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
            //for creating a VM with a space shared scheduling policy for Cloudlets:
            //vm[i] = Vm(i, userId, mips, pesNumber, ram, bw, size, priority, vmm, new CloudletSchedulerSpaceShared());
            list.add(vm[i]);
        }
        return list;
    }

    private static List<Cloudlet> createCloudlet(int userId, int Cloudlets) {
        // Creates a container to store Cloudlets
        LinkedList<Cloudlet> list = new LinkedList<Cloudlet>();
        //Cloudlet parameters
        long length = 1000;
        long fileSize = 300;
        long outputSize = 300;
        int pesNumber = 1;
        UtilizationModel utilizationModel = new UtilizationModelFull();

        Cloudlet[] Cloudlet = new Cloudlet[Cloudlets];
        for(int i = 0; i < Cloudlets; i++) {
            Cloudlet[i] = new Cloudlet(i, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel,
                    utilizationModel);
            // setting the owner of these Cloudlets
            Cloudlet[i].setUserId(userId);
            list.add(Cloudlet[i]);
        }
        return list;
    }

    /**
     * Creates main() to run this example
     */
    public static void main(String[] args) {
        Log.printLine("Starting CloudSimExample6...");
        try {
            // First step: Initialize the CloudSim package. It should be called
            // before creating any entities.
            int num_user = 1; // number of grid users
            Calendar calendar = Calendar.getInstance();
            boolean trace_flag = false; // mean trace events
            // Initialize the CloudSim library
            CloudSim.init(num_user, calendar, trace_flag);

            // Second step: Create Datacenters
            //Datacenters are the resource providers in CloudSim. We need at list one of
            //them to run a CloudSim simulation
            Datacenter datacenter0 = createDatacenter("Datacenter 0");
            Datacenter datacenter1 = createDatacenter("Datacenter 1");

            //Third step: Create Broker
            DatacenterBroker broker = createBroker();
            int brokerId = broker.getId();

            //Fourth step: Create VMs and Cloudlets and send them to broker
            vmlist = createVM(brokerId, 20); //creating 20 vms
            CloudletList = createCloudlet(brokerId, 40); // creating 40 Cloudlets
            broker.submitVmList(vmlist);
            broker.submitCloudletList(CloudletList);

            // Fifth step: Starts the simulation
            CloudSim.startSimulation();

            // Final step: Print results when simulation is over
            List<Cloudlet> newList = broker.getCloudletReceivedList();
            CloudSim.stopSimulation();
            printCloudletList(newList);

            Log.printLine("CloudSimExample6 finished!");
        } catch (Exception e) {
            e.printStackTrace();
            Log.printLine("The simulation has been terminated due to an unexpected error");
        }
    }

    private static Datacenter createDatacenter(String name) {
        // Here are the steps needed to create a PowerDatacenter:
        // 1. We need to create a list to store one or more
        // Machines
        List<Host> hostList = new ArrayList<Host>();

        // 2. A Machine contains one or more PEs or CPUs/Cores. Therefore, should
        // create a list to store these PEs before creating
        // a Machine.
        List<Pe> peList1 = new ArrayList<Pe>();
        int mips = 1000;

        // 3. Create PEs and add these into the list.
        //for a quad-core machine, a list of 4 PEs is required:
        peList1.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
        peList1.add(new Pe(1, new PeProvisionerSimple(mips)));
        peList1.add(new Pe(2, new PeProvisionerSimple(mips)));
        peList1.add(new Pe(3, new PeProvisionerSimple(mips)));

        //Another list, for a dual-core machine
        List<Pe> peList2 = new ArrayList<Pe>();
        peList2.add(new Pe(0, new PeProvisionerSimple(mips)));
        peList2.add(new Pe(1, new PeProvisionerSimple(mips)));

        //4. Create Hosts 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,
                        peList1,
                        new VmSchedulerTimeShared(peList1)
                )
        ); // This is our first machine
        hostId++;
        hostList.add(
                new Host(
                        hostId,
                        new RamProvisionerSimple(ram),
                        new BwProvisionerSimple(bw),
                        storage,
                        peList2,
                        new VmSchedulerTimeShared(peList2)
                )
        ); // Second 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.1; // the cost of using storage in this resource
        double costPerBw = 0.1; // 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;
    }

    private static DatacenterBroker createBroker() {
        DatacenterBroker broker = null;
        try {
            broker = new DatacenterBroker("Broker");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return broker;
    }

    /* Prints the Cloudlet objects */
    private static void printCloudletList(List<Cloudlet> list) {
        int size = list.size();
        Cloudlet Cloudlet;
        Log.printLine("========== OUTPUT ==========");
        Log.printLine("Cloudlet ID" + "STATUS" + "Data center ID" + "VM ID"
                + "Time" + "Start Time" + "Finish Time");
        for (int i = 0; i < size; i++) {
            Cloudlet = list.get(i);
            Log.print(Cloudlet.getCloudletId());
            if (Cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) {
                Log.print("SUCCESS");
            }
            Log.printLine(Cloudlet.getResourceId() + Cloudlet.getVmId() + (Cloudlet.getActualCPUTime() +
                    Cloudlet.getExecStartTime() + Cloudlet.getFinishTime()));
        }
    }
}

该示例的输出日志如下:

Output:CloudSim Example6 Starting CloudSimExample6...
Initialising...
Starting CloudSim version 3.0
Datacenter 0 is starting...
Datacenter 1 is starting...
Broker is starting...
Entities started.
0.0: Broker: Cloud Resource List received with 2 resource(s)
. . . 0.0: Broker: Trying to Create VM #3 in Datacenter 0
. . . . . . 0.0: Broker: Trying to Create VM #17 in Datacenter 0
0.0: Broker: Trying to Create VM #18 in Datacenter 0
0.0: Broker: Trying to Create VM #19 in Datacenter 0
[VmScheduler.vmCreate] Allocation of VM #6 to Host #0 failed by RAM
. . . . . . [VmScheduler.vmCreate] Allocation of VM #18 to Host #1 failed by MIPS
[VmScheduler.vmCreate] Allocation of VM #19 to Host #0 failed by RAM
[VmScheduler.vmCreate] Allocation of VM #19 to Host #1 failed by MIPS
0.1: Broker: VM #0 has been created in Datacenter #2, Host #0
. . . 0.1: Broker: VM #5 has been created in Datacenter #2, Host #1
0.1: Broker: Creation of VM #6 failed in Datacenter #2
. . . 0.1: Broker: Creation of VM #19 failed in Datacenter #2
. . . 0.1: Broker: Trying to Create VM #13 in Datacenter 1
0.1: Broker: Trying to Create VM #14 in Datacenter 1
–
–
–
[VmScheduler.vmCreate] Allocation of VM #12 to Host #0 failed by RAM
. . . . . .
Broker is shutting down...
Simulation: No more future events
CloudInformationService: Notify all CloudSim entities for shutting down.
Datacenter 0 is shutting down...
Datacenter 1 is shutting down...
Broker is shutting down...
Simulation completed.

该示例的执行流程可以用 mermaid 流程图表示:

graph TD;
    A[初始化 CloudSim] --> B[创建数据中心];
    B --> C[创建代理];
    C --> D[创建虚拟机列表];
    D --> E[创建云任务列表];
    E --> F[提交虚拟机和云任务列表给代理];
    F --> G[启动模拟];
    G --> H[输出结果];

总结

通过以上四个 CloudSim 示例,我们对云模拟有了更深入的了解。从基础的资源分配模拟到复杂的容器初始放置和可扩展模拟,CloudSim 提供了丰富的功能和接口,帮助我们模拟不同场景下的云环境。

在实际应用中,我们可以根据需求选择合适的示例进行参考,例如在研究云资源分配策略时,可以参考 CloudSim Example 3 和 4;在探索容器放置问题时,可以参考 CloudSim Example 5;在进行大规模云模拟时,可以参考 CloudSim Example 6。

同时,我们也可以根据这些示例的代码进行扩展和修改,以满足特定的研究需求。例如,可以调整虚拟机和云任务的参数,改变数据中心的配置,或者实现自定义的调度策略等。

希望这些示例能为大家在云模拟领域的研究和实践提供有价值的参考。

相关推荐

云平台仿真框架cloudsim介绍

http://1.johnhome.sinaapp.com/?p=257 幻灯片1 云计算仿真框架CloudSim介绍 jiangzw#ihep.ac.cn (以下为本人某次报告做的调研的PPT及其它一些实践记录,为保证清晰度,一些插入的图片较大,可在新标签页中打开) 本文基于 署名 3.0 中国大陆 许可协议发布,未经本人许可不得转载

John:网络安全_Qt技术_积累 9746

CloudSim云仿真的使用及论文阅读

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录前言一、maven 配置二、CloudSimExample1.CloudSimExample12.CloudSimExample4总结 前言 提示:这里可以添加本文要记录的大概内容: 例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。 提示:以下是本篇文章正文内容,下面案例可供参考 一、maven 配置 maven 本地仓库的配置 二、CloudSimEx.

qq_42856609的博客 5047

23、CloudSim 示例:模拟云环境的实用案例

本文详细介绍了使用 CloudSim 工具进行云环境模拟的多个实用案例。内容涵盖了 CloudSimExample 3 到 CloudSimExample 6 的具体实现,包括基础模拟、多数据中心模拟、容器初始放置以及可扩展性模拟。通过运行结果、算法步骤和源代码的展示,读者可以了解如何创建和管理数据中心、虚拟机、云任务,并学习如何处理资源分配和任务调度问题。此外,还总结了各个示例的特点和差异,并提供了实际应用中的注意事项,如资源分配策略、超订问题、可扩展性和错误处理等。这些内容为研究和实践中的云模拟实验提供

pear55的博客 85

23、基于遗传算法的云安全伪随机数生成

本文提出一种结合线性反馈移位寄存器(LFSR)和遗传算法(GA)的混合模型,用于云安全领域的高质量伪随机数生成。该模型通过LFSR生成初始序列,并利用GA的选择、交叉和两次变异操作扩展序列长度并增强随机性。实验结果显示,混合模型显著提升了序列周期(达LFSR的15倍),并通过卡方检验验证了其优良的均匀性。模型在CloudSim环境下可高效运行,适用于数据加密、随机访问控制等场景。文章还探讨了性能评估、并行优化策略及未来在量子计算挑战与AI融合中的发展趋势,为云安全提供了一种高可靠性的随机数生成方案。

pandas7gardener的博客 51

11、云计算负载均衡与DDoS攻击缓解策略解析

本文探讨了云计算环境下的任务调度启发式算法性能评估以及基于风险转移的DDoS攻击缓解框架。通过使用Cloudsim Plus模拟器,在线和批处理模式下的多种启发式算法被分析比较,MCT和KPB在在线模式下表现最佳,而MinMin在批处理模式中效果最优。同时,提出了一种利用雾节点和自治系统的DDoS攻击缓解方案,有效提升了云环境的安全性和可用性。未来的研究方向包括更多算法优化、统计分布建模及第三方协同机制设计,以进一步提升云计算的性能与安全性。

h6j7k8l9p0的博客 101

【信息科学与工程学】计算机科学与自动化—第十五篇 云计算 11 算法篇01

编号类型领域问题问题的数学分析(含几何学/拓扑学/代数学/数论/集合论/离散数学/概率论/统计学/其他)及数值分析及算法分析及参数列表及参数数值设计C/C++/rust/python代码软件(含编译器)及硬件资源需求(CPU/GPU/内存【NAND/DRAM/HBM/其他】/HBM、HDD、SSD、RAID卡、其他)关联知识1工作负载调度数据中心最小化总完成时间/成本。

weixin_49199313的博客 240

【电子电气架构】RCP框架下车载通信设计变革:寄存器级访问与动态拓扑下的通信架构重构

内容概要:本文深入探讨了在RCP(Register-based Communication Protocol)框架下整车通信设计所面临的变革与挑战。传统通信架构以“信号”为核心,依赖DBC或ARXML等通信数据库描述带有物理语义的信号,并据此生成代码、进行测试和系统集成。而RCP将通信对象从“信号”转变为“寄存器访问”,传输原始寄存器值,物理语义上移至ZCU应用层处理,导致通信数据库失去90%的内容,退化为硬件访问清单。这一转变引发四大结构性矛盾:信号消失导致功能可追溯链断裂;拓扑运行时发现与通信数据库静态生成之间的冲突;周期性通信设计失效,需重构请求调度机制;现有工具链(如DBC/ARXML)无法表达RCP语义,造成上下游工具全面断裂。文章进一步指出项目节奏受硬件冻结制约、通信架构师角色分化为“端点建模”与“数据调度”两大方向,并强调在新范式下对整车数据流的整体把控能力反而更加关键。; 适合人群:从事汽车电子、车载通信架构设计的工程师,尤其是工作3-5年以上的系统架构师、通信开发人员及技术管理者;也适用于关注SOA、区域控制器、中央计算单元(ZCU)演进路径的技术决策者。; 使用场景及目标:①理解RCP如何颠覆传统基于信号的通信设计范式;②掌握在RCP架构下重建数据可追溯性、设计请求调度策略、构建逻辑通道抽象的方法;③指导团队应对工具链断裂、角色分工调整与项目节奏变化等现实挑战;④为下一代电子电气架构中的通信体系设计提供前瞻性思考。; 阅读建议:此文档不仅讲解技术细节,更侧重于架构思维的转型,建议结合实际项目背景精读,重点关注“信号消失”“静态vs发现”“周期失效”“工具断裂”四条主线,并思考如何在组织层面重构流程与职责分工,以适应RCP带来的系统性变革。

YOLO26算法雨天城市道路车辆行人及交通设施目标检测+训练好的模型+998张数据集+pyqt可视化界面.zip

附训练好的 YOLO 权重与 PyQt 可视化检测界面,页面底部含可视化效果预览,毕设/课设开箱即用。 【数据集概况】 · 检测类别(中文):[卡车(0), 公交车(1), 小汽车(2), 行人(3), 交通灯(4), 交通标志(5)] · 总计:998 张 · 测试集:100 张 · 验证集:199 张 · 训练集:699 张 【训练曲线与评估图】 【模型训练配置】 参数 | 值 模型 | yolo26n 训练轮数 | 100 epochs 输入尺寸 | 640x640 批次大小 | 24 优化器 | auto 初始学习率 | 0.01 训练设备 【关键指标汇总】 训练了 100 个 epoch,最终轮指标: 指标 | 数值 mAP50 | **0.8669** mAP50-95 | 0.6242 Precision | 0.8223 Recall | 0.7889 train/box_loss | 1.0169 train/cls_loss | 0.5504 val/box_loss | 1.0274 val/cls_loss | 0.6034 【训练过程分析】 经过100个训练周期后,我们观察到了模型训练的详细过程。在训练的前50个周期里,loss的下降幅度非常显著,尤其是在前20个周期内,train/box_loss从1.3降到1.0,train/cls_loss从0.6降至0.5。这表明模型在训练初期快速地学习到目标的基本特征表示。从第20个周期开始,loss的下降趋势放缓,但整体依然保持下降趋势,说明模型在继续优化细节特征。到了训练第70个周期,train/box_loss和train/cls_loss分别为0.98和0.54,val/box_loss和val/cls_loss分别为1.02和... 使用场景:毕业设计、课程设计、深度学习入门、工业场景落地验证。

C++并发与内存池实战:线程安全队列+对象池+基准对照,可跑源码

面向C++并发与性能练习的离线资源包。用C++17实现线程安全多生产者多消费者队列、固定块内存池与对象池,并与new/delete做短基准对照;另附循环展开与可选向量化对比,无SIMD指令也能在普通x86上运行。含多线程正确性测试,可离线用g++编译。MIT。作者blog.csdn.net/mtl1994

绿色农业智慧监测系统设计方案.docx

绿色农业智慧监测系统设计方案.docx

跨国企业十五五全球供应链数据编织(Data Fabric)平台项目建设方案.docx

跨国企业十五五全球供应链数据编织(Data Fabric)平台项目建设方案.docx

大型银行十五五金融大模型风控系统与智能投顾平台项目建设方案.docx

大型银行十五五金融大模型风控系统与智能投顾平台项目建设方案.docx

同行技术转移机构在构建生态合作时,应该具备哪些核心资质才能被平台认可?.docx

科易网基于行业知识库+行业大数据+科技资源要素+AI模型,以AI,赋能技术转移、成果转化、技术经理人培训、知识产权管理、区域产业分析与布局、地方科技招商、创新创业大赛等场景,推出科技创新领域的AI工具、场景化服务和数智化解决方案,推动科技创新与产业创新智能化发展。

模糊PID、传统PID对比的水下航行器运动控制系统Simulink仿真【附说明文档+仿真模型】

模糊PID、传统PID对比的水下航行器运动控制系统Simulink仿真【附说明文档+仿真模型】内容概要:本文主要介绍了“模糊PID与传统PID对比的水下航行器运动控制系统Simulink仿真”资源包,重点在于通过Simulink搭建水下航行器的运动控制模型,比较模糊PID控制器与传统PID控制器在系统响应速度、稳定性和抗干扰能力等方面的性能差异。文中涵盖了控制系统的建模、控制器设计、仿真测试方案及结果分析,旨在为相关领域的研究人员和工程师提供一套完整的仿真解决方案和技术参考。同时,资源包还包括详细的说明文档和可运行的仿真模型,便于用户理解和复现。; 适合人群:具备自动控制、海洋工程或相关领域基础知识的研究生、科研人员及工程技术人员。; 使用场景及目标:①用于高校教学实验和课程设计,帮助学生掌握PID控制与模糊控制的基本原理及仿真方法;②为水下机器人、无人潜航器等复杂系统的控制器设计与优化提供技术参考和仿真验证手段;③支持科研人员开展先进控制算法的研究与对比分析。; 阅读建议:建议读者结合提供的Simulink模型与说明文档同步学习,重点关注控制器参数的整定方法和仿真结果的分析过程,有条件者可尝试修改模型参数或引入新的控制策略进行拓展研究。

SAP采购信息记录批量维护实战:用BAPI ME_INFORECORD_MAINTAIN搞定价格等级和条件记录

本文深入解析SAP标准BAPI ME_INFORECORD_MAINTAIN在采购信息记录批量维护中的应用,特别聚焦价格等级和条件记录的技术难点。通过实战案例和代码示例,帮助用户高效处理供应商-物料价格数据,提升供应链管理效率。

weixin_42522320的博客 416

桌面云架构讲解(VDI、IDV、VOI/TCI、RDS)

什么是云桌面桌面云是虚拟化技术成熟后发展起来的一种应用,桌面云通常也称为云桌面、VDI等桌面云中的云一般指的是企业的数据中心,通过在数据中心的服务器上安装若干个虚拟机,这个虚拟机就是桌面;但是终端无法直接连接到这个虚拟机(云桌面),因此就需要通过技术将就虚拟机变为桌面云发放出来;发放出来之后只需要瘦客户端(PC、手机、瘦客户机等)连接到数据中心的云桌面服务器平台,最终就可以连接到桌面来进行使用云桌面的优势终端与数据信息分离,数据在后台集中处理和存储 ,数据实现统一管理。

m0_49864110的博客 3万+

labview设置工业摄像头外部触发

使用labview对海康MV-CA013-GM相机设置外部触发。 一、硬件部分 1、硬件引脚定义 2、触发模式设置 相机的触发模式分为两种,一种是内触发模式、另外一种是外触发模式。 3、接线图 信号线的地要跟给信号的设备共地。信号线给高电平时触发拍照。 二、软件部分 1、创建vision acquisition 2、选择使用的摄像头。 3、选择模式。 4、在Acquisition Control中设置这些选项。 5、设置保存图片路径 设置保存路径和保存图片的格式。点击完成即可 参考:https:/

qq_43493715的博客 5670

Augustus手动安装教程

本文记载了如何结合conda手动安装Augustus

m0_65437087的博客 1260

Android一个APP里面最少有几个线程

Android应用启动时,默认会创建一个进程,该进程中最少包含负责处理用户交互、UI更新等核心操作,所有与界面相关的逻辑必须在此线程执行。若在此线程执行耗时操作(如网络请求),会导致界面卡顿甚至触发ANR(应用无响应)。当对象重写了finalize()方法时,该线程负责将这些对象放入队列并调用其finalize()方法,完成资源释放后再由GC回收。监控的执行效率。如果finalize()方法执行超时(默认10秒),此线程会触发虚拟机退出以防止应用长时间阻塞。

编程进化论 619

嵌入式开发之瑞芯微RK356x--基本环境搭建

嵌入式环境搭建

NexyHO的博客 619

【论文精读】《Towards Deep Learning Models Resistant to Adversarial Attacks》

本文探讨了深度学习模型在面对对抗性攻击时的脆弱性,并提出了一种基于鲁棒优化的方法来增强神经网络的对抗鲁棒性。通过鞍点优化框架,作者提供了对抗攻击和防御机制的统一视角,并在MNIST和CIFAR-10数据集上验证了其方法的有效性。对抗训练的核心思想是将对抗样本引入训练过程,使模型能够学习到对抗样本的特征,从而提升其鲁棒性。本文通过鞍点优化框架提出了一种基于鲁棒优化的对抗训练方法,显著提升了深度学习模型的对抗鲁棒性。本文为深度学习模型的对抗鲁棒性研究提供了新的理论和实证支持,同时为未来研究指明了方向。

nmdbbzcl的博客 613

ADB加密实例

主要介绍如何给adb命令增加加密访问

四儿家的小祖宗的博客 2914

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

上一篇: 3、Swift编程基础:简单值与类型入门
下一篇: 68、网络安全攻防:从策略到实战
java5
博客等级 码龄22年 85粉丝 2103原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值