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云仿真的使用及论文阅读

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

qq_42856609的博客 5043

云平台仿真框架CloudSim

一、实验名称 云平台仿真框架CloudSim应用 二、云平台仿真框架CloudSim介绍 CloudSim是在离散事件模拟包SimJava上开发的函数库 1.功能及组件 CloudSim 独特功能有:一是提供虚拟化引擎,旨在数据中心节点上帮助建立和管理多重的、独立的、协同的的虚拟化服务;二是在对虚拟化服务分配处理核心时能够在时间共享和空间共享之间灵活切换。 CloudSim平台有助于加

catchingSun的专栏 4513

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的博客 222

UsageLog电脑使用记录软件

UsageLog电脑使用记录软件

最新推荐-2026年固态电池+锂电正极+硅基负极等关键技术实践PPT合集(55份).zip

2026年最新固态电池+锂电正极+硅基负极等关键技术实践PPT合集,共55份。供大家查阅。 一、固态电池 1.全固态电池用硅基负极材料研究进展 2.全固态电池硅基负极的开发思考 3.功能型固态电解质设计及界面调控 4.固态电池及关键材料研发与产业化进展 5.固态电池的产业化应用探索 6.固态锂电池开发现状及未来展望 7.固态锂离子电池正极结构设计与材料选择 8.固态锂金属电池设计与应用 9.硫化物全固态电池石墨和硅负极性能调控技术 10.硫化物固态电解质行业应用 11.聚合物基固态电解质与固态电池的关键技术 12.蜂鸟声共振技术-固态电池产业化的革命性创新 13.长安汽车固态电池应用探索 14.高安全性固态电池技术发展趋势 15.高性能硫化物全固态锂电池解决方案 16.高硅体系的膨胀解决方案 二、硅基负极 1.化学气相沉积碳包覆技术在硅基负极材料中的应用 2.新型粘结剂解决 硅基负极膨胀问题 3.氧化亚硅负极材料化学预锂化与界面设计 4.流化床法生产磷酸铁锂及硅负极材料研究 5.石墨烯包覆硅碳负极 6.硅基材料的发展现状及展望 7.硅基负极与固态电解质 8.硅基负极技术与进展 9.硅基负极材料体积膨胀解决策略 10.硅基负极材料及其结构设计 11.硅基负极材料的冶金法制备 12.硅基负极材料的发展与应用 13.硅基负极材料研究进展 14.硅基负极材料:从基础研究到产业应用 15.硅基负极析锂行为及调制研究 16.硅碳负极低成本制造技术报告 17.硅碳负极制备用多孔碳的开发 18.硅碳负极挑战和进展 19.硅碳负极新路线及关键材料制备 20.硅碳负极锂离子电池应力特性研究 21.锂电石墨负极材料工程化技术进步 22.锂离子电池负极材料 23.高容量石墨烯-硅基复合负极材料的研究进展 三、锂电正极 1.基于AI和图论结构化学的锂电池的材料基因探索 2.废旧磷酸铁锂电池梯次及再生利用进展 3.电动汽车大功率充电标准体系与检测认证实践 4.磷酸铁及磷酸铁锂异物防控管理 5.磷酸铁锂正极材料:液相法合成及产业化应用研究 6.磷酸锰铁锂正极材料的研究现状 7.车用动力电池安全标准化工作进展及未来展望 8.锂电层状氧化物正极材料的原子尺度失效机制 9.锂电正极材料工厂异物防控管理图册 10.锂离子电池高熵正极材料成分设计及储锂机制研究 11.高压实磷酸铁锂正极材料生产工艺配方.docx 12.高安全正极材料添加剂提升三元锂电安全性 13.高比能富锂锰基电池关键技术 14.高能量密度锂离子电池正极材料及应用研究 15.高镍单晶三元正极材料研究 16.三元高电压单晶正极材料

Zotero 是学术管理领域非常优秀的软件 它功能成熟、生态稳定,帮助许多科研人员建立了最初的文献归档体系

Zotero 是学术管理领域非常优秀的软件。它功能成熟、生态稳定,帮助许多科研人员建立了最初的文献归档体系。但在当下日常科研与深度使用各类 Agent 时,传统的文献工具链暴露出一些断点:上下文严重分散:论文存储在 Zotero,笔记记在 Obsidian,与模型的推导和分析留在各个网页对话框中。三者数据彼此隔离,当需要 Agent 结合某篇具体论文与历史笔记进行深入推导时,用户必须反复手动复制粘贴。文献格式对模型不友好:人类习惯阅读排版良好的 PDF 文件;但对于模型而言,直接解析双栏排版、跨页表格、复杂数学公式和交叉引用的成本极高,极易产生识别错误与幻觉。结构化 Markdown 与 LaTeX 才是模型容易准确理解的格式。维护成本较高:AI 伴读、全文翻译、笔记同步等高频需求,往往需要安装和调试多个社区插件,配置门槛高且在版本升级时容易出现兼容性问题。批量自动化能力有限:通过 Deep Research 或自动化检索工具发现的大量文献,目前仍需人工在浏览器中逐篇点击保存,难以顺畅衔接批量研究流。Agentero 并非旨在替代 Zotero,而是探索一种人与 Agent 协同处理科研上下文的新方式:人类负责:提出研究问题、进行学术价值判断、深度研读与核心结论推导;Agent 负责:批量检索筛选、元数据抓取、图表与公式提取、引用关系梳理及基础总结。

基于 .net 8、blazor 、furion 开发的后台管理系统,功能全(完善的用户权限管理、定时任务、附件管理、日志审计、物联网、企业门户等)、技术新

基于 .net 7开发的后台管理系统,系统前后台分离,api 是基于Furion 框架开发,前端是基于ant-design-blazor开发,系统使用技术或框架较新

材料科学基于电致塑性效应的多场耦合精密成形:难变形合金超薄带材低缺陷轧制工艺

内容概要:本文系统阐述了合金在电、热、力多场耦合作用下的电致塑性精密成形工艺(Electrically-Assisted Rolling, EAR),重点介绍其通过瞬时脉冲电流实现材料“成形时软、用时强”的核心技术原理。该工艺利用电子风力、焦耳热微区软化等非热与热效应协同作用,降低难变形合金的流动应力,提升单道次压下率(如SUS304由33.8%提升至41.5%),显著减少中间退火次数,实现数十微米级极薄带材的高效、低残余应力、高平整度轧制。文章详细分析了工艺参数(电流密度、频率、脉宽、温度窗口等)、装备配置(脉冲电源、绝缘辊系、在线检测)及失效模式控制,并强调需以“变形区有效电流密度”和“窄温区闭环控制”为核心进行工艺设计与优化。; 适合人群:从事金属材料加工、精密轧制、先进成形技术研发的科研人员与工程技术人员,具备材料科学与工程、机械制造或相关领域背景的研发工程师及研究生。; 使用场景及目标:①开发高强钛合金、不锈钢、特种合金等难变形金属的超薄精密箔材(如折叠屏基材、光刻机钢带);②优化现有冷轧工艺,降低能耗与退火次数,提升产品尺寸精度与表面质量;③研究电-热-力多场耦合成形机理,指导新型电辅助制造装备开发。; 阅读建议:本文兼具理论深度与工程实践指导意义,建议结合图表与实测数据理解多机制协同效应,重点关注电流回路设计、温度场闭环控制与参数标定方法,避免直接套用文献参数;在应用中应坚持“实验标定+仿真验证”原则,确保工艺安全性与可重复性。

电气工程基于电磁原理的继电器工作机理与应用:工业控制中强弱电隔离开关的设计选型及保护电路分析

内容概要:本文深入浅出地介绍了继电器的工作原理、核心结构、分类、常见应用场景及选型要点。继电器是一种利用小电流控制大电流的“自动开关”,通过线圈通电产生磁场,驱动衔铁吸合或释放,从而控制触点的通断。文章详细解析了其五大组成部分(线圈、铁芯、衔铁、弹簧、触点)和工作三步循环过程,强调了强弱电隔离的优势,并区分了常开、常闭和转换型触点的应用。同时,文章列举了继电器在工业控制、汽车电子、家用电器、新能源和电力系统中的典型应用,重点指出高压直流继电器在新能源汽车中的关键作用。针对选型,强调需根据负载类型(阻性、感性、容性)进行降额使用,并介绍续流二极管、RC吸收电路等保护措施以延长寿命。最后对比了电磁继电器与固态继电器的优缺点,帮助读者合理选择。; 适合人群:具备基础电工知识,从事电子、电气、自动化相关工作的技术人员或爱好者,以及工科类学生。; 使用场景及目标:①理解继电器在电路控制中的隔离与放大作用;②掌握继电器的选型方法与常见故障排查技巧;③应用于实际项目中如电机控制、电源管理、自动化系统设计等; 阅读建议:结合实物或电路图对照学习,重点关注触点保护与负载匹配部分,在实际应用中注意降额设计与环境因素影响。

智算中心AI大模型赋能智能体平台及AI场景应用规划方案(决策评审版).pptx

智算中心AI大模型赋能智能体平台及AI场景应用规划方案(决策评审版).pptx

Everything-v.1.4.1.1032 -X64-号称全世界查找文件最快的工具-便携版 .zip

Everything_v.1.4.1.1032 _X64_号称全世界查找文件最快的工具_便携版 .zip

STM32F103跑LVGL,用DMA加速刷屏,800*480大屏也能丝滑

本文详细介绍了如何在STM32F103芯片上通过DMA加速和内存优化,实现800*480大屏的LVGL流畅运行。通过FSMC+DMA硬件架构优化、双缓冲机制和LVGL参数调优,显著提升了界面刷新率和响应速度,适用于嵌入式GUI开发中的高性能需求场景。

weixin_30357231的博客 377

OpenCV实战:如何用Debevec算法搞定相机响应函数(附完整代码)

本文详细介绍了如何使用OpenCV实现Debevec算法计算相机响应函数(CRF),并应用于HDR图像合成。通过完整的代码示例和工程实践问题解决方案,帮助开发者掌握从原理到实现的关键步骤,提升高动态范围成像和计算机视觉任务的处理能力。

weixin_29061041的博客 232

【NCBI】SRA toolkit安装及使用-Windows&Linux版本

由于市面上的文章介绍SRA toolkit基本上都是基于Linux,而在windows下运行SRA toolkit基本上可以达到相同的效果且更为方便,故本文将分别阐明在Windows和Linux环境下SRA toolkit的安装及使用。

weixin_48076899的博客 2万+

SAP SD POD 配置与 VLPOD 操作:3步解决发货10件开票7件的业务场景

本文详细解析了SAP SD POD功能在解决发货与开票数量差异中的应用,通过3步配置法实现精准匹配。重点介绍了POD核心逻辑、关键配置步骤及VLPOD操作技巧,帮助企业高效处理易损品运输等复杂场景,提升供应链管理效率。

weixin_30613343的博客 396

概率论与数理统计基础概念与重要定义汇总

文章目录一、随机事件和概率1:互斥,对立,独立事件的定义和性质。2:概率,条件概率和五大概率公式3:古典型,几何型概率和伯努利试验 一、随机事件和概率 1:互斥,对立,独立事件的定义和性质。 互斥事件\color{red}\textbf{互斥事件}互斥事件 事件A和B的交集为空,A与B就是互斥事件,也叫互不相容事件。也可叙述为:不可能同时发生的事件。如A∩B为不可能事件(A∩B=Φ),那么称事件A与事件B互斥,其含义是:事件A与事件B在任何一次试验中不会同时发生。 则P(A+B)=P(A)+P(B)(这个公

csyifanZhang的博客 1万+

王者荣耀AI绝悟如何选英雄?

王者荣耀AI绝悟如何选英雄? 【抢射手?抢中单位?「绝悟」在打王者荣耀时是如何选英雄的?】 腾讯 AI Lab 开发的 AI 智能体「绝悟」已让王者峡谷不再只是人类召唤师的竞技场,而且这个 AI 战队在上月底进化成了「完全体」。在一局完整的比赛中,英雄选择阶段是至关重要的(比如五射手或五法师阵容会有官方劝退)。 近日,腾讯 AI Lab 和上海交通大学发布的一篇论文介绍了绝悟的英雄选择策略:Ju...

不断学习,不断进步,提高自己 1万+

【人工智能时代】-什么是MCP?本地如何开发MCP Server

MCP(Model Context Protocol)全称模型上下文协议,是由 Anthropic 推出的一种开放标准,旨在统一大型语言模型(LLM)与外部数据源和工具之间的通信协议。掌握更多的信息控制更多的工具在没有联网搜索之前,大模型的数据来源只有训练数据的时候以及推理我们告诉他的东西。所以后来的rag、知识库都是让AI掌握更多的信息,而MCP的出现是为了让大模型控制更多的工具,赋予更多能力。在本篇文章中,基于 Python 完成了一个简单的 MCP Server 的开发。

xiaoli8748的专栏 1994

【RT-DETR创新改进】改进前必看!对Ultralytics调参, 1:1还原RT-DETR官方版本实验参数,使用原汁原味的RT-DETR模型,才能高效跑实验、高效涨点、收割小论文、完成大论文!!!

本文针对Ultralytics训练RT-DETR精度不佳问题,提供参数配置优化方案。通过对比官方RT-DETR参数设置,详细指导如何修改Ultralytics版本的关键参数,包括优化器、学习率、权重衰减等6处配置调整。操作步骤涵盖default.yaml文件修改和trainer.py代码调整,确保模型收敛性能达到官方水平,帮助研究者快速提升实验效果。文末附官方源码链接和具体参数配置网址供参考。

Ai缝合怪、助力小伙伴高效发论文 1781

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

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

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值