From aeba154d1aeea18948863deb7984f380f40d6202 Mon Sep 17 00:00:00 2001 From: Manoel Campos Date: Sat, 24 Oct 2026 21:31:07 -0300 Subject: [PATCH] Update to the CloudSim Plus single Processor API (cloudsimplus#595) - Hosts and VMs are created with a CoreCapacity instead of a List and (mips, pes) arguments. - A single immutable CoreCapacity is reused for all Hosts/VMs with the same capacity, documenting why that is safe. - getPesNumber()/getMips() on Hosts and VMs use the machine Processor. - Cloudlet.getPesNumber() is now getRequiredCores(). - PeVerticalScaling methods are now CpuVerticalScaling ones. - Rename *_PES constants to *_CORES. Co-Authored-By: Claude Opus 5.5 --- .../examples/network/NetworkExample1.java | 14 ++--- .../examples/network/NetworkExample2.java | 18 +++--- .../examples/network/NetworkExample3.java | 18 +++--- .../examples/network/NetworkExample4.java | 14 ++--- .../NetworkVmExampleAbstract.java | 39 +++++++------ .../NetworkVmsExampleBagOfTasksApp.java | 2 +- .../NetworkVmsExampleSimpleApp.java | 36 ++++++------ .../NetworkVmsExampleWorkflowApp.java | 2 +- .../examples/BasicFirstExample.java | 39 +++++++------ .../CloudletAndVmLifeTimeExample.java | 34 +++++++----- .../examples/CloudletCancellationExample.java | 35 +++++++----- .../examples/CloudletLifeTimeExample.java | 34 +++++++----- ...loudletsTableBuilderFormattingExample.java | 44 ++++++++------- .../examples/HostFaultInjectionExample1.java | 49 +++++++++-------- .../examples/LargeScaleExample.java | 37 ++++++++----- .../cloudsimplus/examples/LoggingExample.java | 34 ++++++------ .../examples/MinTimeBetweenEventsExample.java | 33 +++++++---- .../examples/ParallelSimulationsExample.java | 12 ++-- .../RandomVmAllocationPolicyExample.java | 35 +++++++----- .../cloudsimplus/examples/ReducedExample.java | 7 +-- .../examples/StorageAreaNetworkExample1.java | 35 +++++++----- .../VmAllocationPolicyRoundRobinExample.java | 36 +++++++----- .../VmBootTimeAndOverheadExample.java | 38 +++++++------ .../examples/VmDestructionExample.java | 35 +++++++----- .../examples/VmGroupPlacementExample1.java | 27 ++++----- ...dBalancerByHorizontalVmScalingExample.java | 30 ++++++---- .../VerticalVmCpuScalingDynamicThreshold.java | 38 ++++++++----- .../VerticalVmCpuScalingExample.java | 36 +++++++----- .../VerticalVmRamScalingExample.java | 35 +++++++----- .../BrokerTargetDatacenterExample.java | 35 +++++++----- .../brokers/CloudletToVmMappingBestFit.java | 22 ++++---- ...erBrokerBatchVmCreationRequestExample.java | 37 ++++++++----- .../DatacenterBrokerHeuristicExample.java | 20 +++---- .../DatacenterBrokersMappingComparison.java | 20 +++---- .../DatacenterSelectionByTimeZoneExample.java | 36 +++++++----- .../examples/brokers/MultipleBrokers1.java | 35 +++++++----- .../examples/brokers/MultipleBrokers2.java | 35 +++++++----- .../examples/brokers/MultipleBrokers3.java | 34 +++++++----- .../brokers/SelectNextDatacenterExample.java | 27 ++++----- .../examples/costs/CostsExample1.java | 37 ++++++++----- .../CreateCloudletAfterLastFinishedOne.java | 12 ++-- .../dynamic/DynamicCloudletsArrival1.java | 12 ++-- .../dynamic/DynamicCloudletsArrival2.java | 12 ++-- ...namicCreationOfVmsAndCloudletsExample.java | 14 ++--- .../examples/dynamic/DynamicHostCreation.java | 35 +++++++----- ...namicVmAllocationPolicyBestFitExample.java | 26 +++------ .../examples/dynamic/DynamicVmsArrival.java | 26 +++++---- .../examples/dynamic/DynamicVmsArrival2.java | 12 ++-- .../dynamic/IndefiniteLengthCloudlet.java | 35 +++++++----- .../dynamic/KeepSimulationRunningExample.java | 32 +++++------ .../RandomCloudletsArrivalExample.java | 30 +++++----- .../listeners/CloudletListenersExample1.java | 12 ++-- ...tenersExample2_ResourceUsageAlongTime.java | 12 ++-- .../listeners/VmListenersExample1.java | 12 ++-- .../listeners/VmListenersExample2.java | 12 ++-- ...VmListenersExample3_DynamicVmCreation.java | 12 ++-- .../migration/InterDatacenterMigration1.java | 31 ++++------- .../migration/ManualMigrationExample1.java | 23 +++----- .../examples/migration/MigrationExample1.java | 55 ++++++++----------- .../performance/PerformanceExample1.java | 34 +++++++----- .../UtilizationModelFullPerformance.java | 34 +++++++----- ...UtilizationModelStochasticPerformance.java | 34 +++++++----- .../examples/power/HostActivationExample.java | 33 ++++++----- .../examples/power/PowerExample.java | 36 +++++++----- .../power/PowerExampleSchedulingInterval.java | 34 +++++++----- .../examples/power/PowerSpecFileExample.java | 35 +++++++----- .../resourceusage/HostsCpuUsageExample.java | 20 +++---- .../UtilizationModelDynamicExample.java | 18 ++---- ...equestedRamHigherThanAvailableExample.java | 36 +++++++----- ...elativeHostResourceUtilizationExample.java | 35 +++++++----- .../resourceusage/VmsCpuUsageExample.java | 14 ++--- .../VmsRamAndBwUsageExample.java | 29 +++++----- .../CloudletSchedulerSpaceSharedExample1.java | 28 +++++----- .../CloudletSchedulerTimeSharedExample1.java | 35 +++++++----- .../LinuxCompletelyFairSchedulerExample.java | 34 ++++++------ ...PEsUsingVmSchedulerSpaceSharedExample.java | 24 ++++---- ...tPEsUsingVmSchedulerTimeSharedExample.java | 25 ++++----- ...woCloudletsAndOneSpaceSharedVmExample.java | 10 ++-- ...TwoCloudletsAndOneTimeSharedVmExample.java | 10 ++-- .../VmSchedulerTimeSharedExample.java | 38 ++++++++----- .../PauseSimulationAtGivenTimeExample1.java | 23 ++++---- .../PauseSimulationAtGivenTimeExample2.java | 23 ++++---- ...nateSimulationAtGivenConditionExample.java | 16 ++---- ...TerminateSimulationAtGivenTimeExample.java | 16 ++---- ...grationWhenCpuMetricIsViolatedExample.java | 24 ++++---- .../SynchronousSimulationExample1.java | 36 +++++++----- .../examples/traces/PlanetLabExample1.java | 35 +++++++----- .../traces/SwfWorkloadFormatExample1.java | 35 ++++++------ .../google/GoogleMachineEventsExample1.java | 18 ++---- .../google/GoogleTaskEventsExample1.java | 39 +++++++------ 90 files changed, 1314 insertions(+), 1146 deletions(-) diff --git a/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample1.java b/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample1.java index 84aeb3c..8712d30 100755 --- a/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample1.java +++ b/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample1.java @@ -19,8 +19,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.network.topologies.BriteNetworkTopology; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.resources.SanStorage; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -42,7 +41,7 @@ /// causing the Cloudlet to start executing just after a few seconds. public class NetworkExample1 { private static final String NETWORK_TOPOLOGY_FILE = "topology.brite"; - private static final int VM_PES = 1; + private static final int VM_CORES = 1; private final Datacenter datacenter0; private final DatacenterBroker broker; @@ -102,7 +101,7 @@ private void createAndSubmitCloudlets(DatacenterBroker broker) { final var utilizationModel = new UtilizationModelFull(); final var cloudlet1 = - new CloudletSimple(length, VM_PES) + new CloudletSimple(length, VM_CORES) .setFileSize(fileSize) .setOutputSize(outputSize) .setUtilizationModel(utilizationModel); @@ -119,7 +118,7 @@ private void createAndSubmitVms(DatacenterBroker broker) { final long size = 10000; //image size (Megabyte) final int ram = 512; //vm memory (Megabyte) final long bw = 1000; //in Megabits/s - final Vm vm1 = new VmSimple(mips, VM_PES) + final Vm vm1 = new VmSimple(new CoreCapacity(VM_CORES, mips)) .setRam(ram).setBw(bw).setSize(size) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -129,16 +128,15 @@ private void createAndSubmitVms(DatacenterBroker broker) { private Datacenter createDatacenter() { final var hostList = new ArrayList(); - final var peList = new ArrayList(); final long mips = 1000; - peList.add(new PeSimple(mips)); + final var cpuCapacity = new CoreCapacity(1, mips); final long ram = 2048; // in Megabytes final long storage = 1000000; // in Megabytes final long bw = 10000; //in Megabits/s - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, cpuCapacity); hostList.add(host); return new DatacenterSimple(simulation, hostList); diff --git a/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample2.java b/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample2.java index 6d9721d..43755df 100755 --- a/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample2.java +++ b/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample2.java @@ -19,8 +19,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.network.topologies.BriteNetworkTopology; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; @@ -32,7 +31,7 @@ /// It sets a network topology and then run 2 cloudlets. public class NetworkExample2 { private static final String NETWORK_TOPOLOGY_FILE = "topology.brite"; - private static final int VM_PES = 1; + private static final int VM_CORES = 1; private final List datacenterList; private final List cloudletList; @@ -98,13 +97,13 @@ private void createAndSubmitCloudlets() { final var utilizationModel = new UtilizationModelFull(); final var cloudlet1 = - new CloudletSimple(length, VM_PES) + new CloudletSimple(length, VM_CORES) .setFileSize(fileSize) .setOutputSize(outputSize) .setUtilizationModel(utilizationModel); final var cloudlet2 = - new CloudletSimple(length, VM_PES) + new CloudletSimple(length, VM_CORES) .setFileSize(fileSize) .setOutputSize(outputSize) .setUtilizationModel(utilizationModel); @@ -123,10 +122,10 @@ private void createAndSubmitVms() { final int ram = 512; //vm memory (Megabyte) final long bw = 1000; - final Vm vm1 = new VmSimple(mips, VM_PES) + final Vm vm1 = new VmSimple(new CoreCapacity(VM_CORES, mips)) .setRam(ram).setBw(bw).setSize(size); - final Vm vm2 = new VmSimple(mips, VM_PES) + final Vm vm2 = new VmSimple(new CoreCapacity(VM_CORES, mips)) .setRam(ram).setBw(bw).setSize(size); vmlist.add(vm1); @@ -137,16 +136,15 @@ private void createAndSubmitVms() { private Datacenter createDatacenter() { final var hostList = new ArrayList(); - final var peList = new ArrayList(); final long mips = 1000; - peList.add(new PeSimple(mips)); + final var cpuCapacity = new CoreCapacity(1, mips); final int ram = 2048; //host memory (Megabyte) final long storage = 1000000; //host storage final long bw = 10000; - final Host host = new HostSimple(ram, bw, storage, peList); + final Host host = new HostSimple(ram, bw, storage, cpuCapacity); hostList.add(host); return new DatacenterSimple(simulation, hostList); diff --git a/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample3.java b/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample3.java index 31f9cb8..824443b 100755 --- a/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample3.java +++ b/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample3.java @@ -19,8 +19,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.network.topologies.BriteNetworkTopology; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; @@ -31,7 +30,7 @@ /// A simple example showing how to create 2 datacenters with 1 host each and run /// cloudlets of 2 users. It also sets a network topology. public class NetworkExample3 { - private static final int VM_PES = 1; + private static final int VM_CORES = 1; private final List datacenterList; private final List brokerList; @@ -96,13 +95,13 @@ private void createAndSubmitCloudlets() { final var utilizationModel = new UtilizationModelFull(); final var cloudlet1 = - new CloudletSimple(length, VM_PES) + new CloudletSimple(length, VM_CORES) .setFileSize(fileSize) .setOutputSize(outputSize) .setUtilizationModel(utilizationModel); final var cloudlet2 = - new CloudletSimple(length, VM_PES) + new CloudletSimple(length, VM_CORES) .setFileSize(fileSize) .setOutputSize(outputSize) .setUtilizationModel(utilizationModel); @@ -120,10 +119,10 @@ private void createAndSubmitVms() { final int ram = 512; //vm memory (Megabyte) final long bw = 1000; - final Vm vm1 = new VmSimple(mips, VM_PES) + final Vm vm1 = new VmSimple(new CoreCapacity(VM_CORES, mips)) .setRam(ram).setBw(bw).setSize(size); - final Vm vm2 = new VmSimple(mips, VM_PES) + final Vm vm2 = new VmSimple(new CoreCapacity(VM_CORES, mips)) .setRam(ram).setBw(bw).setSize(size); vmList1.add(vm1); @@ -159,16 +158,15 @@ private void createNetwork() { private Datacenter createDatacenter() { final var hostList = new ArrayList(); - final var peList = new ArrayList(); final long mips = 1000; - peList.add(new PeSimple(mips)); + final var cpuCapacity = new CoreCapacity(1, mips); final long ram = 2048; // in Megabytes final long storage = 1000000; // in Megabytes final long bw = 10000; //in Megabits/s - final Host host = new HostSimple(ram, bw, storage, peList); + final Host host = new HostSimple(ram, bw, storage, cpuCapacity); hostList.add(host); return new DatacenterSimple(simulation, hostList); diff --git a/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample4.java b/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample4.java index 192728b..250223a 100755 --- a/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample4.java +++ b/src/main/java/org/cloudbus/cloudsim/examples/network/NetworkExample4.java @@ -21,8 +21,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.network.topologies.BriteNetworkTopology; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; @@ -41,7 +40,7 @@ /// If 3 messages are sent to the broker for starting a Cloudlet, /// the total delay is the network latency multiplied by 3. public class NetworkExample4 { - private static final int VM_PES = 1; + private static final int VM_CORES = 1; /// In Megabits/s. private static final double NETWORK_BW = 10.0; @@ -98,7 +97,7 @@ private void createAndSubmitCloudlets() { final var utilizationModel = new UtilizationModelFull(); final var cloudlet1 = - new CloudletSimple(length, VM_PES) + new CloudletSimple(length, VM_CORES) .setFileSize(fileSize) .setOutputSize(outputSize) .setUtilizationModel(utilizationModel); @@ -113,7 +112,7 @@ private void createAndSubmitVms() { final int ram = 512; //vm memory (Megabyte) final long bw = 1000; - final Vm vm1 = new VmSimple(mips, VM_PES) + final Vm vm1 = new VmSimple(new CoreCapacity(VM_CORES, mips)) .setRam(ram).setBw(bw).setSize(size); vmList.add(vm1); @@ -122,16 +121,15 @@ private void createAndSubmitVms() { private Datacenter createDatacenter() { final var hostList = new ArrayList(); - final var peList = new ArrayList(); final long mips = 1000; - peList.add(new PeSimple(mips)); + final var cpuCapacity = new CoreCapacity(1, mips); long ram = 2048; //host memory (Megabyte) long storage = 1000000; //host storage (Megabyte) long bw = 10000; //Megabits/s - final Host host = new HostSimple(ram, bw, storage, peList) + final Host host = new HostSimple(ram, bw, storage, cpuCapacity) .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) .setVmScheduler(new VmSchedulerTimeShared()); diff --git a/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmExampleAbstract.java b/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmExampleAbstract.java index c1c72e2..5ded9b0 100755 --- a/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmExampleAbstract.java +++ b/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmExampleAbstract.java @@ -14,8 +14,7 @@ import org.cloudsimplus.network.switches.EdgeSwitch; import org.cloudsimplus.network.switches.RootSwitch; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.vms.network.NetworkVm; @@ -44,7 +43,15 @@ abstract class NetworkVmExampleAbstract { public static final double COST_PER_BW = 0.0; // the cost of using bw in this resource public static final int HOST_MIPS = 1000; - public static final int HOST_PES = 8; + public static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + public static final int HOST_RAM = 2048; // MEGA public static final long HOST_STORAGE = 1000000; // MEGA public static final long HOST_BW = 10000; @@ -53,14 +60,21 @@ abstract class NetworkVmExampleAbstract { public static final long VM_SIZE = 10000; // image size (Megabyte) public static final int VM_RAM = 512; // MEGA public static final long VM_BW = 1000; - public static final int VM_PES_NUMBER = HOST_PES / MAX_VMS_PER_HOST; + public static final int VM_PES_NUMBER = HOST_CORES / MAX_VMS_PER_HOST; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_PES_NUMBER, VM_MIPS); /// Number of fictitious applications to create. /// Each application is just a list of [NetworkCloudlet]. /// @see #appMap public static final int APPS_NUMBER = 1; - public static final int CLOUDLET_PES = VM_PES_NUMBER; + public static final int CLOUDLET_CORES = VM_PES_NUMBER; public static final int TASK_LENGTH = 4000; public static final int CLOUDLET_FILE_SIZE = 300; public static final int CLOUDLET_OUTPUT_SIZE = 300; @@ -154,8 +168,8 @@ protected final NetworkDatacenter createDatacenter() { final int hostsNumber = EdgeSwitch.PORTS * AggregateSwitch.PORTS * RootSwitch.PORTS; final var netHostList = new ArrayList(hostsNumber); for (int i = 0; i < hostsNumber; i++) { - final List peList = createPEs(HOST_PES, HOST_MIPS); - final var host = new NetworkHost(HOST_RAM, HOST_BW, HOST_STORAGE, peList); + final CoreCapacity cpuCapacity = HOST_CAPACITY; + final var host = new NetworkHost(HOST_RAM, HOST_BW, HOST_STORAGE, cpuCapacity); host .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) @@ -175,15 +189,6 @@ protected final NetworkDatacenter createDatacenter() { return dc; } - protected List createPEs(final int pesNumber, final long mips) { - final var peList = new ArrayList(); - for (int i = 0; i < pesNumber; i++) { - peList.add(new PeSimple(mips)); - } - - return peList; - } - /// Creates internal Datacenter network. /// @param datacenter Datacenter where the network will be created protected void createNetwork(final NetworkDatacenter datacenter) { @@ -224,7 +229,7 @@ protected final List createAndSubmitVMs(DatacenterBroker broker) { final int vmsNumber = getDatacenterHostList().size() * MAX_VMS_PER_HOST; final var netVmList = new ArrayList(); for (int i = 0; i < vmsNumber; i++) { - final var vm = new NetworkVm(i, VM_MIPS, VM_PES_NUMBER); + final var vm = new NetworkVm(i, VM_CAPACITY); vm.setRam(VM_RAM) .setBw(VM_BW) .setSize(VM_SIZE) diff --git a/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmsExampleBagOfTasksApp.java b/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmsExampleBagOfTasksApp.java index b36eea8..3e7d26a 100755 --- a/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmsExampleBagOfTasksApp.java +++ b/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmsExampleBagOfTasksApp.java @@ -36,7 +36,7 @@ public List createNetworkCloudlets(DatacenterBroker broker){ for(int i = 0; i < CLOUDLETS_BY_APP; i++){ final var utilizationModel = new UtilizationModelFull(); - final var cloudlet = new NetworkCloudlet(i, CLOUDLET_PES); + final var cloudlet = new NetworkCloudlet(i, CLOUDLET_CORES); final NetworkVm vm = getVmList().get(i); cloudlet .setFileSize(CLOUDLET_FILE_SIZE) diff --git a/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmsExampleSimpleApp.java b/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmsExampleSimpleApp.java index 45a59aa..5c08d51 100755 --- a/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmsExampleSimpleApp.java +++ b/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmsExampleSimpleApp.java @@ -12,8 +12,7 @@ import org.cloudsimplus.hosts.network.NetworkHost; import org.cloudsimplus.network.switches.EdgeSwitch; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -32,7 +31,22 @@ public class NetworkVmsExampleSimpleApp { private static final int HOSTS = 2; private static final int HOST_MIPS = 1000; - private static final int HOST_PES = 4; + private static final int HOST_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = VM_CAPACITY; + private static final int HOST_RAM = 2048; // host memory (Megabyte) private static final long HOST_STORAGE = 1000000; // host storage private static final long HOST_BW = 10000; @@ -100,8 +114,7 @@ private NetworkDatacenter createDatacenter() { } private NetworkHost createHost() { - final var peList = createPEs(HOST_PES, HOST_MIPS); - final var host = new NetworkHost(HOST_RAM, HOST_BW, HOST_STORAGE, peList); + final var host = new NetworkHost(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY); host .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) @@ -110,15 +123,6 @@ private NetworkHost createHost() { return host; } - private List createPEs(final int pesNumber, final long mips) { - final var peList = new ArrayList(); - for (int i = 0; i < pesNumber; i++) { - peList.add(new PeSimple(mips)); - } - - return peList; - } - /// Creates internal Datacenter network. /// /// @param datacenter Datacenter where the network will be created @@ -152,7 +156,7 @@ private List createAndSubmitVMs(DatacenterBroker broker) { } private NetworkVm createVm(int id) { - final var vm = new NetworkVm(id, HOST_MIPS, HOST_PES); + final var vm = new NetworkVm(id, HOST_CAPACITY); vm .setRam(HOST_RAM) .setBw(HOST_BW) @@ -189,7 +193,7 @@ private List createNetworkCloudlets() { /// @param vm the VM that will run the created [NetworkCloudlet] /// @return private NetworkCloudlet createNetworkCloudlet(NetworkVm vm) { - final var netCloudlet = new NetworkCloudlet(HOST_PES); + final var netCloudlet = new NetworkCloudlet(HOST_CORES); netCloudlet .setFileSize(CLOUDLET_FILE_SIZE) .setOutputSize(CLOUDLET_OUTPUT_SIZE) diff --git a/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmsExampleWorkflowApp.java b/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmsExampleWorkflowApp.java index 457ff7f..8882da0 100755 --- a/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmsExampleWorkflowApp.java +++ b/src/main/java/org/cloudbus/cloudsim/examples/network/applications/NetworkVmsExampleWorkflowApp.java @@ -59,7 +59,7 @@ public List createNetworkCloudlets(final DatacenterBroker broke /// @return private NetworkCloudlet createNetworkCloudlet(final int id, final NetworkVm vm) { final var utilizationModel = new UtilizationModelFull(); - final var cloudlet = new NetworkCloudlet(id, CLOUDLET_PES); + final var cloudlet = new NetworkCloudlet(id, CLOUDLET_CORES); cloudlet .setFileSize(CLOUDLET_FILE_SIZE) .setOutputSize(CLOUDLET_OUTPUT_SIZE) diff --git a/src/main/java/org/cloudsimplus/examples/BasicFirstExample.java b/src/main/java/org/cloudsimplus/examples/BasicFirstExample.java index 5038c08..0db0235 100755 --- a/src/main/java/org/cloudsimplus/examples/BasicFirstExample.java +++ b/src/main/java/org/cloudsimplus/examples/BasicFirstExample.java @@ -33,8 +33,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; @@ -47,23 +46,38 @@ /// /// It defines a set of constants that enables a developer /// to change the number of Hosts, VMs and Cloudlets to create -/// and the number of [Pe]s for Hosts, VMs and Cloudlets. +/// and the number of CPU cores for Hosts, VMs and Cloudlets. /// /// @author Manoel Campos da Silva Filho /// @since CloudSim Plus 1.0 public class BasicFirstExample { private static final int HOSTS = 1; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; private static final int HOST_MIPS = 1000; // Million Instructions per Second (MIPS) + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + private static final int HOST_RAM = 2048; //in Megabytes private static final long HOST_BW = 10_000; //in Megabits/s private static final long HOST_STORAGE = 1_000_000; //in Megabytes private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, HOST_MIPS); private static final int CLOUDLETS = 4; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10_000; // Million Instructions (MI) private final CloudSimPlus simulation; @@ -111,18 +125,11 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - //Uses a PeProvisionerSimple by default to provision PEs for VMs - peList.add(new PeSimple(HOST_MIPS)); - } - /* Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList); + return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY); } /// Creates a list of VMs. @@ -130,7 +137,7 @@ private List createVms() { final var vmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final var vm = new VmSimple(HOST_MIPS, VM_PES); + final var vm = new VmSimple(VM_CAPACITY); vm.setRam(512).setBw(1000).setSize(10_000); vmList.add(vm); } @@ -146,7 +153,7 @@ private List createCloudlets() { final var utilizationModel = new UtilizationModelDynamic(0.5); for (int i = 0; i < CLOUDLETS; i++) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES, utilizationModel); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES, utilizationModel); cloudlet.setSizes(1024); cloudletList.add(cloudlet); } diff --git a/src/main/java/org/cloudsimplus/examples/CloudletAndVmLifeTimeExample.java b/src/main/java/org/cloudsimplus/examples/CloudletAndVmLifeTimeExample.java index ca61dd1..49ce525 100644 --- a/src/main/java/org/cloudsimplus/examples/CloudletAndVmLifeTimeExample.java +++ b/src/main/java/org/cloudsimplus/examples/CloudletAndVmLifeTimeExample.java @@ -35,8 +35,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.util.TimeUtil; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -48,7 +47,6 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import java.util.stream.IntStream; /// An example showing how to use the new [Lifetimed#setLifeTime(double)] to /// define the maximum time [Cloudlet] or [Vm] entity is allowed to execute. @@ -67,14 +65,28 @@ /// @see CloudletLifeTimeExample public class CloudletAndVmLifeTimeExample { private static final int HOSTS = 3; - private static final int HOST_PES = 10; + private static final int HOST_CORES = 10; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 4; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; private static final int VM_MIPS = 1000; + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, VM_MIPS); + private static final int CLOUDLETS = 4; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10_000; /// If the scheduling interval is not multiple of the VM/Cloudlet lifetime, @@ -161,14 +173,10 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - IntStream.range(0, HOST_PES).forEach(i -> peList.add(new PeSimple(1000))); - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setVmScheduler(new VmSchedulerTimeShared()); return host; } @@ -176,7 +184,7 @@ private Host createHost() { private List createVms() { final var vmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { - final var vm = new VmSimple(i, VM_MIPS, VM_PES); + final var vm = new VmSimple(i, VM_CAPACITY); vmList.add(vm); } @@ -186,7 +194,7 @@ private List createVms() { private List createCloudlets() { final var cloudletList = new ArrayList(CLOUDLETS); for (int i = 0; i < CLOUDLETS; i++) { - final var cloudlet = new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_CORES); cloudlet .setFileSize(1024) .setOutputSize(1024) diff --git a/src/main/java/org/cloudsimplus/examples/CloudletCancellationExample.java b/src/main/java/org/cloudsimplus/examples/CloudletCancellationExample.java index 67124ed..3f592ca 100755 --- a/src/main/java/org/cloudsimplus/examples/CloudletCancellationExample.java +++ b/src/main/java/org/cloudsimplus/examples/CloudletCancellationExample.java @@ -35,8 +35,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.CloudletVmEventInfo; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletScheduler; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; @@ -66,13 +65,27 @@ public class CloudletCancellationExample { private static final int SCHEDULING_INTERVAL = 1; private static final int HOSTS = 1; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = 4; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -141,19 +154,13 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes final var ramProvisioner = new ResourceProvisionerSimple(); final var bwProvisioner = new ResourceProvisionerSimple(); final var vmScheduler = new VmSchedulerTimeShared(); - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host .setRamProvisioner(ramProvisioner) .setBwProvisioner(bwProvisioner) @@ -166,7 +173,7 @@ private List createVms() { final var list = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { Vm vm = - new VmSimple(i, 1000, VM_PES) + new VmSimple(i, VM_CAPACITY) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -181,7 +188,7 @@ private List createCloudlets() { final var list = new ArrayList(CLOUDLETS); for (int i = 0; i < CLOUDLETS; i++) { final var cloudlet = - new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_PES) + new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelCpu(new UtilizationModelFull()) diff --git a/src/main/java/org/cloudsimplus/examples/CloudletLifeTimeExample.java b/src/main/java/org/cloudsimplus/examples/CloudletLifeTimeExample.java index dac0402..52492fd 100644 --- a/src/main/java/org/cloudsimplus/examples/CloudletLifeTimeExample.java +++ b/src/main/java/org/cloudsimplus/examples/CloudletLifeTimeExample.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.util.TimeUtil; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -46,7 +45,6 @@ import java.time.LocalTime; import java.util.ArrayList; import java.util.List; -import java.util.stream.IntStream; /// An example showing how to use the new [Cloudlet#setLifeTime(double)] to /// define the maximum time the Cloudlet is allowed to execute. @@ -58,14 +56,28 @@ /// @see CloudletAndVmLifeTimeExample public class CloudletLifeTimeExample { private static final int HOSTS = 3; - private static final int HOST_PES = 10; + private static final int HOST_CORES = 10; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 4; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; private static final int VM_MIPS = 1000; + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, VM_MIPS); + private static final int CLOUDLETS = 4; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10_000; /// If the scheduling interval is not multiple of the VM/Cloudlet lifetime, @@ -125,14 +137,10 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - IntStream.range(0, HOST_PES).forEach(i -> peList.add(new PeSimple(1000))); - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setVmScheduler(new VmSchedulerTimeShared()); return host; } @@ -140,7 +148,7 @@ private Host createHost() { private List createVms() { final var vmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { - final var vm = new VmSimple(i, VM_MIPS, VM_PES); + final var vm = new VmSimple(i, VM_CAPACITY); vmList.add(vm); } @@ -150,7 +158,7 @@ private List createVms() { private List createCloudlets() { final var cloudletList = new ArrayList(CLOUDLETS); for (int i = 0; i < CLOUDLETS; i++) { - final var cloudlet = new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_CORES); cloudlet .setFileSize(1024) .setOutputSize(1024) diff --git a/src/main/java/org/cloudsimplus/examples/CloudletsTableBuilderFormattingExample.java b/src/main/java/org/cloudsimplus/examples/CloudletsTableBuilderFormattingExample.java index 28be2b9..161718b 100644 --- a/src/main/java/org/cloudsimplus/examples/CloudletsTableBuilderFormattingExample.java +++ b/src/main/java/org/cloudsimplus/examples/CloudletsTableBuilderFormattingExample.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; @@ -53,17 +52,32 @@ /// @author Manoel Campos da Silva Filho public class CloudletsTableBuilderFormattingExample { private static final int HOSTS = 1; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; private static final int HOST_MIPS = 1000; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + private static final int HOST_RAM = 2048; //in Megabytes private static final long HOST_BW = 10_000; //in Megabits/s private static final long HOST_STORAGE = 1_000_000; //in Megabytes private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, HOST_MIPS); private static final int CLOUDLETS = 4; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; /// Cloudlet lengths are deliberately arbitrary to create more /// interesting results for custom formatting. @@ -107,7 +121,6 @@ private CloudletsTableBuilderFormattingExample() { /// Displays a list of cloudlets as a table while demonstrating several formatting/display options. /// @param cloudletFinishedList The list of cloudlets to use for the demonstration. private void demonstrateCloudletTableFormattingOptions(List cloudletFinishedList) { - /// Prints the results with default settings. new CloudletsTableBuilder(cloudletFinishedList) .build(); @@ -149,18 +162,11 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - //Uses a PeProvisionerSimple by default to provision PEs for VMs - peList.add(new PeSimple(HOST_MIPS)); - } - /* Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList); + return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY); } /// Creates a list of VMs. @@ -168,7 +174,7 @@ private List createVms() { final var vmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final var vm = new VmSimple(HOST_MIPS, VM_PES); + final var vm = new VmSimple(VM_CAPACITY); vm.setRam(512).setBw(1000).setSize(10_000); vmList.add(vm); } @@ -185,20 +191,18 @@ private List createCloudlets() { final var utilizationModel = new UtilizationModelDynamic(0.5); for (int i = 0; i < CLOUDLETS; i++) { - if(i % 2 == 0) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH_SHORT, CLOUDLET_PES, utilizationModel); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH_SHORT, CLOUDLET_CORES, utilizationModel); cloudlet.setSizes(1024); cloudlet.setSubmissionDelay(0.7); cloudletList.add(cloudlet); }else { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH_LONG, CLOUDLET_PES, utilizationModel); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH_LONG, CLOUDLET_CORES, utilizationModel); cloudlet.setSizes(2048); cloudlet.setSubmissionDelay(1.2); cloudletList.add(cloudlet); } - - + } return cloudletList; diff --git a/src/main/java/org/cloudsimplus/examples/HostFaultInjectionExample1.java b/src/main/java/org/cloudsimplus/examples/HostFaultInjectionExample1.java index e3444ea..a34d8f9 100755 --- a/src/main/java/org/cloudsimplus/examples/HostFaultInjectionExample1.java +++ b/src/main/java/org/cloudsimplus/examples/HostFaultInjectionExample1.java @@ -37,8 +37,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.util.TimeUtil; @@ -51,7 +50,7 @@ import java.util.List; import java.util.stream.IntStream; -/// Example showing how to inject random [Pe] faults into Hosts using +/// Example showing how to inject random CPU core faults into Hosts using /// [HostFaultInjection] objects. /// /// It's considered that we have multiple VMs from a given customer (broker), @@ -75,8 +74,16 @@ public final class HostFaultInjectionExample1 { /// Number of Hosts to create for each Datacenter. The number of elements in /// this array defines the number of Datacenters to be created. private static final int HOSTS = 8; - private static final int HOST_PES = 5; + private static final int HOST_CORES = 5; private static final int HOST_MIPS_BY_PE = 1000; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS_BY_PE); + private static final long HOST_RAM = 500000; //host memory (Megabyte) private static final long HOST_STORAGE = 1000000; //host storage private static final long HOST_BW = 100000000L; @@ -92,14 +99,22 @@ public final class HostFaultInjectionExample1 { private final List hostList = new ArrayList<>(); private static final int VMS_BY_BROKER = 2; - private static final int VM_PES = 2; //number of cpus + private static final int VM_CORES = 2; //number of cpus private static final int VM_MIPS = 1000; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, VM_MIPS); + private static final long VM_SIZE = 1000; //image size (Megabyte) private static final int VM_RAM = 10000; //vm memory (Megabyte) private static final long VM_BW = 100000; private static final int CLOUDLETS_BY_BROKER = 6; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; /// The length has to be large to ensure the simulation will run for long enough, /// so that faults will affect all VMs from certain broker. @@ -179,7 +194,7 @@ public void createAndSubmitVms(final DatacenterBroker broker) { } public Vm createVm() { - final Vm vm = new VmSimple(++createdVms, VM_MIPS, VM_PES); + final Vm vm = new VmSimple(++createdVms, VM_CAPACITY); vm .setRam(VM_RAM).setBw(VM_BW).setSize(VM_SIZE) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -195,7 +210,7 @@ public void createAndSubmitCloudlets(final DatacenterBroker broker) { final var utilizationModelFull = new UtilizationModelFull(); for (int i = 0; i < CLOUDLETS_BY_BROKER; i++) { Cloudlet c - = new CloudletSimple(++createdCloudlets, CLOUDLET_LENGTH, CLOUDLET_PES) + = new CloudletSimple(++createdCloudlets, CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(CLOUDLET_FILESIZE) .setOutputSize(CLOUDLET_OUTPUT_SIZE) .setUtilizationModelCpu(utilizationModelFull) @@ -219,11 +234,10 @@ private Datacenter createDatacenter() { } public Host createHost(final int id) { - final var pesList = createPeList(HOST_PES, HOST_MIPS_BY_PE); final var ramProvisioner = new ResourceProvisionerSimple(); final var bwProvisioner = new ResourceProvisionerSimple(); final var vmScheduler = new VmSchedulerTimeShared(); - final var host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, pesList); + final var host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY); host .setRamProvisioner(ramProvisioner) .setBwProvisioner(bwProvisioner) @@ -233,15 +247,6 @@ public Host createHost(final int id) { return host; } - public List createPeList(final int pesNumber, final long mips) { - final var peList = new ArrayList(pesNumber); - for (int i = 0; i < pesNumber; i++) { - peList.add(new PeSimple(mips)); - } - - return peList; - } - /// Creates the fault injection for host /// /// @param datacenter @@ -270,7 +275,7 @@ private HostFaultInjection createFaultInjectionForHosts(final Datacenter datacen /// /// @see #createFaultInjectionForHosts(Datacenter) private Vm cloneVm(final Vm vm) { - final Vm clone = new VmSimple(vm.getMips(), vm.getPesNumber()); + final Vm clone = new VmSimple(new CoreCapacity(vm.getProcessor().getCores(), vm.getProcessor().getMips())); /*It' not required to set an ID for the clone. It is being set here just to make it easy to relate the ID of the vm to its clone, @@ -286,7 +291,7 @@ private Vm cloneVm(final Vm vm) { System.out.printf( "%n# %s: Cloning %s as Vm %d -> MIPS: %.0f PEs Number: %d%n", - vm.getBroker(), vm, clone.getId(), clone.getMips(), clone.getPesNumber()); + vm.getBroker(), vm, clone.getId(), clone.getProcessor().getMips(), clone.getProcessor().getCores()); return clone; } @@ -320,7 +325,7 @@ private List cloneCloudlets(final Vm sourceVm) { /// @param source the Cloudlet to be cloned. /// @return the cloned (new) cloudlet private Cloudlet cloneCloudlet(Cloudlet source) { - final var clone = new CloudletSimple(source.getLength(), source.getPesNumber()); + final var clone = new CloudletSimple(source.getLength(), source.getRequiredCores()); /*It' not required to set an ID for the clone. It is being set here just to make it easy to relate the ID of the cloudlet to its clone, diff --git a/src/main/java/org/cloudsimplus/examples/LargeScaleExample.java b/src/main/java/org/cloudsimplus/examples/LargeScaleExample.java index 437e77d..90defab 100755 --- a/src/main/java/org/cloudsimplus/examples/LargeScaleExample.java +++ b/src/main/java/org/cloudsimplus/examples/LargeScaleExample.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.util.Log; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.vms.Vm; @@ -65,17 +64,32 @@ /// @since ClodSimPlus 7.3.1 public class LargeScaleExample { private static final int HOSTS = 200_000; - private static final int HOST_PES = 16; + private static final int HOST_CORES = 16; private static final int HOST_MIPS = 1000; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + private static final int HOST_RAM = 2048; //in Megabytes private static final long HOST_BW = 10_000; //in Megabits/s private static final long HOST_STORAGE = 1_000_000; //in Megabytes private static final int VMS = HOSTS*4; - private static final int VM_PES = HOST_PES/4; + private static final int VM_CORES = HOST_CORES/4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, HOST_MIPS); private static final int CLOUDLETS = VMS; - private static final int CLOUDLET_PES = VM_PES/2; + private static final int CLOUDLET_CORES = VM_CORES/2; private static final int CLOUDLET_LENGTH = HOST_MIPS * 10; /// Defines a time interval to process cloudlets execution @@ -157,18 +171,11 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - //Uses a PeProvisionerSimple by default to provision PEs for VMs - peList.add(new PeSimple(HOST_MIPS)); - } - /* Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList); + return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY); } /// Creates a list of VMs. @@ -177,7 +184,7 @@ private List createVms() { System.out.printf("Creating %,d VMs%n", VMS); for (int i = 0; i < VMS; i++) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final var vm = new VmSimple(HOST_MIPS, VM_PES); + final var vm = new VmSimple(VM_CAPACITY); vm.setRam(512).setBw(1000).setSize(10_000); vmList.add(vm); } @@ -194,7 +201,7 @@ private List createCloudlets() { System.out.printf("Creating %,d Cloudlets%n", CLOUDLETS); for (int i = 0; i < CLOUDLETS; i++) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES, utilizationModel); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES, utilizationModel); cloudlet.setSizes(1024); cloudletList.add(cloudlet); } diff --git a/src/main/java/org/cloudsimplus/examples/LoggingExample.java b/src/main/java/org/cloudsimplus/examples/LoggingExample.java index db6f7ac..a488832 100755 --- a/src/main/java/org/cloudsimplus/examples/LoggingExample.java +++ b/src/main/java/org/cloudsimplus/examples/LoggingExample.java @@ -37,8 +37,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletScheduler; import org.cloudsimplus.selectionpolicies.VmSelectionPolicyRandomSelection; import org.cloudsimplus.util.Log; @@ -61,13 +60,13 @@ public class LoggingExample { private static final int SCHEDULING_INTERVAL_SECS = 10; private static final double HOST_OVER_UTILIZATION_MIGRATION_THRESHOLD = 0.7; - private static final int[] HOST_PES = {8, 8, 4, 4, 4}; + private static final int[] HOST_CORES = {8, 8, 4, 4, 4}; private static final int VMS = 5; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; private static final int CLOUDLETS = 2; - private static final int CLOUDLET_PES = 1; + private static final int CLOUDLET_CORES = 1; private static final int CLOUDLET_LENGTH = 50_000; private static final int HOST_MIPS = 10_000; @@ -76,6 +75,14 @@ public class LoggingExample { private static final int HOST_STORAGE = 1_000_000; private static final int VM_MIPS = 1_000; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, VM_MIPS); + private static final int VM_RAM = 2_000; private static final int VM_BW = 2_000; private static final int VM_SIZE = 10_000; @@ -144,8 +151,8 @@ private UtilizationModelDynamic createDynamicUtilizationModel() { /// Creates a Datacenter and its Hosts. private Datacenter createDatacenter() { - final var hostList = new ArrayList(HOST_PES.length); - for (int pes : HOST_PES) { + final var hostList = new ArrayList(HOST_CORES.length); + for (int pes : HOST_CORES) { final var host = createHost(pes); hostList.add(host); } @@ -165,18 +172,13 @@ private Datacenter createDatacenter() { } private Host createHost(final int pes) { - final var peList = new ArrayList(pes); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < pes; i++) { - //Uses a PeProvisionerSimple by default to provision PEs for VMs - peList.add(new PeSimple(HOST_MIPS)); - } + final var cpuCapacity = new CoreCapacity(pes, HOST_MIPS); /* Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList); + return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, cpuCapacity); } /// Creates a list of VMs. @@ -184,7 +186,7 @@ private List createVms() { final var list = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final Vm vm = new VmSimple(VM_MIPS, VM_PES); + final Vm vm = new VmSimple(VM_CAPACITY); vm.setRam(VM_RAM).setBw(VM_BW).setSize(VM_SIZE); list.add(vm); } @@ -205,7 +207,7 @@ private List createCloudlets(final UtilizationModel utilizationModel, final var list = new ArrayList(CLOUDLETS); for (int i = 0; i < CLOUDLETS; i++) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES, utilizationModel); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES, utilizationModel); cloudlet.setSubmissionDelay(submissionDelay); cloudlet.setSizes(1024); list.add(cloudlet); diff --git a/src/main/java/org/cloudsimplus/examples/MinTimeBetweenEventsExample.java b/src/main/java/org/cloudsimplus/examples/MinTimeBetweenEventsExample.java index b67d824..bd8b220 100755 --- a/src/main/java/org/cloudsimplus/examples/MinTimeBetweenEventsExample.java +++ b/src/main/java/org/cloudsimplus/examples/MinTimeBetweenEventsExample.java @@ -40,8 +40,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.vm.VmSchedulerSpaceShared; import org.cloudsimplus.util.Log; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -89,8 +88,24 @@ public class MinTimeBetweenEventsExample { private static final int CLOUDLETS = 6; private static final long HOST_MIPS = 1000; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_PES_NUMBER, HOST_MIPS); + private static final int VM_MIPS = 1000; - private static final int CLOUDLET_PES = 1; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_PES_NUMBER, VM_MIPS); + + private static final int CLOUDLET_CORES = 1; private static final long CLOUDLET_LENGTH = 100; //in number of Million Instructions (MI) private final List hostList; @@ -131,17 +146,11 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(); - for (int i = 0; i < HOST_PES_NUMBER; i++) { - final var peSimple = new PeSimple(HOST_MIPS); - peList.add(peSimple); - } - final long ram = 4096; // host memory (Megabyte) final long storage = 1000000; // host storage (Megabyte) final long bw = 10000; //Megabits/s - return new HostSimple(ram, bw, storage, peList) + return new HostSimple(ram, bw, storage, HOST_CAPACITY) .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) .setVmScheduler(new VmSchedulerSpaceShared()); @@ -164,7 +173,7 @@ private Vm createVm(final int id) { final long bw = 1000; //It uses a CloudletSchedulerTimeShared by default - final Vm vm = new VmSimple(id, VM_MIPS, VM_PES_NUMBER); + final Vm vm = new VmSimple(id, VM_CAPACITY); vm.setRam(ram).setBw(bw).setSize(size); return vm; } @@ -190,7 +199,7 @@ private Cloudlet createCloudlet(final Vm vm) { final long outputSize = 300; //in bytes final var utilizationModel = new UtilizationModelDynamic(0.1); - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES) + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(fileSize) .setOutputSize(outputSize) .setUtilizationModelCpu(new UtilizationModelFull()) diff --git a/src/main/java/org/cloudsimplus/examples/ParallelSimulationsExample.java b/src/main/java/org/cloudsimplus/examples/ParallelSimulationsExample.java index 5c82994..0cd5f3a 100755 --- a/src/main/java/org/cloudsimplus/examples/ParallelSimulationsExample.java +++ b/src/main/java/org/cloudsimplus/examples/ParallelSimulationsExample.java @@ -34,8 +34,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.util.Log; @@ -155,12 +154,9 @@ private Host createHost() { final long bw = 10000; // in Megabits/s final int pesNumber = 4; - final var peList = new ArrayList(pesNumber); // List of CPU cores - for(int i = 0; i < pesNumber; i++) { - peList.add(new PeSimple(mips)); - } + final var cpuCapacity = new CoreCapacity(pesNumber, mips); - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerTimeShared()); + return new HostSimple(ram, bw, storage, cpuCapacity).setVmScheduler(new VmSchedulerTimeShared()); } private void createVms() { @@ -182,7 +178,7 @@ private Vm createVm(final int id) { final long bw = 1000; // vm bandwidth (Megabits/s) final int pesNumber = 2; // number of CPU cores - return new VmSimple(id, mips, pesNumber) + return new VmSimple(id, new CoreCapacity(pesNumber, mips)) .setRam(ram) .setBw(bw) .setSize(storage); diff --git a/src/main/java/org/cloudsimplus/examples/RandomVmAllocationPolicyExample.java b/src/main/java/org/cloudsimplus/examples/RandomVmAllocationPolicyExample.java index a5eae5c..33508cf 100755 --- a/src/main/java/org/cloudsimplus/examples/RandomVmAllocationPolicyExample.java +++ b/src/main/java/org/cloudsimplus/examples/RandomVmAllocationPolicyExample.java @@ -38,8 +38,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.util.Log; @@ -68,13 +67,27 @@ /// @since CloudSim Plus 4.0.5 public class RandomVmAllocationPolicyExample { private static final int HOSTS = 10; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 4; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = 4; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -162,16 +175,10 @@ private Optional findRandomSuitableHostForVm(final VmAllocationPolicy vmAl } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) @@ -184,7 +191,7 @@ private List createVms() { final var list = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { Vm vm = - new VmSimple(i, 1000, VM_PES) + new VmSimple(i, VM_CAPACITY) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -200,7 +207,7 @@ private List createCloudlets() { final var utilization = new UtilizationModelDynamic(0.2); for (int i = 0; i < CLOUDLETS; i++) { final var cloudlet = - new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_PES) + new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelBw(utilization) diff --git a/src/main/java/org/cloudsimplus/examples/ReducedExample.java b/src/main/java/org/cloudsimplus/examples/ReducedExample.java index 14d42ed..17a41a8 100755 --- a/src/main/java/org/cloudsimplus/examples/ReducedExample.java +++ b/src/main/java/org/cloudsimplus/examples/ReducedExample.java @@ -29,7 +29,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.examples.BasicFirstExample; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.vms.VmSimple; @@ -66,10 +66,9 @@ void main() { final long bw = 100000; //in Megabits/s //Creates one Hosts with a specific list of CPU cores (PEs). - //Uses a PeProvisionerSimple by default to provision PEs for VMs. //Uses ResourceProvisionerSimple by default for RAM and BW provisioning //Uses VmSchedulerSpaceShared by default for VM scheduling - final var host0 = new HostSimple(ram, bw, storage, List.of(new PeSimple(20000))); + final var host0 = new HostSimple(ram, bw, storage, new CoreCapacity(20000)); //Creates one Datacenter with a list of Hosts //Uses a VmAllocationPolicySimple by default to allocate VMs @@ -77,7 +76,7 @@ void main() { //Creates one Vm to run applications (Cloudlets). //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets. - final var vm0 = new VmSimple(1000, 1); + final var vm0 = new VmSimple(new CoreCapacity(1, 1000)); vm0.setRam(1000).setBw(1000).setSize(1000); final var vmList = List.of(vm0); diff --git a/src/main/java/org/cloudsimplus/examples/StorageAreaNetworkExample1.java b/src/main/java/org/cloudsimplus/examples/StorageAreaNetworkExample1.java index bf9ac4c..4ae46e1 100755 --- a/src/main/java/org/cloudsimplus/examples/StorageAreaNetworkExample1.java +++ b/src/main/java/org/cloudsimplus/examples/StorageAreaNetworkExample1.java @@ -34,9 +34,8 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.resources.File; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; import org.cloudsimplus.resources.SanStorage; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; @@ -60,13 +59,27 @@ /// @since CloudSim Plus 1.2.6 public class StorageAreaNetworkExample1 { private static final int HOSTS = 2; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 4; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = VMS; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private static final double NETWORK_LATENCY_SEC = 0.3; @@ -175,17 +188,11 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes final var vmScheduler = new VmSchedulerTimeShared(); - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setVmScheduler(vmScheduler); return host; } @@ -195,7 +202,7 @@ private List createVms() { final var list = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { Vm vm = - new VmSimple(i, 1000, VM_PES) + new VmSimple(i, VM_CAPACITY) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -213,7 +220,7 @@ private List createCloudlets() { final var utilization = new UtilizationModelFull(); for (int i = 0; i < CLOUDLETS; i++) { final var cloudlet = - new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_PES) + new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModel(utilization); diff --git a/src/main/java/org/cloudsimplus/examples/VmAllocationPolicyRoundRobinExample.java b/src/main/java/org/cloudsimplus/examples/VmAllocationPolicyRoundRobinExample.java index 3f2cce7..07a8788 100755 --- a/src/main/java/org/cloudsimplus/examples/VmAllocationPolicyRoundRobinExample.java +++ b/src/main/java/org/cloudsimplus/examples/VmAllocationPolicyRoundRobinExample.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; @@ -57,13 +56,27 @@ /// @since CloudSim Plus 4.4.2 public class VmAllocationPolicyRoundRobinExample { private static final int HOSTS = 4; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 8; - private static final int VM_PES = 2; + private static final int VM_CORES = 2; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = 8; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -111,13 +124,6 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - //Uses a PeProvisionerSimple by default to provision PEs for VMs - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes @@ -126,7 +132,7 @@ private Host createHost() { Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - return new HostSimple(ram, bw, storage, peList, false); + return new HostSimple(ram, bw, storage, HOST_CAPACITY, false); } /// Creates a list of VMs. @@ -134,7 +140,7 @@ private List createVms() { final var list = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final Vm vm = new VmSimple(1000, VM_PES); + final Vm vm = new VmSimple(VM_CAPACITY); vm.setRam(512).setBw(1000).setSize(10000); list.add(vm); } @@ -150,7 +156,7 @@ private List createCloudlets() { final var utilizationModel = new UtilizationModelDynamic(0.5); for (int i = 0; i < CLOUDLETS; i++) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES, utilizationModel); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES, utilizationModel); cloudlet.setSizes(1024); list.add(cloudlet); } diff --git a/src/main/java/org/cloudsimplus/examples/VmBootTimeAndOverheadExample.java b/src/main/java/org/cloudsimplus/examples/VmBootTimeAndOverheadExample.java index eeb648d..494f65e 100755 --- a/src/main/java/org/cloudsimplus/examples/VmBootTimeAndOverheadExample.java +++ b/src/main/java/org/cloudsimplus/examples/VmBootTimeAndOverheadExample.java @@ -34,8 +34,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.VmHostEventInfo; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.BootModel; import org.cloudsimplus.utilizationmodels.UtilizationModel; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -52,17 +51,32 @@ /// @since CloudSim Plus 8.3.0 public class VmBootTimeAndOverheadExample { private static final int HOSTS = 1; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; private static final int HOST_MIPS = 1000; // Million Instructions per Second (MIPS) + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + private static final int HOST_RAM = 2048; //in Megabytes private static final long HOST_BW = 10_000; //in Megabits/s private static final long HOST_STORAGE = 1_000_000; //in Megabytes private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, HOST_MIPS); private static final int CLOUDLETS = 2; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10_000; // Million Instructions (MI) /// Defines the time (in seconds) each VM will take to boot up. @@ -116,7 +130,6 @@ private static double getVmCpuUsage(Vm vm) { return vm.getCpuPercentUtilization() * 100.0; } - private static double getVmRamUsage(final Vm vm) { return vm.getRam().getPercentUtilization() * 100.0; } @@ -134,18 +147,11 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - //Uses a PeProvisionerSimple by default to provision PEs for VMs - peList.add(new PeSimple(HOST_MIPS)); - } - /* Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList); + return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY); } /// Creates a list of VMs setting a [BootModel] @@ -157,7 +163,7 @@ private List createVms() { final var bootModelRam = new UtilizationModelDynamic(0.3); for (int i = 0; i < VMS; i++) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final var vm = new VmSimple(HOST_MIPS, VM_PES); + final var vm = new VmSimple(VM_CAPACITY); vm.setRam(512) .setBw(1000) .setSize(10_000) @@ -178,7 +184,7 @@ private List createCloudlets() { final var utilizationModel = new UtilizationModelDynamic(0.5); for (int i = 0; i < CLOUDLETS; i++) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES, utilizationModel); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES, utilizationModel); cloudlet.setSizes(1024); cloudletList.add(cloudlet); } diff --git a/src/main/java/org/cloudsimplus/examples/VmDestructionExample.java b/src/main/java/org/cloudsimplus/examples/VmDestructionExample.java index a3c538b..1af10d8 100755 --- a/src/main/java/org/cloudsimplus/examples/VmDestructionExample.java +++ b/src/main/java/org/cloudsimplus/examples/VmDestructionExample.java @@ -36,8 +36,7 @@ import org.cloudsimplus.listeners.EventListener; import org.cloudsimplus.listeners.VmHostEventInfo; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -80,13 +79,27 @@ public class VmDestructionExample { private static final int SCHEDULING_INTERVAL = 1; private static final int HOSTS = 1; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = 4; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -163,19 +176,13 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes final var ramProvisioner = new ResourceProvisionerSimple(); final var bwProvisioner = new ResourceProvisionerSimple(); final var vmScheduler = new VmSchedulerTimeShared(); - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host .setRamProvisioner(ramProvisioner) .setBwProvisioner(bwProvisioner) @@ -188,7 +195,7 @@ private List createVms() { final var list = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { Vm vm = - new VmSimple(i, 1000, VM_PES) + new VmSimple(i, VM_CAPACITY) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -213,7 +220,7 @@ private List createCloudlets() { for (int i = 0; i < CLOUDLETS; i++) { final var cloudlet = - new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_PES) + new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelRam(utilization) diff --git a/src/main/java/org/cloudsimplus/examples/VmGroupPlacementExample1.java b/src/main/java/org/cloudsimplus/examples/VmGroupPlacementExample1.java index 8116efb..c294b21 100755 --- a/src/main/java/org/cloudsimplus/examples/VmGroupPlacementExample1.java +++ b/src/main/java/org/cloudsimplus/examples/VmGroupPlacementExample1.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; @@ -63,13 +62,20 @@ public class VmGroupPlacementExample1 { /// Number of [Vm]s in each [VmGroup]. private static final int VMS_BY_GROUP = 2; - private static final int BASE_HOST_RAM = 1000; private static final int BASE_HOST_BW = 1000; private static final int BASE_HOST_STORAGE = 100_000; private static final int HOST_MIPS = 1000; - private static final int VM_PES = 2; + private static final int VM_CORES = 2; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, HOST_MIPS); + private static final int VM_RAM = 1200; private static final int VM_BW = 1200; private static final int VM_STORAGE = 10_000; @@ -131,12 +137,7 @@ private Datacenter createDatacenter() { } private Host createHost(final long id, final int pes) { - final var peList = new ArrayList(pes); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < pes; i++) { - //Uses a PeProvisionerSimple by default to provision PEs for VMs - peList.add(new PeSimple(HOST_MIPS)); - } + final var cpuCapacity = new CoreCapacity(pes, HOST_MIPS); //Host resources will be defined increasingly, according to the Host id. final long ram = BASE_HOST_RAM * id; //in Megabytes @@ -147,7 +148,7 @@ private Host createHost(final long id, final int pes) { Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - final Host host = new HostSimple(ram, bw, storage, peList); + final Host host = new HostSimple(ram, bw, storage, cpuCapacity); host.setId(id); return host; } @@ -167,7 +168,7 @@ private List createVms() { final var vmList = new ArrayList(VMS_BY_GROUP); for (int i = 0; i < VMS_BY_GROUP; i++) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final Vm vm = new VmSimple(HOST_MIPS, VM_PES); + final Vm vm = new VmSimple(VM_CAPACITY); vm.setRam(VM_RAM).setBw(VM_BW).setSize(VM_STORAGE); vmList.add(vm); } @@ -183,7 +184,7 @@ private void createCloudlets(final VmGroup group) { final var utilizationModelCpu = new UtilizationModelFull(); for (Vm vm : group.getVmList()) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, VM_PES); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, VM_CORES); cloudlet.setSizes(1024) .setUtilizationModelCpu(utilizationModelCpu) .setUtilizationModelRam(utilizationModelRamBw) diff --git a/src/main/java/org/cloudsimplus/examples/autoscaling/LoadBalancerByHorizontalVmScalingExample.java b/src/main/java/org/cloudsimplus/examples/autoscaling/LoadBalancerByHorizontalVmScalingExample.java index c7b8b17..a10e0bd 100755 --- a/src/main/java/org/cloudsimplus/examples/autoscaling/LoadBalancerByHorizontalVmScalingExample.java +++ b/src/main/java/org/cloudsimplus/examples/autoscaling/LoadBalancerByHorizontalVmScalingExample.java @@ -41,8 +41,7 @@ import org.cloudsimplus.listeners.EventInfo; import org.cloudsimplus.listeners.EventListener; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -104,7 +103,15 @@ public class LoadBalancerByHorizontalVmScalingExample { private static final int CLOUDLETS_CREATION_INTERVAL = SCHEDULING_INTERVAL * 2; private static final int HOSTS = 50; - private static final int HOST_PES = 32; + private static final int HOST_CORES = 32; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); + private static final int VMS = 4; private static final int CLOUDLETS = 6; private final CloudSimPlus simulation; @@ -116,6 +123,14 @@ public class LoadBalancerByHorizontalVmScalingExample { /// Different lengths that will be randomly assigned to created Cloudlets. private static final long[] CLOUDLET_LENGTHS = {2000, 4000, 10000, 16000, 2000, 30000, 20000}; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(2, 1000); + private final ContinuousDistribution rand; private int createdCloudlets; @@ -211,15 +226,10 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; // in Megabytes final long storage = 1000000; // in Megabytes final long bw = 10000; //in Megabits/s - return new HostSimple(ram, bw, storage, peList) + return new HostSimple(ram, bw, storage, HOST_CAPACITY) .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) .setVmScheduler(new VmSchedulerTimeShared()); @@ -270,7 +280,7 @@ private boolean isVmOverloaded(final Vm vm) { /// @return the created Vm private Vm createVm() { final int id = createsVms++; - return new VmSimple(id, 1000, 2) + return new VmSimple(id, VM_CAPACITY) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); } diff --git a/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingDynamicThreshold.java b/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingDynamicThreshold.java index e121948..bdea028 100755 --- a/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingDynamicThreshold.java +++ b/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingDynamicThreshold.java @@ -43,8 +43,7 @@ import org.cloudsimplus.listeners.EventInfo; import org.cloudsimplus.listeners.EventListener; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.resources.Processor; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; @@ -97,9 +96,25 @@ public class VerticalVmCpuScalingDynamicThreshold { private static final int SCHEDULING_INTERVAL = 1; private static final int HOSTS = 1; - private static final int HOST_PES = 32; + private static final int HOST_CORES = 32; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); + private static final int VMS = 1; - private static final int VM_PES = 14; + private static final int VM_CORES = 14; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); + private static final int VM_RAM = 1200; private final CloudSimPlus simulation; private final DatacenterBroker broker0; @@ -150,9 +165,9 @@ private void onClockTickListener(EventInfo evt) { System.out.printf( "\t\tTime %6.1f: Vm %d CPU Usage: %6.2f%% (%2d vCPUs. Running Cloudlets: #%02d) Upper Threshold: %.2f%n", evt.getTime(), vm.getId(), vm.getCpuPercentUtilization()*100.0, - vm.getPesNumber(), + vm.getProcessor().getCores(), vm.getCloudletScheduler().getCloudletExecList().size(), - vm.getPeVerticalScaling().getUpperThresholdFunction().apply(vm)); + vm.getCpuVerticalScaling().getUpperThresholdFunction().apply(vm)); }); } @@ -176,16 +191,11 @@ private void createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 20000; //in Megabytes final long bw = 100000; //in Megabytes final long storage = 10000000; //in Megabytes final int id = hostList.size(); - return new HostSimple(ram, bw, storage, peList) + return new HostSimple(ram, bw, storage, HOST_CAPACITY) .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) .setVmScheduler(new VmSchedulerTimeShared()); @@ -201,7 +211,7 @@ private List createListOfScalableVms(final int numberOfVms) { List newList = new ArrayList<>(numberOfVms); for (int i = 0; i < numberOfVms; i++) { final var vm = createVm(); - vm.setPeVerticalScaling(createVerticalPeScaling()); + vm.setCpuVerticalScaling(createVerticalPeScaling()); newList.add(vm); } @@ -216,7 +226,7 @@ private List createListOfScalableVms(final int numberOfVms) { private Vm createVm() { final int id = createsVms++; - final Vm vm = new VmSimple(id, 1000, VM_PES) + final Vm vm = new VmSimple(id, VM_CAPACITY) .setRam(VM_RAM).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); return vm; diff --git a/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingExample.java b/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingExample.java index d268bf5..900574a 100755 --- a/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingExample.java +++ b/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmCpuScalingExample.java @@ -42,8 +42,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.EventInfo; import org.cloudsimplus.listeners.EventListener; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.resources.Processor; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -91,11 +90,27 @@ public class VerticalVmCpuScalingExample { private static final int SCHEDULING_INTERVAL = 1; private static final int HOSTS = 1; - private static final int HOST_PES = 64; + private static final int HOST_CORES = 64; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); + private static final int VMS = 1; - private static final int VM_PES = 14; + private static final int VM_CORES = 14; private static final int VM_RAM = 1200; private static final int VM_MIPS = 1000; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, VM_MIPS); + private final CloudSimPlus simulation; private final DatacenterBroker broker0; private List hostList; @@ -146,7 +161,7 @@ private void onClockTickListener(EventInfo evt) { vmList.forEach(vm -> System.out.printf( "\t\tTime %6.1f: Vm %d CPU Usage: %6.2f%% (%2d vCPUs. Running Cloudlets: #%d). RAM usage: %.2f%% (%d MB)%n", - evt.getTime(), vm.getId(), vm.getCpuPercentUtilization()*100.0, vm.getPesNumber(), + evt.getTime(), vm.getId(), vm.getCpuPercentUtilization()*100.0, vm.getProcessor().getCores(), vm.getCloudletScheduler().getCloudletExecList().size(), vm.getRam().getPercentUtilization()*100, vm.getRam().getAllocatedResource()) ); @@ -171,15 +186,10 @@ private void createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 20000; //in Megabytes final long bw = 100000; //in Megabytes final long storage = 10000000; //in Megabytes - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerTimeShared()); + return new HostSimple(ram, bw, storage, HOST_CAPACITY).setVmScheduler(new VmSchedulerTimeShared()); } /// Creates a list of initial VMs in which each VM is able to scale vertically @@ -192,7 +202,7 @@ private List createListOfScalableVms(final int vmsNumber) { final var newVmList = new ArrayList(vmsNumber); for (int i = 0; i < vmsNumber; i++) { final var vm = createVm(); - vm.setPeVerticalScaling(createVerticalPeScaling()); + vm.setCpuVerticalScaling(createVerticalPeScaling()); newVmList.add(vm); } @@ -202,7 +212,7 @@ private List createListOfScalableVms(final int vmsNumber) { private Vm createVm() { final int id = createsVms++; - return new VmSimple(id, VM_MIPS, VM_PES).setRam(VM_RAM).setBw(1000).setSize(10000); + return new VmSimple(id, VM_CAPACITY).setRam(VM_RAM).setBw(1000).setSize(10000); } /// Creates a [VerticalVmScaling] for scaling VM's CPU when it is under or overloaded. diff --git a/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmRamScalingExample.java b/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmRamScalingExample.java index dcdd218..516c265 100755 --- a/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmRamScalingExample.java +++ b/src/main/java/org/cloudsimplus/examples/autoscaling/VerticalVmRamScalingExample.java @@ -39,8 +39,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.EventInfo; import org.cloudsimplus.listeners.EventListener; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.resources.Ram; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModel; @@ -95,19 +94,34 @@ public class VerticalVmRamScalingExample { private static final int SCHEDULING_INTERVAL = 1; private static final int HOSTS = 1; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; /// Host RAM capacity in Megabytes. private static final long HOST_RAM = 20000; private static final int HOST_MIPS = 1000; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + private static final int VMS = 1; /// Vm RAM capacity in Megabytes. private static final int VM_RAM = 1000; - private static final int VM_PES = 5; + private static final int VM_CORES = 5; private static final int VM_MIPS = 1000; + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, VM_MIPS); + /// The percentage (in scale from 0 to 1) to scale VM RAM capacity up/down /// when it becomes under/overloaded. /// @see #createVerticalRamScalingForVm(Vm) @@ -125,7 +139,7 @@ public class VerticalVmRamScalingExample { /// the VM resource usage will reduce when a Cloudlet finishes. private static final long[] CLOUDLET_LENGTHS = {40_000, 50_000, 60_000, 70_000, 80_000}; - private static final int CLOUDLET_PES = 1; + private static final int CLOUDLET_CORES = 1; private int createdCloudlets; private int createsVms; @@ -193,14 +207,9 @@ private void createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(HOST_MIPS)); - } - final long bw = 100000; //in Megabytes final long storage = 10000000; //in Megabytes - return new HostSimple(HOST_RAM, bw, storage, peList).setVmScheduler(new VmSchedulerTimeShared()); + return new HostSimple(HOST_RAM, bw, storage, HOST_CAPACITY).setVmScheduler(new VmSchedulerTimeShared()); } /// Creates a list of initial VMs in which each one is able to scale horizontally @@ -223,7 +232,7 @@ private List createListOfScalableVms(final int vmsNumber) { private Vm createVm() { final int id = createsVms++; - return new VmSimple(id, VM_MIPS, VM_PES) + return new VmSimple(id, VM_CAPACITY) .setRam(VM_RAM).setBw(1000).setSize(10000); } @@ -300,7 +309,7 @@ private void createCloudletList() { private Cloudlet createCloudlet(final UtilizationModel ramUtilizationModel, final long length) { final int id = createdCloudlets++; final double initialBwUtilizationPercent = 0.1; - return new CloudletSimple(id, length, CLOUDLET_PES) + return new CloudletSimple(id, length, CLOUDLET_CORES) .setUtilizationModelCpu(new UtilizationModelFull()) .setUtilizationModelBw(new UtilizationModelDynamic(initialBwUtilizationPercent)) .setUtilizationModelRam(ramUtilizationModel); diff --git a/src/main/java/org/cloudsimplus/examples/brokers/BrokerTargetDatacenterExample.java b/src/main/java/org/cloudsimplus/examples/brokers/BrokerTargetDatacenterExample.java index 67a34ba..2dc83f9 100755 --- a/src/main/java/org/cloudsimplus/examples/brokers/BrokerTargetDatacenterExample.java +++ b/src/main/java/org/cloudsimplus/examples/brokers/BrokerTargetDatacenterExample.java @@ -33,8 +33,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; @@ -58,12 +57,26 @@ public class BrokerTargetDatacenterExample { private static final int DATACENTERS = 3; private static final int HOSTS_BY_DC = 5; - private static final int HOST_PES = 6; + private static final int HOST_CORES = 6; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int BASE_VM_NUMBER = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10_000; private final CloudSimPlus simulation; @@ -87,7 +100,6 @@ private BrokerTargetDatacenterExample() { datacenterList = createDatacenters(); createBrokersVmsAndCloudlets(); - simulation.start(); brokerList.forEach(BrokerTargetDatacenterExample::createCloudletsResultTable); @@ -146,11 +158,6 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes @@ -159,7 +166,7 @@ private Host createHost() { Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - final Host host = new HostSimple(ram, bw, storage, peList); + final Host host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setId(lastHostId++); return host; } @@ -169,7 +176,7 @@ private List createVms(final int vmsNumber) { final var vms = new ArrayList(vmsNumber); for (int i = 0; i < vmsNumber; i++) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final Vm vm = new VmSimple(lastVmId++, 1000, VM_PES); + final Vm vm = new VmSimple(lastVmId++, VM_CAPACITY); vm.setRam(512).setBw(1000).setSize(10000); vms.add(vm); } @@ -185,7 +192,7 @@ private List createCloudlets(int cloudletsNumber) { final var utilizationModel = new UtilizationModelDynamic(0.5); for (int i = 0; i < cloudletsNumber; i++) { - final var cloudlet = new CloudletSimple(lastCloudletId++, CLOUDLET_LENGTH, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(lastCloudletId++, CLOUDLET_LENGTH, CLOUDLET_CORES); cloudlet.setUtilizationModel(utilizationModel); cloudlets.add(cloudlet); } diff --git a/src/main/java/org/cloudsimplus/examples/brokers/CloudletToVmMappingBestFit.java b/src/main/java/org/cloudsimplus/examples/brokers/CloudletToVmMappingBestFit.java index e3d2024..9468bbc 100755 --- a/src/main/java/org/cloudsimplus/examples/brokers/CloudletToVmMappingBestFit.java +++ b/src/main/java/org/cloudsimplus/examples/brokers/CloudletToVmMappingBestFit.java @@ -33,8 +33,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -60,7 +59,14 @@ /// @since CloudSim Plus 1.3.0 public class CloudletToVmMappingBestFit { private static final int HOSTS = 2; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 4; @@ -113,17 +119,11 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes final var vmScheduler = new VmSchedulerTimeShared(); - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setVmScheduler(vmScheduler); return host; } @@ -135,7 +135,7 @@ private List createVms() { final var vmList = new ArrayList(VMS); for (int i = VMS-1; i >= 0; i--) { final Vm vm = - new VmSimple(1000, i+1) + new VmSimple(new CoreCapacity(i+1, 1000)) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); diff --git a/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokerBatchVmCreationRequestExample.java b/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokerBatchVmCreationRequestExample.java index 7d2d94d..13e9e58 100755 --- a/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokerBatchVmCreationRequestExample.java +++ b/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokerBatchVmCreationRequestExample.java @@ -36,8 +36,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.EventInfo; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.selectionpolicies.VmSelectionPolicyMinimumUtilization; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.vms.Vm; @@ -59,16 +58,31 @@ /// @since CloudSim Plus 8.5.0 public class DatacenterBrokerBatchVmCreationRequestExample { private static final int HOSTS = 2; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; private static final int HOST_MIPS = 1000; // Million Instructions per Second (MIPS) + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + private static final int HOST_RAM = 2048; //in Megabytes private static final long HOST_BW = 10_000; //in Megabits/s private static final long HOST_STORAGE = 1_000_000; //in Megabytes private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, HOST_MIPS); - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10_000; // Million Instructions (MI) private final CloudSimPlus simulation; @@ -153,25 +167,18 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - //Uses a PeProvisionerSimple by default to provision PEs for VMs - peList.add(new PeSimple(HOST_MIPS)); - } - /* Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList); + return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY); } private ArrayList createAndSubmitVms() { final var newVms = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final var vm = new VmSimple(HOST_MIPS, VM_PES); + final var vm = new VmSimple(VM_CAPACITY); vm.setRam(512).setBw(1000).setSize(10_000); newVms.add(vm); } @@ -188,7 +195,7 @@ private List createAndSubmitCloudlets(final List vms) { final var utilizationModel = new UtilizationModelDynamic(0.5); for (final var vm : vms) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES, utilizationModel); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES, utilizationModel); cloudlet.setSizes(1024); broker0.bindCloudletToVm(cloudlet, vm); newCloulets.add(cloudlet); diff --git a/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokerHeuristicExample.java b/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokerHeuristicExample.java index a44daba..4e9bb48 100755 --- a/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokerHeuristicExample.java +++ b/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokerHeuristicExample.java @@ -39,8 +39,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.util.Log; @@ -56,7 +55,7 @@ /// An example that uses a /// [Simulated Annealing](http://en.wikipedia.org/wiki/Simulated_annealing) /// heuristic to find a suboptimal mapping between Cloudlets and Vm's submitted to a -/// DatacenterBroker. The number of [Pe]s of Vm's and Cloudlets are defined +/// DatacenterBroker. The number of CPU cores of Vm's and Cloudlets are defined /// randomly. /// /// The [DatacenterBrokerHeuristic] is used @@ -192,13 +191,10 @@ private Host createHost() { final long storage = 1000000; // host storage final long bw = 10000; - final var peList = new ArrayList(); - /*Creates the Host's CPU cores and defines the provisioner - used to allocate each core for requesting VMs.*/ - for(int i = 0; i < 8; i++) - peList.add(new PeSimple(mips)); + //Defines the number of Host CPU cores and the MIPS capacity of each core + final var cpuCapacity = new CoreCapacity(8, mips); - return new HostSimple(ram, bw, storage, peList) + return new HostSimple(ram, bw, storage, cpuCapacity) .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) .setVmScheduler(new VmSchedulerTimeShared()); @@ -210,7 +206,7 @@ private Vm createVm(final DatacenterBroker broker, final int pesNumber) { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; // vm bandwidth - return new VmSimple(createdVms++, mips, pesNumber) + return new VmSimple(createdVms++, new CoreCapacity(pesNumber, mips)) .setRam(ram).setBw(bw).setSize(storage) .setCloudletScheduler(new CloudletSchedulerTimeShared()); } @@ -260,9 +256,9 @@ private void printSolution( System.out.printf( "Cloudlet %3d (%d PEs, %6d MI) mapped to Vm %3d (%d PEs, %6.0f MIPS)%n", e.getKey().getId(), - e.getKey().getPesNumber(), e.getKey().getLength(), + e.getKey().getRequiredCores(), e.getKey().getLength(), e.getValue().getId(), - e.getValue().getPesNumber(), e.getValue().getMips()); + e.getValue().getProcessor().getCores(), e.getValue().getProcessor().getMips()); } System.out.println(); diff --git a/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokersMappingComparison.java b/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokersMappingComparison.java index 46b9c55..53a18fd 100755 --- a/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokersMappingComparison.java +++ b/src/main/java/org/cloudsimplus/examples/brokers/DatacenterBrokersMappingComparison.java @@ -44,8 +44,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.util.Log; @@ -63,7 +62,7 @@ /// An example that uses a /// [Simulated Annealing](http://en.wikipedia.org/wiki/Simulated_annealing) /// heuristic to find a suboptimal mapping between Cloudlets and Vm's submitted to a -/// DatacenterBroker. The number of [Pe]s of Vm's and Cloudlets are defined +/// DatacenterBroker. The number of CPU cores of Vm's and Cloudlets are defined /// randomly. /// /// The [DatacenterBrokerHeuristic] is used @@ -218,13 +217,10 @@ private Host createHost() { final long storage = 1000000; // host storage final long bw = 10000; - final var peList = new ArrayList(); - /*Creates the Host's CPU cores and defines the provisioner - used to allocate each core for requesting VMs.*/ - for (int i = 0; i < 8; i++) - peList.add(new PeSimple(mips)); + //Defines the number of Host CPU cores and the MIPS capacity of each core + final var cpuCapacity = new CoreCapacity(8, mips); - return new HostSimple(ram, bw, storage, peList) + return new HostSimple(ram, bw, storage, cpuCapacity) .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) .setVmScheduler(new VmSchedulerTimeShared()); @@ -236,7 +232,7 @@ private Vm createVm(final long id, final int pesNumber) { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; // vm bandwidth - return new VmSimple(id, mips, pesNumber) + return new VmSimple(id, new CoreCapacity(pesNumber, mips)) .setRam(ram).setBw(bw).setSize(storage) .setCloudletScheduler(new CloudletSchedulerTimeShared()); } @@ -290,9 +286,9 @@ private void printSolution( System.out.printf( "Cloudlet %3d (%d PEs, %6d MI) mapped to Vm %3d (%d PEs, %6.0f MIPS)%n", e.getKey().getId(), - e.getKey().getPesNumber(), e.getKey().getLength(), + e.getKey().getRequiredCores(), e.getKey().getLength(), e.getValue().getId(), - e.getValue().getPesNumber(), e.getValue().getMips()); + e.getValue().getProcessor().getCores(), e.getValue().getProcessor().getMips()); } System.out.println(); diff --git a/src/main/java/org/cloudsimplus/examples/brokers/DatacenterSelectionByTimeZoneExample.java b/src/main/java/org/cloudsimplus/examples/brokers/DatacenterSelectionByTimeZoneExample.java index 37cc399..eff86e3 100755 --- a/src/main/java/org/cloudsimplus/examples/brokers/DatacenterSelectionByTimeZoneExample.java +++ b/src/main/java/org/cloudsimplus/examples/brokers/DatacenterSelectionByTimeZoneExample.java @@ -36,8 +36,7 @@ import org.cloudsimplus.datacenters.TimeZoned; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.util.Log; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.vms.Vm; @@ -76,17 +75,31 @@ public class DatacenterSelectionByTimeZoneExample { ); private static final int HOSTS = 5; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); /// The list of timezones where each VM is expected to be placed. /// This way, the broker will try to place each VM at the closest /// Datacenter as possible. private static final double[] VMS_TIMEZONES = {1, 5, -3, -5, 0, 5.5, 2, 4, 9, 11, -9}; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = VMS_TIMEZONES.length; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -168,13 +181,6 @@ private Datacenter createDatacenter(final double timeZone) { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - //Uses a PeProvisionerSimple by default to provision PEs for VMs - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes @@ -183,7 +189,7 @@ private Host createHost() { Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setId(++lastHostId); return host; } @@ -195,7 +201,7 @@ private List createVms() { final var vmList = new ArrayList(VMS_TIMEZONES.length); for (final double timezone : VMS_TIMEZONES) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final Vm vm = new VmSimple(1000, VM_PES); + final Vm vm = new VmSimple(VM_CAPACITY); vm.setRam(512).setBw(1000).setSize(10000).setTimeZone(timezone); vmList.add(vm); } @@ -211,7 +217,7 @@ private List createCloudlets() { final var utilizationModel = new UtilizationModelDynamic(0.5); for (int i = 0; i < CLOUDLETS; i++) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES, utilizationModel); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES, utilizationModel); cloudlet.setSizes(1024); cloudletList.add(cloudlet); } diff --git a/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers1.java b/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers1.java index 7e871d5..9bc32c7 100755 --- a/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers1.java +++ b/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers1.java @@ -34,8 +34,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -72,15 +71,29 @@ public class MultipleBrokers1 { /// @see Datacenter#getSchedulingInterval() private static final int SCHEDULING_INTERVAL = 5; private static final int HOSTS = 2; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int BROKERS = 2; private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = 2; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -175,19 +188,13 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes final var ramProvisioner = new ResourceProvisionerSimple(); final var bwProvisioner = new ResourceProvisionerSimple(); final var vmScheduler = new VmSchedulerTimeShared(); - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host .setRamProvisioner(ramProvisioner) .setBwProvisioner(bwProvisioner) @@ -200,7 +207,7 @@ private List createAndSubmitVms(DatacenterBroker broker) { final var vmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { final Vm vm = - new VmSimple(this.vmList.size()+i, 1000, VM_PES) + new VmSimple(this.vmList.size()+i, VM_CAPACITY) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -227,7 +234,7 @@ private List createAndSubmitCloudlets(DatacenterBroker broker, final i private Cloudlet createCloudlet(final int id, final int length) { final var utilization = new UtilizationModelFull(); - final var cloudlet = new CloudletSimple(id, length, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(id, length, CLOUDLET_CORES); cloudlet .setFileSize(1024) .setOutputSize(1024) diff --git a/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers2.java b/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers2.java index fa61b81..caa6a56 100755 --- a/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers2.java +++ b/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers2.java @@ -36,8 +36,7 @@ import org.cloudsimplus.listeners.EventInfo; import org.cloudsimplus.listeners.EventListener; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -75,15 +74,29 @@ public class MultipleBrokers2 { /// @see Datacenter#getSchedulingInterval() private static final int SCHEDULING_INTERVAL = 5; private static final int HOSTS = 2; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int BROKERS = 2; private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = 2; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -229,19 +242,13 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes final var ramProvisioner = new ResourceProvisionerSimple(); final var bwProvisioner = new ResourceProvisionerSimple(); final var vmScheduler = new VmSchedulerTimeShared(); - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host .setRamProvisioner(ramProvisioner) .setBwProvisioner(bwProvisioner) @@ -254,7 +261,7 @@ private List createAndSubmitVms(DatacenterBroker broker) { final var vmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { final var vm = - new VmSimple(this.vmList.size()+i, 1000, VM_PES) + new VmSimple(this.vmList.size()+i, VM_CAPACITY) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -281,7 +288,7 @@ private List createAndSubmitCloudlets(DatacenterBroker broker, final i private Cloudlet createCloudlet(final int id, final int length) { final var utilization = new UtilizationModelFull(); - final var cloudlet = new CloudletSimple(id, length, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(id, length, CLOUDLET_CORES); cloudlet .setFileSize(1024) .setOutputSize(1024) diff --git a/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers3.java b/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers3.java index a0209b6..bbb0e90 100755 --- a/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers3.java +++ b/src/main/java/org/cloudsimplus/examples/brokers/MultipleBrokers3.java @@ -34,8 +34,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -54,15 +53,29 @@ /// @since CloudSim Plus 1.3.1 public class MultipleBrokers3 { private static final int HOSTS = 2; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int BROKERS = 2; private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = 2; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -136,15 +149,10 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) @@ -156,7 +164,7 @@ private List createAndSubmitVms(DatacenterBroker broker) { final var vmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { final var vm = - new VmSimple(1000, VM_PES) + new VmSimple(VM_CAPACITY) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -172,7 +180,7 @@ private List createAndSubmitCloudlets(DatacenterBroker broker) { final var cloudletList = new ArrayList(CLOUDLETS); for (int i = 1; i <= CLOUDLETS; i++) { final var utilizationModel = new UtilizationModelFull(); - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES); cloudlet .setFileSize(1024) .setOutputSize(1024) diff --git a/src/main/java/org/cloudsimplus/examples/brokers/SelectNextDatacenterExample.java b/src/main/java/org/cloudsimplus/examples/brokers/SelectNextDatacenterExample.java index 07dbe9c..b6ab445 100755 --- a/src/main/java/org/cloudsimplus/examples/brokers/SelectNextDatacenterExample.java +++ b/src/main/java/org/cloudsimplus/examples/brokers/SelectNextDatacenterExample.java @@ -33,8 +33,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; @@ -58,10 +57,17 @@ public class SelectNextDatacenterExample { private static final int HOSTS = 5; private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = 4; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -123,12 +129,7 @@ private Datacenter createDatacenter(final int hostsPes) { } private Host createHost(final int pes) { - final var peList = new ArrayList(pes); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < pes; i++) { - //Uses a PeProvisionerSimple by default to provision PEs for VMs - peList.add(new PeSimple(1000)); - } + final var cpuCapacity = new CoreCapacity(pes, 1000); final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s @@ -138,7 +139,7 @@ private Host createHost(final int pes) { Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, cpuCapacity); host.setId(++lastHostId); return host; } @@ -148,7 +149,7 @@ private List createVms() { final var vmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final Vm vm = new VmSimple(1000, VM_PES); + final Vm vm = new VmSimple(VM_CAPACITY); vm.setRam(512).setBw(1000).setSize(10000); vmList.add(vm); } @@ -164,7 +165,7 @@ private List createCloudlets() { final var utilizationModel = new UtilizationModelDynamic(0.5); for (int i = 0; i < CLOUDLETS; i++) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES, utilizationModel); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES, utilizationModel); cloudlet.setSizes(1024); cloudletList.add(cloudlet); } diff --git a/src/main/java/org/cloudsimplus/examples/costs/CostsExample1.java b/src/main/java/org/cloudsimplus/examples/costs/CostsExample1.java index 4efe13e..711fffc 100755 --- a/src/main/java/org/cloudsimplus/examples/costs/CostsExample1.java +++ b/src/main/java/org/cloudsimplus/examples/costs/CostsExample1.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmCost; @@ -58,17 +57,32 @@ public class CostsExample1 { private static final int SCHEDULING_INTERVAL = 1; private static final int HOSTS = 4; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; private static final int HOST_MIPS = 1000; + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + private static final int VMS = 6; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, HOST_MIPS); + private static final int VM_RAM = 512; private static final int VM_BW = 1000; private static final int VM_SIZE = 10000; private static final int CLOUDLET_BY_VM = 2; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 100_000; private final CloudSimPlus simulation; @@ -138,13 +152,6 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - //Uses a PeProvisionerSimple by default to provision PEs for VMs - peList.add(new PeSimple(HOST_MIPS)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes @@ -153,7 +160,7 @@ private Host createHost() { Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - return new HostSimple(ram, bw, storage, peList); + return new HostSimple(ram, bw, storage, HOST_CAPACITY); } /// Creates a list of VMs. @@ -161,7 +168,7 @@ private List createVms() { final var vmList = new ArrayList(VMS); for (int id = 0; id < VMS; id++) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final Vm vm = new VmSimple(id, HOST_MIPS, VM_PES); + final Vm vm = new VmSimple(id, VM_CAPACITY); vm.setRam(VM_RAM).setBw(VM_BW).setSize(VM_SIZE); vmList.add(vm); } @@ -180,7 +187,7 @@ private List createCloudlets() { for (int i = 1; i <= VMS/3; i++) { final Vm vm = vmList.get(i-1); for (int j = 0; j < CLOUDLET_BY_VM; j++) { - final var cloudlet = new CloudletSimple(cloudletId, (cloudletId+1) * CLOUDLET_LENGTH, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(cloudletId, (cloudletId+1) * CLOUDLET_LENGTH, CLOUDLET_CORES); cloudlet.setSizes(1024).setUtilizationModel(utilizationModel); cloudlet.setVm(vm); newCloudletList.add(cloudlet); diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/CreateCloudletAfterLastFinishedOne.java b/src/main/java/org/cloudsimplus/examples/dynamic/CreateCloudletAfterLastFinishedOne.java index 5a40123..e800c9b 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/CreateCloudletAfterLastFinishedOne.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/CreateCloudletAfterLastFinishedOne.java @@ -36,8 +36,7 @@ import org.cloudsimplus.listeners.CloudletVmEventInfo; import org.cloudsimplus.listeners.EventListener; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerSpaceShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -124,7 +123,7 @@ private List createAndSubmitVms() { private Vm createVm() { final int mips = 1000; - return new VmSimple(mips, VM_PES_NUMBER) + return new VmSimple(new CoreCapacity(VM_PES_NUMBER, mips)) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); } @@ -175,16 +174,13 @@ private Datacenter createDatacenter() { /// @param id The Host id /// @return the created host private Host createHost(int id) { - final var peList = new ArrayList(); long mips = 1000; - for(int i = 0; i < HOST_PES_NUMBER; i++){ - peList.add(new PeSimple(mips)); - } + final var cpuCapacity = new CoreCapacity(HOST_PES_NUMBER, mips); long ram = 2048; // host memory (Megabyte) long storage = 1000000; // host storage (Megabyte) long bw = 10000; //Megabits/s - return new HostSimple(ram, bw, storage, peList) + return new HostSimple(ram, bw, storage, cpuCapacity) .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) .setVmScheduler(new VmSchedulerSpaceShared()); diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCloudletsArrival1.java b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCloudletsArrival1.java index de118bc..8c82d90 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCloudletsArrival1.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCloudletsArrival1.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerSpaceShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -161,7 +160,7 @@ private Vm createVm() { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; - return new VmSimple(mips, VM_PES_NUMBER) + return new VmSimple(new CoreCapacity(VM_PES_NUMBER, mips)) .setRam(ram).setBw(bw).setSize(size) .setCloudletScheduler(new CloudletSchedulerTimeShared()); } @@ -203,16 +202,13 @@ private Datacenter createDatacenter() { /// @param id The Host id /// @return the created host private Host createHost(int id) { - final var peList = new ArrayList(); final long mips = 1000; - for(int i = 0; i < HOST_PES_NUMBER; i++){ - peList.add(new PeSimple(mips)); - } + final var cpuCapacity = new CoreCapacity(HOST_PES_NUMBER, mips); final long ram = 2048; // host memory (Megabyte) final long storage = 1000000; // host storage (Megabyte) final long bw = 10000; //Megabits/s - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerSpaceShared()); + return new HostSimple(ram, bw, storage, cpuCapacity).setVmScheduler(new VmSchedulerSpaceShared()); } } diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCloudletsArrival2.java b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCloudletsArrival2.java index 760b698..e906b19 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCloudletsArrival2.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCloudletsArrival2.java @@ -33,8 +33,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerSpaceShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -158,7 +157,7 @@ private Vm createVm(int id, DatacenterBroker broker) { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; - return new VmSimple(id, mips, VM_PES_NUMBER) + return new VmSimple(id, new CoreCapacity(VM_PES_NUMBER, mips)) .setRam(ram).setBw(bw).setSize(size) .setCloudletScheduler(new CloudletSchedulerTimeShared()); } @@ -199,17 +198,14 @@ private Datacenter createDatacenter() { /// @param id The Host id /// @return the created host private Host createHost(int id) { - final var peList = new ArrayList(); final long mips = 1000; - for(int i = 0; i < HOST_PES_NUMBER; i++){ - peList.add(new PeSimple(mips)); - } + final var cpuCapacity = new CoreCapacity(HOST_PES_NUMBER, mips); final long ram = 2048; // in Megabytes final long storage = 1000000; // in Megabytes final long bw = 10000; //in Megabits/s - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerSpaceShared()); + return new HostSimple(ram, bw, storage, cpuCapacity).setVmScheduler(new VmSchedulerSpaceShared()); } } diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCreationOfVmsAndCloudletsExample.java b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCreationOfVmsAndCloudletsExample.java index 0dc4ce8..22aedf4 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCreationOfVmsAndCloudletsExample.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicCreationOfVmsAndCloudletsExample.java @@ -34,8 +34,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.CloudletVmEventInfo; import org.cloudsimplus.listeners.EventListener; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerSpaceShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -160,12 +159,9 @@ private Host createHost() { final long bw = 10000; //in Megabits/s final int pesNumber = 8; - final var peList = new ArrayList(pesNumber); //List of CPU cores - for (int i = 0; i < pesNumber; i++) { - peList.add(new PeSimple(mips)); - } + final var cpuCapacity = new CoreCapacity(pesNumber, mips); - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerTimeShared()); + return new HostSimple(ram, bw, storage, cpuCapacity).setVmScheduler(new VmSchedulerTimeShared()); } private Vm createVm(DatacenterBroker broker) { @@ -175,7 +171,7 @@ private Vm createVm(DatacenterBroker broker) { final long bw = 1000; // vm bandwidth (Megabits/s) final int pesNumber = 1; // number of CPU cores - return new VmSimple(createVmsNumber++, mips, pesNumber) + return new VmSimple(createVmsNumber++, new CoreCapacity(pesNumber, mips)) .setRam(ram) .setBw(bw) .setSize(storage) @@ -186,7 +182,7 @@ private Cloudlet createCloudlet(DatacenterBroker broker, Vm vm) { final long length = 10000; //in Million Instructions (MI) final long fileSize = 300; //Size (in bytes) before execution final long outputSize = 300; //Size (in bytes) after execution - final long numberOfCpuCores = vm.getPesNumber(); //cloudlet will use all the VM's CPU cores + final long numberOfCpuCores = vm.getProcessor().getCores(); //cloudlet will use all the VM's CPU cores //Defines how CPU, RAM and Bandwidth resources are used //Sets the same utilization model for all these resources. diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicHostCreation.java b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicHostCreation.java index f773ad0..2d295bc 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicHostCreation.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicHostCreation.java @@ -36,8 +36,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.EventInfo; import org.cloudsimplus.listeners.EventListener; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -95,11 +94,25 @@ public class DynamicHostCreation { private static final int SCHEDULING_INTERVAL = 5; private static final int HOSTS = 2; - private static final int HOST_PES = 4; + private static final int HOST_CORES = 4; - private static final int VM_PES = 2; + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); - private static final int CLOUDLET_PES = 2; + private static final int VM_CORES = 2; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); + + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -178,17 +191,11 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes final var vmScheduler = new VmSchedulerTimeShared(); - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setVmScheduler(vmScheduler); return host; } @@ -204,7 +211,7 @@ private List createVms(final int count) { } private Vm createVm(final int id) { - return new VmSimple(id,1000, VM_PES) + return new VmSimple(id, VM_CAPACITY) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); } @@ -214,7 +221,7 @@ private List createCloudlets(final int count) { final var utilization = new UtilizationModelFull(); for (int i = 0; i < count; i++) { final var cloudlet = - new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES) + new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelCpu(new UtilizationModelFull()) diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicVmAllocationPolicyBestFitExample.java b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicVmAllocationPolicyBestFitExample.java index 83348f8..ce18f3f 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicVmAllocationPolicyBestFitExample.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicVmAllocationPolicyBestFitExample.java @@ -58,8 +58,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -118,7 +117,7 @@ public final class DynamicVmAllocationPolicyBestFitExample { private static final long VM_SIZE = 1000; //image size (MB) private static final int VM_RAM = 10000; //VM memory (MB) private static final double VM_BW = HOST_BW/(double)VMS; - private static final int VM_PES = 2; + private static final int VM_CORES = 2; private static final long CLOUDLET_LENGHT = 20000; private static final long CLOUDLET_FILESIZE = 300; @@ -172,7 +171,7 @@ private Optional bestFitHostSelectionPolicy(VmAllocationPolicy allocationP .getHostList() .stream() .filter(host -> host.isSuitableForVm(vm)) - .min(Comparator.comparingInt(Host::getFreePesNumber)); + .min(Comparator.comparingLong(host -> host.getProcessor().getFreeCores())); } public void createAndSubmitCloudlets(DatacenterBroker broker) { @@ -191,7 +190,7 @@ public void createAndSubmitCloudlets(DatacenterBroker broker) { /// @return the created Cloudlets public Cloudlet createCloudlet(Vm vm, DatacenterBroker broker) { final var cloudlet = - new CloudletSimple(CLOUDLET_LENGHT, (int)vm.getPesNumber()) + new CloudletSimple(CLOUDLET_LENGHT, (int)vm.getProcessor().getCores()) .setFileSize(CLOUDLET_FILESIZE) .setOutputSize(CLOUDLET_OUTPUTSIZE) .setUtilizationModel(new UtilizationModelFull()); @@ -202,7 +201,7 @@ public Cloudlet createCloudlet(Vm vm, DatacenterBroker broker) { public void createAndSubmitVms(DatacenterBroker broker) { final var newVmList = new ArrayList(VMS); for(int i = 0; i < VMS; i++){ - final var vm = createVm(VM_PES); + final var vm = createVm(VM_CORES); newVmList.add(vm); } @@ -211,7 +210,7 @@ public void createAndSubmitVms(DatacenterBroker broker) { } public Vm createVm(int pes) { - final var vm = new VmSimple(VM_MIPS, pes); + final var vm = new VmSimple(new CoreCapacity(pes, VM_MIPS)); vm .setRam(VM_RAM).setBw((long)VM_BW).setSize(VM_SIZE) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -235,7 +234,7 @@ private Datacenter createDatacenter() { final var dc = new DatacenterSimple(simulation, hostList, allocationPolicy); - hostList.forEach(host -> System.out.printf("#Created %s with %d PEs%n", host, host.getPesNumber())); + hostList.forEach(host -> System.out.printf("#Created %s with %d PEs%n", host, host.getProcessor().getCores())); System.out.println(); dc.setSchedulingInterval(SCHEDULE_INTERVAL); @@ -243,17 +242,10 @@ private Datacenter createDatacenter() { } public Host createHost(int pesNumber, long mipsByPe) { - final var peList = createPeList(pesNumber, mipsByPe); - final var host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList); + final var cpuCapacity = new CoreCapacity(pesNumber, mipsByPe); + final var host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, cpuCapacity); host.setVmScheduler(new VmSchedulerTimeShared()); return host; } - public List createPeList(int numberOfPEs, long mips) { - final var peList = new ArrayList(numberOfPEs); - for(int i = 0; i < numberOfPEs; i++) { - peList.add(new PeSimple(mips)); - } - return peList; - } } diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicVmsArrival.java b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicVmsArrival.java index d859c86..a381398 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicVmsArrival.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicVmsArrival.java @@ -33,8 +33,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; @@ -54,11 +53,18 @@ public class DynamicVmsArrival { private static final int HOSTS = 2; /// Number of Processor Elements (CPU Cores) of each Host. - private static final int HOST_PES = 2; + private static final int HOST_CORES = 2; private static final double HOST_MIPS = 1000; + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + /// Number of Processor Elements (CPU Cores) of each VM and cloudlet. - private static final int VM_PES = 1; + private static final int VM_CORES = 1; /// Number of VMs to create. /// If you try to increase this number without increases Hosts, @@ -70,7 +76,7 @@ public class DynamicVmsArrival { private static final int CLOUDLETS = VMS; /// The length of each Cloudlet in number of Million Instructions (MI) private static final int CLOUDLET_LENGTH = 10000; - private static final int CLOUDLET_PES = 1; + private static final int CLOUDLET_CORES = 1; /// The time to wait before destroying a VM after it becomes idle (in seconds). public static final int IDLE_VM_DESTRUCTION_DELAY = 1; @@ -180,7 +186,7 @@ private Vm createVm(final double submissionDelay) { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; - final var vm = new VmSimple(mips, VM_PES); + final var vm = new VmSimple(new CoreCapacity(VM_CORES, mips)); vm.setRam(ram) .setBw(bw) .setSize(size) @@ -210,7 +216,7 @@ private Cloudlet createCloudlet(final Vm vm) { final var utilizationModelFull = new UtilizationModelFull(); final var utilizationModelDynamic = new UtilizationModelDynamic(0.2); - return new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES) + return new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES) .setUtilizationModelCpu(utilizationModelFull) .setUtilizationModelRam(utilizationModelDynamic) .setUtilizationModelBw(utilizationModelDynamic) @@ -232,14 +238,10 @@ private Datacenter createDatacenter() { /// /// @return the created host private Host createHost() { - final var peList = new ArrayList(); - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(HOST_MIPS)); - } long ram = 2048; // host memory (Megabyte) long storage = 1000000; // host storage (Megabyte) long bw = 10000; //Megabits/s - return new HostSimple(ram, bw, storage, peList); + return new HostSimple(ram, bw, storage, HOST_CAPACITY); } } diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicVmsArrival2.java b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicVmsArrival2.java index 4f43711..c1516d1 100644 --- a/src/main/java/org/cloudsimplus/examples/dynamic/DynamicVmsArrival2.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/DynamicVmsArrival2.java @@ -33,8 +33,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; import org.cloudsimplus.vms.VmSimple; @@ -149,7 +148,7 @@ private Vm createVm(final int id) { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; - return new VmSimple(id, mips, VM_PES_NUMBER).setRam(ram).setBw(bw).setSize(size); + return new VmSimple(id, new CoreCapacity(VM_PES_NUMBER, mips)).setRam(ram).setBw(bw).setSize(size); } /// Creates a cloudlet with pre-defined configuration. @@ -186,15 +185,12 @@ private Datacenter createDatacenter() { /// /// @return the created host private Host createHost() { - final var peList = new ArrayList(); final long mips = 1000; - for(int i = 0; i < HOST_PES_NUMBER; i++){ - peList.add(new PeSimple(mips)); - } + final var cpuCapacity = new CoreCapacity(HOST_PES_NUMBER, mips); final long ram = 2048; // in Megabytes final long storage = 1000000; // in Megabytes final long bw = 10000; //in Megabits/s - return new HostSimple(ram, bw, storage, peList); + return new HostSimple(ram, bw, storage, cpuCapacity); } } diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/IndefiniteLengthCloudlet.java b/src/main/java/org/cloudsimplus/examples/dynamic/IndefiniteLengthCloudlet.java index f12b388..9f0e500 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/IndefiniteLengthCloudlet.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/IndefiniteLengthCloudlet.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -63,14 +62,28 @@ /// @since CloudSim Plus 4.0.0 public class IndefiniteLengthCloudlet { private static final int HOSTS = 1; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; private static final int VM_MIPS = 1000; + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, VM_MIPS); + private static final int CLOUDLETS = 2; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; /// Defines a negative length for Cloudlets so that /// they keep running until explicitly requested to finish. @@ -128,16 +141,10 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setVmScheduler(new VmSchedulerTimeShared()); return host; } @@ -147,7 +154,7 @@ private List createVms() { final var newVmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { final var vm = - new VmSimple(i, VM_MIPS, VM_PES) + new VmSimple(i, VM_CAPACITY) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -167,7 +174,7 @@ private List createCloudlets() { for (int i = 0; i < CLOUDLETS; i++) { final var cloudlet = - new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES) + new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelCpu(utilizationFull) diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/KeepSimulationRunningExample.java b/src/main/java/org/cloudsimplus/examples/dynamic/KeepSimulationRunningExample.java index a940fc2..ac07150 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/KeepSimulationRunningExample.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/KeepSimulationRunningExample.java @@ -37,8 +37,7 @@ import org.cloudsimplus.listeners.EventInfo; import org.cloudsimplus.listeners.EventListener; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -98,13 +97,20 @@ public class KeepSimulationRunningExample { private static final int SCHEDULING_INTERVAL = 1; private static final int HOSTS = 3; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; private static final int CLOUDLETS = 4; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -160,16 +166,10 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) @@ -180,12 +180,12 @@ private Host createHost() { /// Creates a list of VMs. private void createVms() { for (int i = 0; i < VMS; i++) { - vmList.add(createVm(VM_PES)); + vmList.add(createVm(VM_CORES)); } } private Vm createVm(final int pes) { - return new VmSimple(1000, pes) + return new VmSimple(new CoreCapacity(pes, 1000)) .setRam(1000).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); } @@ -199,7 +199,7 @@ private void createCloudlets() { private Cloudlet createCloudlet() { final var um = new UtilizationModelDynamic(0.2); - return new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES) + return new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelCpu(new UtilizationModelFull()) @@ -212,7 +212,7 @@ private Cloudlet createCloudlet() { private void createDynamicCloudletAndVm(final EventInfo evt) { if((int)evt.getTime() == TIME_TO_CREATE_NEW_CLOUDLET){ System.out.printf("%n# Dynamically creating 1 Cloudlet and 1 VM at time %.2f%n", evt.getTime()); - final var vm = createVm(VM_PES*2); + final var vm = createVm(VM_CORES*2); vmList.add(vm); final var cloudlet = createCloudlet(); cloudletList.add(cloudlet); diff --git a/src/main/java/org/cloudsimplus/examples/dynamic/RandomCloudletsArrivalExample.java b/src/main/java/org/cloudsimplus/examples/dynamic/RandomCloudletsArrivalExample.java index 3b443da..93e6ee7 100755 --- a/src/main/java/org/cloudsimplus/examples/dynamic/RandomCloudletsArrivalExample.java +++ b/src/main/java/org/cloudsimplus/examples/dynamic/RandomCloudletsArrivalExample.java @@ -39,8 +39,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.EventInfo; import org.cloudsimplus.listeners.EventListener; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -90,12 +89,19 @@ public class RandomCloudletsArrivalExample { private static final int SCHEDULING_INTERVAL = 1; private static final int HOSTS = 8; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 10; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; /// Number of Cloudlets to be statically created when the simulation starts. private static final int INITIAL_CLOUDLETS_NUMBER = 5; @@ -156,16 +162,10 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setVmScheduler(new VmSchedulerTimeShared()); return host; } @@ -174,13 +174,13 @@ private Host createHost() { private List createVms() { final var newVmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { - newVmList.add(createVm(VM_PES)); + newVmList.add(createVm(VM_CORES)); } return newVmList; } private Vm createVm(final int pes) { - return new VmSimple(1000, pes) + return new VmSimple(new CoreCapacity(pes, 1000)) .setRam(1000).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); } @@ -198,7 +198,7 @@ private List createCloudlets(final int count) { private Cloudlet createCloudlet() { final var um = new UtilizationModelDynamic(0.2); - return new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES) + return new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelCpu(new UtilizationModelFull()) diff --git a/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample1.java b/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample1.java index 3cd6f94..a043dbb 100755 --- a/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample1.java +++ b/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample1.java @@ -35,8 +35,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.CloudletVmEventInfo; import org.cloudsimplus.listeners.EventListener; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerSpaceShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -166,7 +165,7 @@ private Vm createVm(int id) { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; - final var vm = new VmSimple(id, mips, VM_PES_NUMBER) + final var vm = new VmSimple(id, new CoreCapacity(VM_PES_NUMBER, mips)) .setRam(ram).setBw(bw).setSize(size) .setCloudletScheduler(new CloudletSchedulerSpaceShared()); @@ -211,16 +210,13 @@ private Datacenter createDatacenter() { /// @param id The Host id /// @return the created host private Host createHost(int id) { - final var peList = new ArrayList(); final long mips = 1000; - for(int i = 0; i < HOST_PES_NUMBER; i++){ - peList.add(new PeSimple(mips)); - } + final var cpuCapacity = new CoreCapacity(HOST_PES_NUMBER, mips); final long ram = 2048; // host memory (Megabyte) final long storage = 1000000; // host storage (Megabyte) final long bw = 10000; //Megabits/s - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerTimeShared()); + return new HostSimple(ram, bw, storage, cpuCapacity).setVmScheduler(new VmSchedulerTimeShared()); } } diff --git a/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample2_ResourceUsageAlongTime.java b/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample2_ResourceUsageAlongTime.java index d968150..1276622 100755 --- a/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample2_ResourceUsageAlongTime.java +++ b/src/main/java/org/cloudsimplus/examples/listeners/CloudletListenersExample2_ResourceUsageAlongTime.java @@ -36,8 +36,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.CloudletVmEventInfo; import org.cloudsimplus.listeners.EventListener; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerSpaceShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelStochastic; @@ -168,7 +167,7 @@ private Vm createVm(int id) { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; - final var vm = new VmSimple(id, mips, VM_PES_NUMBER) + final var vm = new VmSimple(id, new CoreCapacity(VM_PES_NUMBER, mips)) .setRam(ram).setBw(bw).setSize(size) .setCloudletScheduler(new CloudletSchedulerSpaceShared()); return vm; @@ -219,16 +218,13 @@ private Datacenter createDatacenter() { /// @param id The Host id /// @return the created host private Host createHost(int id) { - final var peList = new ArrayList(); final long mips = 1000; - for(int i = 0; i < HOST_PES_NUMBER; i++){ - peList.add(new PeSimple(mips)); - } + final var cpuCapacity = new CoreCapacity(HOST_PES_NUMBER, mips); final long ram = 2048; // host memory (Megabyte) final long storage = 1000000; // host storage (Megabyte) final long bw = 10000; //Megabits/s - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerTimeShared()); + return new HostSimple(ram, bw, storage, cpuCapacity).setVmScheduler(new VmSchedulerTimeShared()); } } diff --git a/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample1.java b/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample1.java index d62f5b0..2374d84 100755 --- a/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample1.java +++ b/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample1.java @@ -34,8 +34,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.EventListener; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -164,7 +163,7 @@ private Vm createVm(int id) { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; - return new VmSimple(id, mips, VM_PES_NUMBER) + return new VmSimple(id, new CoreCapacity(VM_PES_NUMBER, mips)) .setRam(ram).setBw(bw).setSize(size) .setCloudletScheduler(new CloudletSchedulerTimeShared()); } @@ -201,16 +200,13 @@ private Datacenter createDatacenter() { /// @param id The Host id /// @return the created host private Host createHost(int id) { - final var peList = new ArrayList(); final long mips = 1000; - for(int i = 0; i < HOST_PES_NUMBER; i++){ - peList.add(new PeSimple(mips)); - } + final var cpuCapacity = new CoreCapacity(HOST_PES_NUMBER, mips); final long ram = 2048; // host memory (Megabyte) final long storage = 1000000; // host storage (Megabyte) final long bw = 10000; //Megabits/s - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerTimeShared()); + return new HostSimple(ram, bw, storage, cpuCapacity).setVmScheduler(new VmSchedulerTimeShared()); } } diff --git a/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample2.java b/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample2.java index e562278..04e0818 100755 --- a/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample2.java +++ b/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample2.java @@ -35,8 +35,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.EventListener; import org.cloudsimplus.listeners.VmHostEventInfo; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -165,7 +164,7 @@ private Vm createVm(int id) { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; - final var vm = new VmSimple(id, mips, VM_PES_NUMBER) + final var vm = new VmSimple(id, new CoreCapacity(VM_PES_NUMBER, mips)) .setRam(ram).setBw(bw).setSize(size) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -210,17 +209,14 @@ private Datacenter createDatacenter() { /// @param id The Host id /// @return the created host private Host createHost(int id) { - final var peList = new ArrayList(); long mips = 1000; - for(int i = 0; i < HOST_PES_NUMBER; i++){ - peList.add(new PeSimple(mips)); - } + final var cpuCapacity = new CoreCapacity(HOST_PES_NUMBER, mips); final long ram = 2048; // host memory (Megabyte) final long storage = 1000000; // host storage (Megabyte) final long bw = 10000; //Megabits/s - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerTimeShared()); + return new HostSimple(ram, bw, storage, cpuCapacity).setVmScheduler(new VmSchedulerTimeShared()); } private void runSimulationAndPrintResults() { diff --git a/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample3_DynamicVmCreation.java b/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample3_DynamicVmCreation.java index c6f872f..9ff6708 100755 --- a/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample3_DynamicVmCreation.java +++ b/src/main/java/org/cloudsimplus/examples/listeners/VmListenersExample3_DynamicVmCreation.java @@ -35,8 +35,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.EventListener; import org.cloudsimplus.listeners.VmHostEventInfo; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerSpaceShared; import org.cloudsimplus.schedulers.vm.VmSchedulerSpaceShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -209,7 +208,7 @@ private Vm createVm(int id, DatacenterBroker broker) { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; - return new VmSimple(id, mips, VM_PES_NUMBER) + return new VmSimple(id, new CoreCapacity(VM_PES_NUMBER, mips)) .setRam(ram).setBw(bw).setSize(size) .setCloudletScheduler(new CloudletSchedulerSpaceShared()) .addOnHostDeallocationListener(this::onHostDeallocationListener); @@ -249,16 +248,13 @@ private Datacenter createDatacenter() { /// @param id The Host id /// @return the created host private Host createHost(int id) { - final var peList = new ArrayList(); long mips = 1000; - for(int i = 0; i < HOST_PES_NUMBER; i++){ - peList.add(new PeSimple(mips)); - } + final var cpuCapacity = new CoreCapacity(HOST_PES_NUMBER, mips); final long ram = 2048; // host memory (Megabyte) final long storage = 1000000; // host storage (Megabyte) final long bw = 10000; //Megabits/s - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerSpaceShared()); + return new HostSimple(ram, bw, storage, cpuCapacity).setVmScheduler(new VmSchedulerSpaceShared()); } } diff --git a/src/main/java/org/cloudsimplus/examples/migration/InterDatacenterMigration1.java b/src/main/java/org/cloudsimplus/examples/migration/InterDatacenterMigration1.java index c08438b..3cb19a2 100755 --- a/src/main/java/org/cloudsimplus/examples/migration/InterDatacenterMigration1.java +++ b/src/main/java/org/cloudsimplus/examples/migration/InterDatacenterMigration1.java @@ -42,8 +42,7 @@ import org.cloudsimplus.listeners.DatacenterBrokerEventInfo; import org.cloudsimplus.listeners.EventListener; import org.cloudsimplus.listeners.VmHostEventInfo; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.selectionpolicies.VmSelectionPolicyMinimumUtilization; import org.cloudsimplus.util.Log; @@ -168,7 +167,7 @@ public final class InterDatacenterMigration1 { /// /// The length of this matrix (number of rows) must be equal to the number of datacenters, /// defined by the length of [#DC_HOST_PES]. - private static final int[][] VM_PES = {{3, 2, 2}, {4, 4, 4}}; + private static final int[][] VM_CORES = {{3, 2, 2}, {4, 4, 4}}; private static final int VM_MIPS = 1000; //for each PE private static final long VM_SIZE = 100_000; //image size (MB) @@ -235,9 +234,9 @@ private void validateConfiguration() { } final int datacentersNumber = DC_HOST_PES.length; - if(VM_PES.length < datacentersNumber) { + if(VM_CORES.length < datacentersNumber) { throw new IllegalStateException("" + - "The number of rows on matrix VM_PES must be at least equal to the number of datacenters, indicating PEs for VMs in each datacenter.."); + "The number of rows on matrix VM_CORES must be at least equal to the number of datacenters, indicating PEs for VMs in each datacenter.."); } } @@ -294,7 +293,7 @@ private void printHostStateHistory(final Host host) { private void createVmsAndCloudlets() { int i = 0; for (final DatacenterBroker broker : brokerList) { - createAndSubmitVms(broker, VM_PES[i++]); + createAndSubmitVms(broker, VM_CORES[i++]); createAndSubmitCloudlets(broker); broker.addOnVmsCreatedListener(this::onVmsCreatedListener); } @@ -322,7 +321,7 @@ private void onVmsCreatedListener(final DatacenterBrokerEventInfo info) { } public void createAndSubmitCloudlets(final DatacenterBroker broker) { - final var cloudletList = new ArrayList(VM_PES.length); + final var cloudletList = new ArrayList(VM_CORES.length); final UtilizationModelDynamic um = createCpuUtilizationModel(CLOUDLET_INITIAL_CPU_PERCENTAGE, 1); for(final var vm: broker.getVmWaitingList()){ final var cloudlet = createCloudlet(vm, um); @@ -340,7 +339,7 @@ public void createAndSubmitCloudlets(final DatacenterBroker broker) { public Cloudlet createCloudlet(final Vm vm, final UtilizationModel cpuUtilizationModel) { final var broker = vm.getBroker(); final var cloudlet = - new CloudletSimple(createdCloudlets++, CLOUDLET_LENGTH, vm.getPesNumber()) + new CloudletSimple(createdCloudlets++, CLOUDLET_LENGTH, vm.getProcessor().getCores()) .setFileSize(CLOUDLET_FILESIZE) .setOutputSize(CLOUDLET_OUTPUT_SIZE) .setUtilizationModelRam(new UtilizationModelDynamic(0.4)) @@ -366,7 +365,7 @@ private void startMigration(final VmHostEventInfo info) { } public Vm createVm(final int pes) { - return new VmSimple(createdVms++, VM_MIPS, pes) + return new VmSimple(createdVms++, new CoreCapacity(pes, VM_MIPS)) .setRam(VM_RAM) .setBw(VM_BW) .setSize(VM_SIZE); @@ -432,7 +431,7 @@ private Datacenter createDatacenter(final int index) { final String hostsStr = hostList.stream() - .map(host -> String.format("Host %d w/ %d PEs", host.getId(), host.getPesNumber())) + .map(host -> String.format("Host %d w/ %d PEs", host.getId(), host.getProcessor().getCores())) .collect(joining(", ")); System.out.printf("%7s-cloud %s: %s%n", distribution, dc, hostsStr); return dc; @@ -449,20 +448,12 @@ private List createHosts(final int[] pesNumberArray) { } public Host createHost(final int pesNumber, final long ram) { - final var peList = createPeList(pesNumber); - final var host = new HostSimple(ram, HOST_BW, HOST_STORAGE, peList); + final var cpuCapacity = new CoreCapacity(pesNumber, HOST_MIPS); + final var host = new HostSimple(ram, HOST_BW, HOST_STORAGE, cpuCapacity); host.setId(createdHosts++) .setVmScheduler(new VmSchedulerTimeShared()) .setStateHistoryEnabled(true); return host; } - public List createPeList(final int pesNumber) { - final var peList = new ArrayList(pesNumber); - for(int i = 0; i < pesNumber; i++) { - peList.add(new PeSimple(HOST_MIPS)); - } - - return peList; - } } diff --git a/src/main/java/org/cloudsimplus/examples/migration/ManualMigrationExample1.java b/src/main/java/org/cloudsimplus/examples/migration/ManualMigrationExample1.java index e6ff1f5..beaee96 100755 --- a/src/main/java/org/cloudsimplus/examples/migration/ManualMigrationExample1.java +++ b/src/main/java/org/cloudsimplus/examples/migration/ManualMigrationExample1.java @@ -42,8 +42,7 @@ import org.cloudsimplus.listeners.EventInfo; import org.cloudsimplus.listeners.EventListener; import org.cloudsimplus.listeners.VmHostEventInfo; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -113,7 +112,7 @@ public final class ManualMigrationExample1 { private static final long VM_SIZE = 1000; //image size (MB) private static final int VM_RAM = 10000; //VM memory (MB) private static final double VM_BW = HOST_BW/(double)VMS; - private static final int VM_PES = 2; + private static final int VM_CORES = 2; private static final long CLOUDLET_LENGHT = 20000; private static final long CLOUDLET_FILESIZE = 300; @@ -212,7 +211,7 @@ public void createAndSubmitCloudlets(DatacenterBroker broker) { /// @return the created Cloudlets public Cloudlet createCloudlet(Vm vm, DatacenterBroker broker) { final var cloudlet = - new CloudletSimple(CLOUDLET_LENGHT, (int)vm.getPesNumber()) + new CloudletSimple(CLOUDLET_LENGHT, (int)vm.getProcessor().getCores()) .setFileSize(CLOUDLET_FILESIZE) .setOutputSize(CLOUDLET_OUTPUTSIZE) .setUtilizationModel(new UtilizationModelFull()); @@ -224,7 +223,7 @@ public Cloudlet createCloudlet(Vm vm, DatacenterBroker broker) { public void createAndSubmitVms(DatacenterBroker broker) { final var newVmList = new ArrayList(VMS); for(int i = 0; i < VMS; i++){ - newVmList.add(createVm(VM_PES)); + newVmList.add(createVm(VM_CORES)); } vmList.addAll(newVmList); @@ -249,7 +248,7 @@ private void startMigration(final VmHostEventInfo info) { } public Vm createVm(int pes) { - final Vm vm = new VmSimple(VM_MIPS, pes); + final Vm vm = new VmSimple(new CoreCapacity(pes, VM_MIPS)); vm .setRam(VM_RAM).setBw((long)VM_BW).setSize(VM_SIZE) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -273,19 +272,11 @@ private Datacenter createDatacenter() { } public Host createHost(int pesNumber, long mipsByPe) { - final var peList = createPeList(pesNumber, mipsByPe); - final var host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList); + final var cpuCapacity = new CoreCapacity(pesNumber, mipsByPe); + final var host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, cpuCapacity); host.setVmScheduler(new VmSchedulerTimeShared()) .setStateHistoryEnabled(true); return host; } - public List createPeList(int numberOfPEs, long mips) { - final var peList = new ArrayList(numberOfPEs); - for(int i = 0; i < numberOfPEs; i++) { - peList.add(new PeSimple(mips)); - } - - return peList; - } } diff --git a/src/main/java/org/cloudsimplus/examples/migration/MigrationExample1.java b/src/main/java/org/cloudsimplus/examples/migration/MigrationExample1.java index 5ba6691..1d10b5d 100755 --- a/src/main/java/org/cloudsimplus/examples/migration/MigrationExample1.java +++ b/src/main/java/org/cloudsimplus/examples/migration/MigrationExample1.java @@ -39,9 +39,7 @@ import org.cloudsimplus.listeners.DatacenterBrokerEventInfo; import org.cloudsimplus.listeners.EventListener; import org.cloudsimplus.listeners.VmHostEventInfo; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; -import org.cloudsimplus.schedulers.MipsShare; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.selectionpolicies.VmSelectionPolicyMinimumUtilization; @@ -146,13 +144,13 @@ public final class MigrationExample1 { /// An array where each item defines the number of PEs for each Host to be created. /// The length of the array represents the number of Hosts. - private static final int HOST_PES[] = {4, 5, 5}; + private static final int HOST_CORES[] = {4, 5, 5}; - private static final int VM_PES[] = {2, 2, 2, 1}; + private static final int VM_CORES[] = {2, 2, 2, 1}; private static final int VM_MIPS = 1000; //for each PE private static final long VM_SIZE = 1000; //image size (MB) private static final int VM_RAM = 10_000; //VM memory (MB) - private static final double VM_BW = HOST_BW/(double)VM_PES.length; + private static final double VM_BW = HOST_BW/(double)VM_CORES.length; private static final long CLOUDLET_LENGTH = 20_000; private static final long CLOUDLET_FILESIZE = 300; @@ -187,8 +185,8 @@ public static void main(String[] args) { private MigrationExample1(){ Log.setLevel(Level.INFO); - if(HOST_PES.length != HOST_RAM.length){ - throw new IllegalStateException("The length of arrays HOST_PES and HOST_RAM must match."); + if(HOST_CORES.length != HOST_RAM.length){ + throw new IllegalStateException("The length of arrays HOST_CORES and HOST_RAM must match."); } System.out.println("Starting " + getClass().getSimpleName()); @@ -224,7 +222,7 @@ private void printHosts() { System.out.println("Host ID | CPUs | MIPS"); System.out.println("---------------------"); for (final var host : hostList) { - System.out.printf("%7s | %4s | %s%n", host.getId(), host.getPesNumber(), (int)host.getMips()); + System.out.printf("%7s | %4s | %s%n", host.getId(), host.getProcessor().getCores(), (int)host.getProcessor().getMips()); } } @@ -260,9 +258,9 @@ private void startMigration(final VmHostEventInfo info) { private void showVmAllocatedMips(final Vm vm, final Host targetHost, final double time) { final String msg = String.format("# %.2f: %s in %s: total allocated", time, vm, targetHost); - final MipsShare allocatedMips = targetHost.getVmScheduler().getAllocatedMips(vm); + final CoreCapacity allocatedMips = targetHost.getVmScheduler().getAllocatedMips(vm); final String msg2 = allocatedMips.totalMips() == VM_MIPS * 0.9 ? " - reduction due to migration overhead" : ""; - System.out.printf("%s %.0f MIPs (divided by %d PEs)%s\n", msg, allocatedMips.totalMips(), allocatedMips.pes(), msg2); + System.out.printf("%s %.0f MIPs (divided by %d PEs)%s\n", msg, allocatedMips.totalMips(), allocatedMips.cores(), msg2); } /// A listener method that is called when a VM migration finishes. @@ -284,11 +282,11 @@ private void finishMigration(final VmHostEventInfo info) { private void showHostAllocatedMips(final double time, final Host host) { System.out.printf( "%.2f: %s allocated %.2f MIPS from %.2f total capacity%n", - time, host, host.getTotalAllocatedMips(), host.getTotalMipsCapacity()); + time, host, host.getVmScheduler().getTotalAllocatedMips(), host.getTotalMipsCapacity()); } public void createAndSubmitCloudlets(DatacenterBroker broker) { - final var newCloudletList = new ArrayList(VM_PES.length); + final var newCloudletList = new ArrayList(VM_CORES.length); var cloudlet = Cloudlet.NULL; UtilizationModelDynamic um = createCpuUtilizationModel(CLOUDLET_INITIAL_CPU_PERCENTAGE, 1); for(final var vm: vmList){ @@ -312,7 +310,7 @@ public Cloudlet createCloudlet(Vm vm, DatacenterBroker broker, UtilizationModel final var utilizationModelFull = new UtilizationModelFull(); final var cloudlet = - new CloudletSimple(CLOUDLET_LENGTH, (int)vm.getPesNumber()) + new CloudletSimple(CLOUDLET_LENGTH, (int)vm.getProcessor().getCores()) .setFileSize(CLOUDLET_FILESIZE) .setOutputSize(CLOUDLET_OUTPUTSIZE) .setUtilizationModelRam(utilizationModelFull) @@ -324,8 +322,8 @@ public Cloudlet createCloudlet(Vm vm, DatacenterBroker broker, UtilizationModel } public void createAndSubmitVms(DatacenterBroker broker) { - final var newVmList = new ArrayList(VM_PES.length); - for (final int pes : VM_PES) { + final var newVmList = new ArrayList(VM_CORES.length); + for (final int pes : VM_CORES) { newVmList.add(createVm(pes)); } @@ -337,7 +335,7 @@ public void createAndSubmitVms(DatacenterBroker broker) { } public Vm createVm(final int pes) { - final var vm = new VmSimple(VM_MIPS, pes); + final var vm = new VmSimple(new CoreCapacity(pes, VM_MIPS)); vm .setRam(VM_RAM).setBw((long)VM_BW).setSize(VM_SIZE) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -383,7 +381,7 @@ private double getCpuUsageIncrement(final UtilizationModelDynamic um){ return um.getUtilization() + um.getTimeSpan()*CLOUDLET_CPU_INCREMENT_PER_SECOND; } - /// Creates a Datacenter with number of Hosts defined by the length of [#HOST_PES], + /// Creates a Datacenter with number of Hosts defined by the length of [#HOST_CORES], /// but only some of these Hosts will be active (powered on) initially. /// /// @return @@ -393,7 +391,7 @@ private Datacenter createDatacenter() { for (Host host : hostList) { System.out.printf( "# Created %s with %.0f MIPS x %d PEs (%.0f total MIPS)%n", - host, host.getMips(), host.getPesNumber(), host.getTotalMipsCapacity()); + host, host.getProcessor().getMips(), host.getProcessor().getCores(), host.getTotalMipsCapacity()); } dc.setSchedulingInterval(SCHEDULING_INTERVAL) .setHostSearchRetryDelay(HOST_SEARCH_RETRY_DELAY); @@ -419,9 +417,9 @@ private VmAllocationPolicyMigrationStaticThreshold createAllocationPolicy() { } private List createHosts() { - final var hostList = new ArrayList(HOST_PES.length); - for (int i = 0; i < HOST_PES.length; i++) { - final int pes = HOST_PES[i]; + final var hostList = new ArrayList(HOST_CORES.length); + for (int i = 0; i < HOST_CORES.length; i++) { + final int pes = HOST_CORES[i]; final long ram = HOST_RAM[i]; hostList.add(createHost(pes, ram)); } @@ -430,22 +428,13 @@ private List createHosts() { } public Host createHost(final int pesNumber, final long ram) { - final var peList = createPeList(pesNumber); - final var host = new HostSimple(ram, HOST_BW, HOST_STORAGE, peList); + final var cpuCapacity = new CoreCapacity(pesNumber, HOST_MIPS); + final var host = new HostSimple(ram, HOST_BW, HOST_STORAGE, cpuCapacity); host.setVmScheduler(new VmSchedulerTimeShared()) .setStateHistoryEnabled(true); return host; } - public List createPeList(final int pesNumber) { - final var peList = new ArrayList(pesNumber); - for(int i = 0; i < pesNumber; i++) { - peList.add(new PeSimple(HOST_MIPS)); - } - - return peList; - } - /// A listener that is called after all VMs from a broker are created, /// setting the allocation policy to the default value /// so that some Hosts will be overloaded with the placed VMs and migration will be fired. diff --git a/src/main/java/org/cloudsimplus/examples/performance/PerformanceExample1.java b/src/main/java/org/cloudsimplus/examples/performance/PerformanceExample1.java index 5520cbc..f32da91 100755 --- a/src/main/java/org/cloudsimplus/examples/performance/PerformanceExample1.java +++ b/src/main/java/org/cloudsimplus/examples/performance/PerformanceExample1.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletScheduler; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; @@ -72,12 +71,26 @@ public class PerformanceExample1 { /// @see Datacenter#getSchedulingInterval() private static final double SCHEDULING_INTERVAL = TimeUtil.hoursToSeconds(1); private static final int HOSTS = 50_000; - private static final int HOST_PES = 64; + private static final int HOST_CORES = 64; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = HOSTS * 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final long CLOUDLET_LENGTH = 10_000_000_000L; /// The percentage of RAM and BW each Cloudlet will request during all simulation execution @@ -138,15 +151,10 @@ private Datacenter createDatacenter() { } private Host createHost() { - final List peList = - IntStream.range(0, HOST_PES) - .mapToObj(i -> new PeSimple(1000)) - .collect(toCollection(() -> new ArrayList<>(HOST_PES))); - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setVmScheduler(new VmSchedulerTimeShared()); return host; } @@ -155,7 +163,7 @@ private List createVms() { final var newVmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { final var vm = - new VmSimple(i, 1000, VM_PES) + new VmSimple(i, VM_CAPACITY) .setCloudletScheduler(cloudletSchedulerSupplier.get()) .setRam(512).setBw(1000).setSize(10000); @@ -169,7 +177,7 @@ private List createVms() { private Cloudlet createCloudlet(final Vm vm) { final var ramBwModel = new UtilizationModelDynamic(RAM_BW_RESOURCE_UTILIZATION_PERCENT); final var cloudlet = - new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES) + new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelBw(ramBwModel) diff --git a/src/main/java/org/cloudsimplus/examples/performance/UtilizationModelFullPerformance.java b/src/main/java/org/cloudsimplus/examples/performance/UtilizationModelFullPerformance.java index f913a78..c03055f 100755 --- a/src/main/java/org/cloudsimplus/examples/performance/UtilizationModelFullPerformance.java +++ b/src/main/java/org/cloudsimplus/examples/performance/UtilizationModelFullPerformance.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.util.BytesConversion; import org.cloudsimplus.util.Log; import org.cloudsimplus.util.TimeUtil; @@ -67,13 +66,27 @@ /// @since CloudSim Plus 4.4.1 public class UtilizationModelFullPerformance { private static final int HOSTS = 20_000; - private static final int HOST_PES = 16; + private static final int HOST_CORES = 16; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = HOSTS*4; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = VMS*2; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10_000; private static final int SCHEDULING_INTERVAL = 0; @@ -146,21 +159,16 @@ private Datacenter createDatacenter() { } private Host createHost() { - final List peList = - IntStream.range(0, HOST_PES) - .mapToObj(i -> new PeSimple(1000)) - .collect(toCollection(() -> new ArrayList<>(HOST_PES))); - final long ramMB = 20480; final long bwMbps = 10000; final long storageMB = 1000000; - return new HostSimple(ramMB, bwMbps, storageMB, peList); + return new HostSimple(ramMB, bwMbps, storageMB, HOST_CAPACITY); } private List createVms() { final var newVmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { - final Vm vm = new VmSimple(1000, VM_PES); + final Vm vm = new VmSimple(VM_CAPACITY); newVmList.add(vm); } @@ -170,7 +178,7 @@ private List createVms() { private List createCloudlets() { final var newCloudletList = new ArrayList(CLOUDLETS); for (int i = 0; i < CLOUDLETS; i++) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES); cloudlet.setUtilizationModelCpu(um).setSizes(1024); newCloudletList.add(cloudlet); } diff --git a/src/main/java/org/cloudsimplus/examples/performance/UtilizationModelStochasticPerformance.java b/src/main/java/org/cloudsimplus/examples/performance/UtilizationModelStochasticPerformance.java index e9b4f04..d9200ea 100755 --- a/src/main/java/org/cloudsimplus/examples/performance/UtilizationModelStochasticPerformance.java +++ b/src/main/java/org/cloudsimplus/examples/performance/UtilizationModelStochasticPerformance.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.util.BytesConversion; import org.cloudsimplus.util.Log; import org.cloudsimplus.util.TimeUtil; @@ -80,13 +79,27 @@ /// @see Issue #197 for more details public class UtilizationModelStochasticPerformance { private static final int HOSTS = 20_000; - private static final int HOST_PES = 16; + private static final int HOST_CORES = 16; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = HOSTS*4; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = VMS*2; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10_000; private static final int SCHEDULING_INTERVAL = 10; @@ -186,21 +199,16 @@ private Datacenter createDatacenter() { } private Host createHost() { - final List peList = - IntStream.range(0, HOST_PES) - .mapToObj(i -> new PeSimple(1000)) - .collect(toCollection(() -> new ArrayList<>(HOST_PES))); - final long ramMB = 20480; final long bwMbps = 10000; final long storageMB = 1000000; - return new HostSimple(ramMB, bwMbps, storageMB, peList); + return new HostSimple(ramMB, bwMbps, storageMB, HOST_CAPACITY); } private List createVms() { final var newVmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { - final Vm vm = new VmSimple(1000, VM_PES); + final Vm vm = new VmSimple(VM_CAPACITY); newVmList.add(vm); } @@ -210,7 +218,7 @@ private List createVms() { private List createCloudlets() { final var newCloudletList = new ArrayList(CLOUDLETS); for (int i = 0; i < CLOUDLETS; i++) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES); this.um = MULTIPLE_UTILIZATION_MODELS || this.um == null ? new UtilizationModelStochastic(SEED) : this.um; this.um .setHistoryEnabled(STORE_CLOUDLETS_CPU_UTILIZATION_HISTORY) diff --git a/src/main/java/org/cloudsimplus/examples/power/HostActivationExample.java b/src/main/java/org/cloudsimplus/examples/power/HostActivationExample.java index 29f8624..567efea 100755 --- a/src/main/java/org/cloudsimplus/examples/power/HostActivationExample.java +++ b/src/main/java/org/cloudsimplus/examples/power/HostActivationExample.java @@ -40,8 +40,7 @@ import org.cloudsimplus.listeners.HostEventInfo; import org.cloudsimplus.power.models.PowerModelHost; import org.cloudsimplus.power.models.PowerModelHostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; @@ -82,7 +81,7 @@ public class HostActivationExample { private static final int SCHEDULING_INTERVAL = 2; private static final int HOSTS = 5; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; /// Defines the power a Host uses, even if it's idle (in Watts). private static final double STATIC_POWER = 35; @@ -109,9 +108,23 @@ public class HostActivationExample { private static final int HOST_IDLE_SECONDS_TO_SHUTDOWN = 5; private static final int HOST_MIPS = 1000; + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + private static final int MIN_VMS = 2; private static final int MAX_VMS = 4; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, HOST_MIPS); private static final int CLOUDLET_LENGTH = 20000; @@ -224,7 +237,7 @@ private List createAndSubmitVmsAndCloudlets(final int vmsToCreate) { final var newCloudletList = new ArrayList(vmsToCreate); for (int i = 0; i < vmsToCreate; i++) { - final var vm = new VmSimple(HOST_MIPS, VM_PES); + final var vm = new VmSimple(VM_CAPACITY); //vm.setSubmissionDelay(2.0); final var cloudlet = createCloudlet(vm); vmList.add(vm); @@ -255,15 +268,9 @@ private Datacenter createDatacenter() { /// @return a new powered-off Host /// @param id private Host createHost(final long id) { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(HOST_MIPS)); - } - //Indicates if the Host will be powered on or not after creation final boolean activate = false; - final var host = new HostSimple(peList, activate); + final var host = new HostSimple(HOST_CAPACITY, activate); host.setId(id) .setStartupDelay(HOST_START_UP_DELAY) .setShutDownDelay(HOST_SHUT_DOWN_DELAY); @@ -287,7 +294,7 @@ private Cloudlet createCloudlet(Vm vm) { * ensuring that a positive length is generated (Cloudlets * with negative length run indefinitely until being explicitly stopped. */ final long len = Math.abs(CLOUDLET_LENGTH - cloudletList.size()*3000); - return new CloudletSimple(len, VM_PES) + return new CloudletSimple(len, VM_CORES) .setUtilizationModelCpu(new UtilizationModelFull()) .setUtilizationModelRam(utilizationModel) .setVm(vm); diff --git a/src/main/java/org/cloudsimplus/examples/power/PowerExample.java b/src/main/java/org/cloudsimplus/examples/power/PowerExample.java index 84ee72c..255e2b9 100755 --- a/src/main/java/org/cloudsimplus/examples/power/PowerExample.java +++ b/src/main/java/org/cloudsimplus/examples/power/PowerExample.java @@ -36,8 +36,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.power.models.PowerModel; import org.cloudsimplus.power.models.PowerModelHostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -93,7 +92,14 @@ public class PowerExample { /// to keep Hosts CPU utilization history records. private static final int SCHEDULING_INTERVAL = 10; private static final int HOSTS = 2; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); /// Indicates the time (in seconds) the Host takes to start up. private static final double HOST_START_UP_DELAY = 5; @@ -108,10 +114,17 @@ public class PowerExample { private static final double HOST_SHUT_DOWN_POWER = 3; private static final int VMS = 4; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = 8; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 50000; /// Defines the power a Host uses, even if it's idle (in Watts). @@ -225,7 +238,6 @@ private void printHostCpuUtilizationAndPowerConsumption(final Host host) { /// Creates a [Datacenter] and its [Host]s. private Datacenter createDatacenter() { - for(int i = 0; i < HOSTS; i++) { final var host = createPowerHost(i); hostList.add(host); @@ -237,18 +249,12 @@ private Datacenter createDatacenter() { } private Host createPowerHost(final int id) { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes final var vmScheduler = new VmSchedulerTimeShared(); - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setStartupDelay(HOST_START_UP_DELAY) .setShutDownDelay(HOST_SHUT_DOWN_DELAY); @@ -269,7 +275,7 @@ private Host createPowerHost(final int id) { private List createVms() { final var list = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { - final var vm = new VmSimple(i, 1000, VM_PES); + final var vm = new VmSimple(i, VM_CAPACITY); vm.setRam(512).setBw(1000).setSize(10000).enableUtilizationStats(); list.add(vm); } @@ -285,7 +291,7 @@ private List createCloudlets() { //Sets half of the cloudlets with the defined length and the other half with the double of it final long length = i < CLOUDLETS / 2 ? CLOUDLET_LENGTH : CLOUDLET_LENGTH * 2; final var cloudlet = - new CloudletSimple(i, length, CLOUDLET_PES) + new CloudletSimple(i, length, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelCpu(new UtilizationModelFull()) diff --git a/src/main/java/org/cloudsimplus/examples/power/PowerExampleSchedulingInterval.java b/src/main/java/org/cloudsimplus/examples/power/PowerExampleSchedulingInterval.java index ff432ce..a22097b 100755 --- a/src/main/java/org/cloudsimplus/examples/power/PowerExampleSchedulingInterval.java +++ b/src/main/java/org/cloudsimplus/examples/power/PowerExampleSchedulingInterval.java @@ -34,8 +34,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.power.models.PowerModelHostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.util.Log; @@ -65,13 +64,27 @@ /// @since CloudSim Plus 4.0.0 public class PowerExampleSchedulingInterval { private static final int HOSTS = 2; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = 4; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 50000; /// Defines the power a Host uses, even if it's idle (in Watts). @@ -149,16 +162,11 @@ private Datacenter createDatacenterSimple() { } private Host createPowerHost(final int id) { - final var peList = new ArrayList(HOST_PES); - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host .setId(id) .setVmScheduler(new VmSchedulerTimeShared()) @@ -170,7 +178,7 @@ private Host createPowerHost(final int id) { private List createVms() { final var newVmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { - final var vm = new VmSimple(i, 1000, VM_PES); + final var vm = new VmSimple(i, VM_CAPACITY); vm.setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()) .enableUtilizationStats(); @@ -187,7 +195,7 @@ private List createCloudlets() { //Sets half of the cloudlets with the defined length and the other half with the double of it final long length = i < CLOUDLETS/2 ? CLOUDLET_LENGTH : CLOUDLET_LENGTH*2; final var cloudlet = - new CloudletSimple(i, length, CLOUDLET_PES) + new CloudletSimple(i, length, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelCpu(new UtilizationModelFull()) diff --git a/src/main/java/org/cloudsimplus/examples/power/PowerSpecFileExample.java b/src/main/java/org/cloudsimplus/examples/power/PowerSpecFileExample.java index 7d18f17..37f124d 100755 --- a/src/main/java/org/cloudsimplus/examples/power/PowerSpecFileExample.java +++ b/src/main/java/org/cloudsimplus/examples/power/PowerSpecFileExample.java @@ -34,8 +34,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.power.models.PowerModelHostSpec; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -67,7 +66,14 @@ public class PowerSpecFileExample { /// to keep Hosts CPU utilization history records. private static final int SCHEDULING_INTERVAL = 10; private static final int HOSTS = 2; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); /// Indicates the time (in seconds) the Host takes to start up. private static final double HOST_START_UP_DELAY = 5; @@ -82,10 +88,17 @@ public class PowerSpecFileExample { private static final double HOST_SHUT_DOWN_POWER = 3; private static final int VMS = 4; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = 8; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 50000; /// The path to the file containing host power utilization specs. @@ -170,18 +183,12 @@ private Datacenter createDatacenter() { } private Host createPowerHost(final int id) { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes final var vmScheduler = new VmSchedulerTimeShared(); - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setStartupDelay(HOST_START_UP_DELAY) .setShutDownDelay(HOST_SHUT_DOWN_DELAY); @@ -203,7 +210,7 @@ private Host createPowerHost(final int id) { private List createVms() { final var list = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { - final var vm = new VmSimple(i, 1000, VM_PES); + final var vm = new VmSimple(i, VM_CAPACITY); vm.setRam(512).setBw(1000).setSize(10000); list.add(vm); } @@ -219,7 +226,7 @@ private List createCloudlets() { //Sets half of the cloudlets with the defined length and the other half with the double of it final long length = i < CLOUDLETS / 2 ? CLOUDLET_LENGTH : CLOUDLET_LENGTH * 2; final var cloudlet = - new CloudletSimple(i, length, CLOUDLET_PES) + new CloudletSimple(i, length, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelCpu(new UtilizationModelFull()) diff --git a/src/main/java/org/cloudsimplus/examples/resourceusage/HostsCpuUsageExample.java b/src/main/java/org/cloudsimplus/examples/resourceusage/HostsCpuUsageExample.java index 45487b8..4fa6a49 100755 --- a/src/main/java/org/cloudsimplus/examples/resourceusage/HostsCpuUsageExample.java +++ b/src/main/java/org/cloudsimplus/examples/resourceusage/HostsCpuUsageExample.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -108,8 +107,8 @@ private HostsCpuUsageExample(){ final var cloudletFinishedList = broker.getCloudletFinishedList(); new CloudletsTableBuilder(cloudletFinishedList) - .addColumn(new TextTableColumn("Host ", "MIPS "), cloudlet -> cloudlet.getVm().getHost().getMips(), 5) - .addColumn(new TextTableColumn("VM MIPS"), cloudlet -> cloudlet.getVm().getMips(), 7) + .addColumn(new TextTableColumn("Host ", "MIPS "), cloudlet -> cloudlet.getVm().getHost().getProcessor().getMips(), 5) + .addColumn(new TextTableColumn("VM MIPS"), cloudlet -> cloudlet.getVm().getProcessor().getMips(), 7) .build(); System.out.printf("%nHosts CPU utilization statistics%n"); @@ -139,7 +138,7 @@ private Vm createVm(final int pesNumber, final long mips) { final long size = 10000; //image size (Megabyte) final int ram = 2048; //vm memory (Megabyte) final long bw = 1000; - final var vm = new VmSimple(mips, pesNumber) + final var vm = new VmSimple(new CoreCapacity(pesNumber, mips)) .setRam(ram).setBw(bw).setSize(size) .setCloudletScheduler(new CloudletSchedulerTimeShared()); vm.enableUtilizationStats(); @@ -149,11 +148,11 @@ private Vm createVm(final int pesNumber, final long mips) { /// Shows CPU utilization mean of all hosts into a given Datacenter. private void printCpuUtilizationForAllHosts() { for (final var host : hostList) { - final double mipsByPe = host.getTotalMipsCapacity() / (double)host.getPesNumber(); + final double mipsByPe = host.getTotalMipsCapacity() / (double)host.getProcessor().getCores(); final double cpuUsageMean = host.getCpuUtilizationStats().getMean()*100; System.out.printf( "\tHost %d: PEs number: %2d MIPS by PE: %.0f CPU Utilization mean: %6.2f%%%n", - host.getId(), host.getPesNumber(), mipsByPe, cpuUsageMean); + host.getId(), host.getProcessor().getCores(), mipsByPe, cpuUsageMean); } } @@ -185,16 +184,13 @@ private Datacenter createDatacenter() { } private Host createHost(final int id, final int pesNumber, final long mips) { - final var peList = new ArrayList(); - for (int i = 0; i < pesNumber; i++) { - peList.add(new PeSimple(mips)); - } + final var cpuCapacity = new CoreCapacity(pesNumber, mips); final long ram = 2048; //host memory (Megabyte) final long storage = 1000000; //host storage (Megabyte) final long bw = 10000; //Megabits/s - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, cpuCapacity); host.setId(id) .setVmScheduler(new VmSchedulerTimeShared()); host.enableUtilizationStats(); diff --git a/src/main/java/org/cloudsimplus/examples/resourceusage/UtilizationModelDynamicExample.java b/src/main/java/org/cloudsimplus/examples/resourceusage/UtilizationModelDynamicExample.java index 2aa1ebf..655642f 100755 --- a/src/main/java/org/cloudsimplus/examples/resourceusage/UtilizationModelDynamicExample.java +++ b/src/main/java/org/cloudsimplus/examples/resourceusage/UtilizationModelDynamicExample.java @@ -32,8 +32,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -121,15 +120,10 @@ private Host createHost() { final long storage = 1000000; // host storage (Megabyte) final long bw = 10000; //in Megabits/s - final var peList = new ArrayList(); //List of CPU cores + //Defines the number of Host CPU cores and the MIPS capacity of each core + final var cpuCapacity = new CoreCapacity(2, mips); - /*Creates the Host's CPU cores and defines the provisioner - used to allocate each core for requesting VMs.*/ - for (int i = 0; i < 2; i++) { - peList.add(new PeSimple(mips)); - } - - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerTimeShared()); + return new HostSimple(ram, bw, storage, cpuCapacity).setVmScheduler(new VmSchedulerTimeShared()); } private Vm createVm(DatacenterBroker broker) { @@ -139,7 +133,7 @@ private Vm createVm(DatacenterBroker broker) { final long bw = 1000; // vm bandwidth (Megabits/s) final int pesNumber = 2; // number of CPU cores - return new VmSimple(vmList.size(), mips, pesNumber) + return new VmSimple(vmList.size(), new CoreCapacity(pesNumber, mips)) .setRam(ram) .setBw(bw) .setSize(storage) @@ -150,7 +144,7 @@ private Cloudlet createCloudlet(DatacenterBroker broker, Vm vm) { final long length = 10000; //in Million Instructions (MI) final long fileSize = 300; //Size (in bytes) before execution final long outputSize = 300; //Size (in bytes) after execution - final long numberOfCpuCores = vm.getPesNumber(); //cloudlet will use all the VM's CPU cores + final long numberOfCpuCores = vm.getProcessor().getCores(); //cloudlet will use all the VM's CPU cores //Defines that the Cloudlet will use all the VM's RAM and Bandwidth. final var utilizationFull = new UtilizationModelFull(); diff --git a/src/main/java/org/cloudsimplus/examples/resourceusage/VirtualMemoryForRequestedRamHigherThanAvailableExample.java b/src/main/java/org/cloudsimplus/examples/resourceusage/VirtualMemoryForRequestedRamHigherThanAvailableExample.java index 2e833dd..ada7e33 100755 --- a/src/main/java/org/cloudsimplus/examples/resourceusage/VirtualMemoryForRequestedRamHigherThanAvailableExample.java +++ b/src/main/java/org/cloudsimplus/examples/resourceusage/VirtualMemoryForRequestedRamHigherThanAvailableExample.java @@ -35,9 +35,8 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.resources.HarddriveStorage; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerAbstract; import org.cloudsimplus.utilizationmodels.UtilizationModel; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -100,17 +99,31 @@ public class VirtualMemoryForRequestedRamHigherThanAvailableExample { private static final long HOST_RAM = 20_480; //in Megabytes private static final int HOSTS = 2; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; private static final int HOST_MIPS = 1_000; + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); private static final int VMS = 3; - private static final int VM_PES = 2; + private static final int VM_CORES = 2; private static final int VM_MIPS = 1_000; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, VM_MIPS); + /// VM RAM capacity (in MB) private static final int VM_RAM = 10_000; - private static final int CLOUDLET_PES = 1; + private static final int CLOUDLET_CORES = 1; private static final int CLOUDLET_LENGTH = 10_000; private final CloudSimPlus simulation; @@ -205,13 +218,6 @@ private Datacenter createDatacenter() { /// that impact the delay imposed for Cloudlets using Virtual Memory. /// @return private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - //Uses a PeProvisionerSimple by default to provision PEs for VMs - peList.add(new PeSimple(HOST_MIPS)); - } - final long bw = 10000; //in Megabits/s final long storageSize = 1_000_000; //in Megabytes final var hardDrive = new HarddriveStorage(storageSize); @@ -221,7 +227,7 @@ private Host createHost() { Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - return new HostSimple(HOST_RAM, bw, hardDrive, peList); + return new HostSimple(HOST_RAM, bw, hardDrive, HOST_CAPACITY); } /// Creates a list of VMs. @@ -229,7 +235,7 @@ private List createVms() { final var newVmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final Vm vm = new VmSimple(VM_MIPS, VM_PES); + final Vm vm = new VmSimple(VM_CAPACITY); vm.setRam(VM_RAM).setBw(1000).setSize(10000); newVmList.add(vm); } @@ -279,7 +285,7 @@ private Cloudlet createCloudlet( final Vm vm, final UtilizationModel utilizationModelRam, final UtilizationModel utilizationModelBw) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES); cloudlet.setUtilizationModelCpu(new UtilizationModelFull()) .setUtilizationModelRam(utilizationModelRam) .setUtilizationModelBw(utilizationModelBw) diff --git a/src/main/java/org/cloudsimplus/examples/resourceusage/VmRelativeHostResourceUtilizationExample.java b/src/main/java/org/cloudsimplus/examples/resourceusage/VmRelativeHostResourceUtilizationExample.java index 8f14e70..00a69c2 100755 --- a/src/main/java/org/cloudsimplus/examples/resourceusage/VmRelativeHostResourceUtilizationExample.java +++ b/src/main/java/org/cloudsimplus/examples/resourceusage/VmRelativeHostResourceUtilizationExample.java @@ -34,8 +34,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.EventInfo; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.util.Log; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -55,18 +54,33 @@ public class VmRelativeHostResourceUtilizationExample { private static final int SCHEDULING_INTERVAL = 2; private static final int HOSTS = 1; - private static final int HOST_PES = 16; + private static final int HOST_CORES = 16; private static final long HOST_RAM = 10_000; //in Megabytes private static final long HOST_BW = 100_000; //in Megabits/s private static final int HOST_MIPS = 1000; + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, HOST_MIPS); + private static final long VM_RAM = HOST_RAM/VMS; //in Megabytes private static final long VM_BW = HOST_BW/VMS; //in Megabits/s private static final int CLOUDLETS = VMS; - private static final int CLOUDLET_PES = VM_PES; + private static final int CLOUDLET_CORES = VM_CORES; private static final int CLOUDLET_LENGTH = 10_000; private final CloudSimPlus simulation; @@ -126,24 +140,19 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(HOST_MIPS)); - } - final long storage = 1000000; //in Megabytes /* Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - return new HostSimple(HOST_RAM, HOST_BW, storage, peList); + return new HostSimple(HOST_RAM, HOST_BW, storage, HOST_CAPACITY); } private List createVms() { final var newVmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { - final var vm = new VmSimple(HOST_MIPS, VM_PES); + final var vm = new VmSimple(VM_CAPACITY); vm.setRam(VM_RAM).setBw(VM_BW).setSize(10000); newVmList.add(vm); } @@ -158,7 +167,7 @@ private List createCloudlets() { final var utilizationModelRamAndBw = new UtilizationModelDynamic(0.5); for (int i = 0; i < CLOUDLETS; i++) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES); cloudlet.setUtilizationModelCpu(new UtilizationModelFull()) .setUtilizationModelBw(utilizationModelRamAndBw) .setUtilizationModelRam(utilizationModelRamAndBw) diff --git a/src/main/java/org/cloudsimplus/examples/resourceusage/VmsCpuUsageExample.java b/src/main/java/org/cloudsimplus/examples/resourceusage/VmsCpuUsageExample.java index c5f2ba5..08b4d61 100755 --- a/src/main/java/org/cloudsimplus/examples/resourceusage/VmsCpuUsageExample.java +++ b/src/main/java/org/cloudsimplus/examples/resourceusage/VmsCpuUsageExample.java @@ -35,8 +35,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -103,7 +102,7 @@ private VmsCpuUsageExample() { simulation.start(); new CloudletsTableBuilder(broker.getCloudletFinishedList()) - .addColumn(new TextTableColumn("VM MIPS"), cl -> cl.getVm().getMips(), 7) + .addColumn(new TextTableColumn("VM MIPS"), cl -> cl.getVm().getProcessor().getMips(), 7) .build(); printCpuUtilizationForAllVms(); @@ -138,7 +137,7 @@ private Vm createVm(final int pesNumber, final int mips, final int id) { final long bw = 1000; //create two VMs - final var vm = new VmSimple(id, mips, pesNumber); + final var vm = new VmSimple(id, new CoreCapacity(pesNumber, mips)); vm.setRam(ram).setBw(bw) .setSize(size) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -175,16 +174,13 @@ private static Datacenter createDatacenter(CloudSimPlus simulation) { } private static Host createHost(final int id, final int pesNumber, final long mips) { - final var peList = new ArrayList(); - for (int i = 0; i < pesNumber; i++) { - peList.add(new PeSimple(mips)); - } + final var cpuCapacity = new CoreCapacity(pesNumber, mips); final int ram = 2048; //host memory (Megabyte) final long storage = 1000000; //host storage final int bw = 10000; - final var host = new HostSimple(ram, bw, storage, peList) + final var host = new HostSimple(ram, bw, storage, cpuCapacity) .setId(id) .setStateHistoryEnabled(true) .setRamProvisioner(new ResourceProvisionerSimple()) diff --git a/src/main/java/org/cloudsimplus/examples/resourceusage/VmsRamAndBwUsageExample.java b/src/main/java/org/cloudsimplus/examples/resourceusage/VmsRamAndBwUsageExample.java index 6d64119..2b7da7f 100755 --- a/src/main/java/org/cloudsimplus/examples/resourceusage/VmsRamAndBwUsageExample.java +++ b/src/main/java/org/cloudsimplus/examples/resourceusage/VmsRamAndBwUsageExample.java @@ -36,6 +36,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.EventInfo; import org.cloudsimplus.listeners.EventListener; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.resources.*; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; @@ -69,13 +70,20 @@ public class VmsRamAndBwUsageExample { private static final int SCHEDULING_INTERVAL = 1; private static final int HOSTS = 4; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 2; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; private static final int CLOUDLETS = 5; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -157,7 +165,6 @@ private void printVmUtilizationHistory(Vm vm) { System.out.printf("----------------------------------------------------------------------------------%n%n"); } - /// Initializes a map that will store utilization history for /// some resource (such as RAM or BW) of every VM. /// It also creates an empty internal map to store @@ -217,16 +224,10 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setVmScheduler(new VmSchedulerTimeShared()); return host; } @@ -235,13 +236,13 @@ private Host createHost() { private List createVms() { final var newVmList = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { - newVmList.add(createVm(VM_PES)); + newVmList.add(createVm(VM_CORES)); } return newVmList; } private Vm createVm(final int pes) { - return new VmSimple(1000, pes) + return new VmSimple(new CoreCapacity(pes, 1000)) .setRam(1000).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); } @@ -266,7 +267,7 @@ private Cloudlet createCloudlet() { ramUtilizationModel.setUtilizationUpdateFunction(this::utilizationUpdate); bwUtilizationModel.setUtilizationUpdateFunction(this::utilizationUpdate); - return new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES) + return new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelCpu(new UtilizationModelFull()) diff --git a/src/main/java/org/cloudsimplus/examples/schedulers/CloudletSchedulerSpaceSharedExample1.java b/src/main/java/org/cloudsimplus/examples/schedulers/CloudletSchedulerSpaceSharedExample1.java index 7a7df40..12234e5 100755 --- a/src/main/java/org/cloudsimplus/examples/schedulers/CloudletSchedulerSpaceSharedExample1.java +++ b/src/main/java/org/cloudsimplus/examples/schedulers/CloudletSchedulerSpaceSharedExample1.java @@ -35,8 +35,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerSpaceShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -60,13 +59,20 @@ /// @since CloudSim Plus 1.2.1 public class CloudletSchedulerSpaceSharedExample1 { private static final int HOSTS = 1; - private static final int HOST_PES = 4; + private static final int HOST_CORES = 4; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 1; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; private static final int CLOUDLETS = 4; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -115,16 +121,10 @@ private Datacenter createDatacenter() { /// Creates a Host that uses a [ResourceProvisionerSimple] by default /// for RAM and BW. private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setVmScheduler(new VmSchedulerTimeShared()); return host; } @@ -134,7 +134,7 @@ private List createVms() { final var vmList = new ArrayList(VMS); final int mips = 1000; for (int id = 0; id < VMS; id++) { - final var vm = new VmSimple(id, mips, VM_PES); + final var vm = new VmSimple(id, new CoreCapacity(VM_CORES, mips)); vm .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerSpaceShared()); @@ -152,7 +152,7 @@ private List createCloudlets() { /* A utilization model for RAM and BW that uses only 50% of the resource capacity all the time. */ final var utilizationModelDynamic = new UtilizationModelDynamic(0.5); for (int id = 0; id < CLOUDLETS; id++) { - final var cloudlet = new CloudletSimple(id, CLOUDLET_LENGTH, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(id, CLOUDLET_LENGTH, CLOUDLET_CORES); cloudlet .setFileSize(1024) .setOutputSize(1024) diff --git a/src/main/java/org/cloudsimplus/examples/schedulers/CloudletSchedulerTimeSharedExample1.java b/src/main/java/org/cloudsimplus/examples/schedulers/CloudletSchedulerTimeSharedExample1.java index fc2e3f6..71aac94 100755 --- a/src/main/java/org/cloudsimplus/examples/schedulers/CloudletSchedulerTimeSharedExample1.java +++ b/src/main/java/org/cloudsimplus/examples/schedulers/CloudletSchedulerTimeSharedExample1.java @@ -33,8 +33,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -60,13 +59,27 @@ /// @since CloudSim Plus 1.2.1 public class CloudletSchedulerTimeSharedExample1 { private static final int HOSTS = 1; - private static final int HOST_PES = 4; + private static final int HOST_CORES = 4; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 1; - private static final int VM_PES = 2; + private static final int VM_CORES = 2; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = 2; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -113,17 +126,11 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes final var vmScheduler = new VmSchedulerTimeShared(); - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host.setVmScheduler(vmScheduler); return host; } @@ -133,7 +140,7 @@ private List createVms() { final var newVmList = new ArrayList(VMS); for (int v = 0; v < VMS; v++) { final var vm = - new VmSimple(v, 1000, VM_PES) + new VmSimple(v, VM_CAPACITY) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -148,7 +155,7 @@ private List createCloudlets() { final var newCloudletList = new ArrayList(CLOUDLETS); for (int c = 0; c < CLOUDLETS; c++) { final var cloudlet = - new CloudletSimple(c, CLOUDLET_LENGTH, CLOUDLET_PES) + new CloudletSimple(c, CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelCpu(new UtilizationModelFull()) diff --git a/src/main/java/org/cloudsimplus/examples/schedulers/LinuxCompletelyFairSchedulerExample.java b/src/main/java/org/cloudsimplus/examples/schedulers/LinuxCompletelyFairSchedulerExample.java index 73d7cd1..60694cd 100755 --- a/src/main/java/org/cloudsimplus/examples/schedulers/LinuxCompletelyFairSchedulerExample.java +++ b/src/main/java/org/cloudsimplus/examples/schedulers/LinuxCompletelyFairSchedulerExample.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerCompletelyFair; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -60,12 +59,20 @@ public class LinuxCompletelyFairSchedulerExample { private static final int HOSTS_NUMBER = 1; private static final long HOST_MIPS = 1000; - private static final int HOST_PES = 3; + private static final int HOST_CORES = 3; private static final int VMS_NUMBER = 1; - private static final int VM_PES = HOST_PES; + private static final int VM_CORES = HOST_CORES; private static final long VM_MIPS = HOST_MIPS; - private static final int CLOUDLETS_NUMBER = HOST_PES*2; - private static final int CLOUDLET_PES = 1; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, VM_MIPS); + + private static final int CLOUDLETS_NUMBER = HOST_CORES*2; + private static final int CLOUDLET_CORES = 1; private static final int CLOUDLET_LEN = 10000; //in MI private final CloudSimPlus simulation; @@ -137,26 +144,17 @@ private Host createHost() { final long storage = 1000000; // host storage final long bw = 10000; - final var peList = createHostPesList(HOST_MIPS); + final var peList = new CoreCapacity(HOST_CORES, HOST_MIPS); return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerTimeShared()); } - private List createHostPesList(long mips) { - final var cpuCoresList = new ArrayList(HOST_PES); - for(int i = 0; i < HOST_PES; i++){ - cpuCoresList.add(new PeSimple(mips)); - } - - return cpuCoresList; - } - private Vm createVm(DatacenterBroker broker) { final long storage = 10000; // vm image size (Megabyte) final int ram = 512; // vm memory (Megabyte) final long bw = 1000; // vm bandwidth - return new VmSimple(numberOfCreatedVms++, VM_MIPS, VM_PES) + return new VmSimple(numberOfCreatedVms++, VM_CAPACITY) .setRam(ram).setBw(bw).setSize(storage) .setCloudletScheduler(new CloudletSchedulerCompletelyFair()); } @@ -166,7 +164,7 @@ private Cloudlet createCloudlet(DatacenterBroker broker) { final long outputSize = 300; //Size (in bytes) after execution final var utilization = new UtilizationModelFull(); - return new CloudletSimple(numberOfCreatedCloudlets++, CLOUDLET_LEN, CLOUDLET_PES) + return new CloudletSimple(numberOfCreatedCloudlets++, CLOUDLET_LEN, CLOUDLET_CORES) .setFileSize(fileSize) .setOutputSize(outputSize) .setUtilizationModelCpu(utilization) diff --git a/src/main/java/org/cloudsimplus/examples/schedulers/SharingHostPEsUsingVmSchedulerSpaceSharedExample.java b/src/main/java/org/cloudsimplus/examples/schedulers/SharingHostPEsUsingVmSchedulerSpaceSharedExample.java index 16c32f5..fb02e71 100755 --- a/src/main/java/org/cloudsimplus/examples/schedulers/SharingHostPEsUsingVmSchedulerSpaceSharedExample.java +++ b/src/main/java/org/cloudsimplus/examples/schedulers/SharingHostPEsUsingVmSchedulerSpaceSharedExample.java @@ -32,8 +32,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerSpaceShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -71,6 +70,13 @@ public class SharingHostPEsUsingVmSchedulerSpaceSharedExample { /// Number of processor elements (CPU cores) of each host. private static final int HOST_PES_NUM = 2; + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_PES_NUM, HOST_MIPS); + /// The total MIPS capacity across all the Host PEs. private static final long HOST_TOTAL_MIPS_CAPACITY = HOST_MIPS*HOST_PES_NUM; @@ -83,7 +89,6 @@ public class SharingHostPEsUsingVmSchedulerSpaceSharedExample { private static final long VM_MIPS = HOST_TOTAL_MIPS_CAPACITY/NUMBER_OF_VMS; private final CloudSimPlus simulation; - private List cloudletList; private List vmList; private int numberOfCreatedCloudlets = 0; @@ -151,14 +156,7 @@ private Host createHost() { final long storage = 1000000; // in Megabytes final long bw = 10000; //in Megabits/s - final var peList = new ArrayList(); - /*Creates the Host's CPU cores and defines the provisioner - used to allocate each core for requesting VMs.*/ - for(int i = 0; i < HOST_PES_NUM; i++){ - peList.add(new PeSimple(HOST_MIPS)); - } - - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerSpaceShared()); + return new HostSimple(ram, bw, storage, HOST_CAPACITY).setVmScheduler(new VmSchedulerSpaceShared()); } private Vm createVm(DatacenterBroker broker, long mips, int pesNumber) { @@ -166,7 +164,7 @@ private Vm createVm(DatacenterBroker broker, long mips, int pesNumber) { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; // vm bandwidth - return new VmSimple(numberOfCreatedVms++, mips, pesNumber) + return new VmSimple(numberOfCreatedVms++, new CoreCapacity(pesNumber, mips)) .setRam(ram).setBw(bw).setSize(storage) .setCloudletScheduler(new CloudletSchedulerTimeShared()); } @@ -174,7 +172,7 @@ private Vm createVm(DatacenterBroker broker, long mips, int pesNumber) { private Cloudlet createCloudlet(DatacenterBroker broker, Vm vm) { final long fileSize = 300; //Size (in bytes) before execution final long outputSize = 300; //Size (in bytes) after execution - final long numberOfCpuCores = vm.getPesNumber(); //cloudlet will use all the VM's CPU cores + final long numberOfCpuCores = vm.getProcessor().getCores(); //cloudlet will use all the VM's CPU cores return new CloudletSimple(numberOfCreatedCloudlets++, CLOUDLET_LENGTH, numberOfCpuCores) .setFileSize(fileSize) diff --git a/src/main/java/org/cloudsimplus/examples/schedulers/SharingHostPEsUsingVmSchedulerTimeSharedExample.java b/src/main/java/org/cloudsimplus/examples/schedulers/SharingHostPEsUsingVmSchedulerTimeSharedExample.java index 741be1f..0fe983d 100755 --- a/src/main/java/org/cloudsimplus/examples/schedulers/SharingHostPEsUsingVmSchedulerTimeSharedExample.java +++ b/src/main/java/org/cloudsimplus/examples/schedulers/SharingHostPEsUsingVmSchedulerTimeSharedExample.java @@ -32,8 +32,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -44,7 +43,7 @@ import java.util.List; /// An example showing how to create 1 host and place multiple VMs at the same -/// [Processor Element (CPU core)][Pe] of it, +/// CPU core of it, /// using a VmSchedulerTimeShared policy at the Host. /// /// The number of VMs to be created will be the double of the Host PEs number. @@ -66,6 +65,13 @@ public class SharingHostPEsUsingVmSchedulerTimeSharedExample { /// Number of processor elements (CPU cores) of each host. private static final int HOST_PES_NUM = 2; + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_PES_NUM, HOST_MIPS); + /// The total MIPS capacity across all the Host PEs. private static final long HOST_TOTAL_MIPS_CAPACITY = HOST_MIPS*HOST_PES_NUM; @@ -146,14 +152,7 @@ private Host createHost() { final long storage = 1000000; // in Megabytes final long bw = 10000; //in Megabits/s - final var peList = new ArrayList(); - /*Creates the Host's CPU cores and defines the provisioner - used to allocate each core for requesting VMs.*/ - for(int i = 0; i < HOST_PES_NUM; i++){ - peList.add(new PeSimple(HOST_MIPS)); - } - - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerTimeShared()); + return new HostSimple(ram, bw, storage, HOST_CAPACITY).setVmScheduler(new VmSchedulerTimeShared()); } private Vm createVm(DatacenterBroker broker, long mips, int pesNumber) { @@ -161,7 +160,7 @@ private Vm createVm(DatacenterBroker broker, long mips, int pesNumber) { final int ram = 512; // vm memory (Megabyte) final long bw = 1000; // vm bandwidth - return new VmSimple(numberOfCreatedVms++, mips, pesNumber) + return new VmSimple(numberOfCreatedVms++, new CoreCapacity(pesNumber, mips)) .setRam(ram).setBw(bw).setSize(storage) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -170,7 +169,7 @@ private Vm createVm(DatacenterBroker broker, long mips, int pesNumber) { private Cloudlet createCloudlet(DatacenterBroker broker, Vm vm) { final long fileSize = 300; //Size (in bytes) before execution final long outputSize = 300; //Size (in bytes) after execution - final long numberOfCpuCores = vm.getPesNumber(); //cloudlet will use all the VM's CPU cores + final long numberOfCpuCores = vm.getProcessor().getCores(); //cloudlet will use all the VM's CPU cores //Defines how CPU, RAM and Bandwidth resources are used //Sets the same utilization model for all these resources. diff --git a/src/main/java/org/cloudsimplus/examples/schedulers/TwoCloudletsAndOneSpaceSharedVmExample.java b/src/main/java/org/cloudsimplus/examples/schedulers/TwoCloudletsAndOneSpaceSharedVmExample.java index 08c8b04..1e378ea 100755 --- a/src/main/java/org/cloudsimplus/examples/schedulers/TwoCloudletsAndOneSpaceSharedVmExample.java +++ b/src/main/java/org/cloudsimplus/examples/schedulers/TwoCloudletsAndOneSpaceSharedVmExample.java @@ -32,8 +32,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerSpaceShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -92,7 +91,7 @@ private TwoCloudletsAndOneSpaceSharedVmExample(){ long bw = 1000; int pesNumber = 1; // number of cpus - final var vm = new VmSimple(vmid, mips, pesNumber) + final var vm = new VmSimple(vmid, new CoreCapacity(pesNumber, mips)) .setRam(ram).setBw(bw).setSize(size) .setCloudletScheduler(new CloudletSchedulerSpaceShared()); vmlist.add(vm); @@ -138,16 +137,15 @@ private TwoCloudletsAndOneSpaceSharedVmExample(){ /// @return the Datacenter private Datacenter createDatacenter() { final var hostList = new ArrayList(); - final var peList = new ArrayList(); final long mips = 1000; - peList.add(new PeSimple(mips)); + final var cpuCapacity = new CoreCapacity(1, mips); final long ram = 20000; //in Megabytes final long bw = 100000; //in Megabytes final long storage = 10000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList) + final var host = new HostSimple(ram, bw, storage, cpuCapacity) .setVmScheduler(new VmSchedulerTimeShared()); hostList.add(host); diff --git a/src/main/java/org/cloudsimplus/examples/schedulers/TwoCloudletsAndOneTimeSharedVmExample.java b/src/main/java/org/cloudsimplus/examples/schedulers/TwoCloudletsAndOneTimeSharedVmExample.java index ffca9c1..eb61b71 100755 --- a/src/main/java/org/cloudsimplus/examples/schedulers/TwoCloudletsAndOneTimeSharedVmExample.java +++ b/src/main/java/org/cloudsimplus/examples/schedulers/TwoCloudletsAndOneTimeSharedVmExample.java @@ -33,8 +33,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; @@ -94,7 +93,7 @@ private TwoCloudletsAndOneTimeSharedVmExample(){ final long bw = 1000; final int pesNumber = 1; // number of cpus - final var vm = new VmSimple(vmid, mips, pesNumber) + final var vm = new VmSimple(vmid, new CoreCapacity(pesNumber, mips)) .setRam(ram).setBw(bw).setSize(size) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -143,16 +142,15 @@ private TwoCloudletsAndOneTimeSharedVmExample(){ /// @return the Datacenter private Datacenter createDatacenter() { final var hostList = new ArrayList(); - final var peList = new ArrayList(); long mips = 1000; - peList.add(new PeSimple(mips)); + final var cpuCapacity = new CoreCapacity(1, mips); final long ram = 20000; //in Megabytes final long bw = 100000; //in Megabytes final long storage = 10000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList) + final var host = new HostSimple(ram, bw, storage, cpuCapacity) .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) .setVmScheduler(new VmSchedulerTimeShared()); diff --git a/src/main/java/org/cloudsimplus/examples/schedulers/VmSchedulerTimeSharedExample.java b/src/main/java/org/cloudsimplus/examples/schedulers/VmSchedulerTimeSharedExample.java index a162c8d..476faa0 100755 --- a/src/main/java/org/cloudsimplus/examples/schedulers/VmSchedulerTimeSharedExample.java +++ b/src/main/java/org/cloudsimplus/examples/schedulers/VmSchedulerTimeSharedExample.java @@ -35,8 +35,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.vm.VmSchedulerSpaceShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.vms.Vm; @@ -83,13 +82,28 @@ public class VmSchedulerTimeSharedExample { private static final long HOST_BW = VM_BW * VMS; //in Megabits/s private static final long HOST_STORAGE = VM_SIZE * VMS; //in Megabytes - private static final int HOST_PES = 2; - private static final int VM_PES = 1; - private static final int CLOUDLET_PES = VM_PES; + private static final int HOST_CORES = 2; + private static final int VM_CORES = 1; + private static final int CLOUDLET_CORES = VM_CORES; private static final int HOST_MIPS = 1000; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + private static final int VM_MIPS = HOST_MIPS/2; + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, VM_MIPS); + private static final int CLOUDLET_LENGTH = HOST_MIPS*10; private final CloudSimPlus simulation; @@ -136,7 +150,7 @@ private VmSchedulerTimeSharedExample() { hostList.forEach(this::printHostStateHistory); for (final var vm : vmList) { - System.out.printf("%s: Requested MIPS: %.0f Allocated MIPS: %.0f%n", vm, vm.getCurrentRequestedMips().totalMips(), vm.getMips()); + System.out.printf("%s: Requested MIPS: %.0f Allocated MIPS: %.0f%n", vm, vm.getCurrentRequestedMips().totalMips(), vm.getProcessor().getMips()); } } @@ -180,13 +194,7 @@ private void createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(HOST_MIPS)); - } - - final var host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList); + final var host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY); host.setStateHistoryEnabled(true) .setVmScheduler(new VmSchedulerTimeShared()); return host; @@ -196,7 +204,7 @@ private Host createHost() { private void createVms() { for (int i = 0; i < VMS; i++) { final var vm = - new VmSimple(VM_MIPS, VM_PES) + new VmSimple(VM_CAPACITY) .setRam(VM_RAM).setBw(VM_BW).setSize(VM_SIZE); vmList.add(vm); } @@ -205,7 +213,7 @@ private void createVms() { /// Creates one Cloudlet for each VM belonging to [#broker0]. private void createCloudlets() { for (final var vm : vmList) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES); cloudlet.setVm(vm); cloudletList.add(cloudlet); } diff --git a/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample1.java b/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample1.java index d51dcdf..2d7f149 100755 --- a/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample1.java +++ b/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample1.java @@ -34,8 +34,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.EventInfo; import org.cloudsimplus.listeners.EventListener; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerSpaceShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -85,6 +84,13 @@ public class PauseSimulationAtGivenTimeExample1 { /// For more details, see [Datacenter#getSchedulingInterval()]. public static final int SCHEDULING_INTERVAL = 1; + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(1, 1000); + private final CloudSimPlus simulation; private final DatacenterBrokerSimple broker; private List cloudletList; @@ -182,17 +188,14 @@ private Host createHost() { final long storage = 1000000; // host storage (Megabyte) final long bw = 10000; //in Megabits/s - final var peList = new ArrayList(); //List of CPU cores - - /*Creates the Host's CPU cores and defines the provisioner - used to allocate each core for requesting VMs.*/ - peList.add(new PeSimple(mips)); + //Defines the number of Host CPU cores and the MIPS capacity of each core + final var cpuCapacity = new CoreCapacity(1, mips); - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerTimeShared()); + return new HostSimple(ram, bw, storage, cpuCapacity).setVmScheduler(new VmSchedulerTimeShared()); } private Vm createVm() { - return new VmSimple(1000, 1) + return new VmSimple(VM_CAPACITY) .setRam(512) .setBw(1000) .setSize(10000) @@ -200,7 +203,7 @@ private Vm createVm() { } private Cloudlet createCloudlet(Vm vm) { - return new CloudletSimple(10000, vm.getPesNumber()) + return new CloudletSimple(10000, vm.getProcessor().getCores()) .setFileSize(300) .setOutputSize(300) .setUtilizationModel(new UtilizationModelFull()) diff --git a/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample2.java b/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample2.java index 6de2d0a..0c3974e 100755 --- a/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample2.java +++ b/src/main/java/org/cloudsimplus/examples/simulationstatus/PauseSimulationAtGivenTimeExample2.java @@ -36,8 +36,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.EventInfo; import org.cloudsimplus.listeners.EventListener; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerSpaceShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -93,6 +92,13 @@ public class PauseSimulationAtGivenTimeExample2 { /// For more details, see [Datacenter#getSchedulingInterval()]. public static final int SCHEDULING_INTERVAL = 1; + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(1, 1000); + private final CloudSimPlus simulation; private final DatacenterBrokerSimple broker; private List cloudletList; @@ -195,17 +201,14 @@ private Host createHost() { final long storage = 1000000; // host storage (Megabyte) final long bw = 10000; //in Megabits/s - final var peList = new ArrayList(); //List of CPU cores - - /*Creates the Host's CPU cores and defines the provisioner - used to allocate each core for requesting VMs.*/ - peList.add(new PeSimple(mips)); + //Defines the number of Host CPU cores and the MIPS capacity of each core + final var cpuCapacity = new CoreCapacity(1, mips); - return new HostSimple(ram, bw, storage, peList).setVmScheduler(new VmSchedulerTimeShared()); + return new HostSimple(ram, bw, storage, cpuCapacity).setVmScheduler(new VmSchedulerTimeShared()); } private Vm createVm() { - return new VmSimple(1000, 1) + return new VmSimple(VM_CAPACITY) .setRam(512) .setBw(1000) .setSize(10000) @@ -213,7 +216,7 @@ private Vm createVm() { } private Cloudlet createCloudlet(Vm vm) { - return new CloudletSimple(10000, vm.getPesNumber()) + return new CloudletSimple(10000, vm.getProcessor().getCores()) .setFileSize(300) .setOutputSize(300) .setUtilizationModel(new UtilizationModelFull()) diff --git a/src/main/java/org/cloudsimplus/examples/simulationstatus/TerminateSimulationAtGivenConditionExample.java b/src/main/java/org/cloudsimplus/examples/simulationstatus/TerminateSimulationAtGivenConditionExample.java index 9947b3b..f4b9a7a 100755 --- a/src/main/java/org/cloudsimplus/examples/simulationstatus/TerminateSimulationAtGivenConditionExample.java +++ b/src/main/java/org/cloudsimplus/examples/simulationstatus/TerminateSimulationAtGivenConditionExample.java @@ -35,8 +35,7 @@ import org.cloudsimplus.listeners.CloudletVmEventInfo; import org.cloudsimplus.listeners.EventListener; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerSpaceShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; @@ -147,13 +146,10 @@ private Host createHost() { final long storage = 1000000; // in Megabytes final long bw = 10000; //in Megabits/s - final var peList = new ArrayList(); //List of CPU cores + //Defines the number of Host CPU cores and the MIPS capacity of each core + final var cpuCapacity = new CoreCapacity(1, mips); - /*Creates the Host's CPU cores and defines the provisioner - used to allocate each core for requesting VMs.*/ - peList.add(new PeSimple(mips)); - - return new HostSimple(ram, bw, storage, peList) + return new HostSimple(ram, bw, storage, cpuCapacity) .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) .setVmScheduler(new VmSchedulerTimeShared()); @@ -166,7 +162,7 @@ private Vm createVm(DatacenterBroker broker) { final long bw = 1000; // vm bandwidth (Megabits/s) final int pesNumber = 1; // number of CPU cores - return new VmSimple(numberOfCreatedVms++, mips, pesNumber) + return new VmSimple(numberOfCreatedVms++, new CoreCapacity(pesNumber, mips)) .setRam(ram) .setBw(bw) .setSize(storage) @@ -177,7 +173,7 @@ private Cloudlet createCloudlet(DatacenterBroker broker, Vm vm) { final long length = 10000; //in Million Instructions (MI) final long fileSize = 300; //Size (in bytes) before execution final long outputSize = 300; //Size (in bytes) after execution - final long numberOfCpuCores = vm.getPesNumber(); //cloudlet will use all the VM's CPU cores + final long numberOfCpuCores = vm.getProcessor().getCores(); //cloudlet will use all the VM's CPU cores //Defines how CPU, RAM and Bandwidth resources are used //Sets the same utilization model for all these resources. diff --git a/src/main/java/org/cloudsimplus/examples/simulationstatus/TerminateSimulationAtGivenTimeExample.java b/src/main/java/org/cloudsimplus/examples/simulationstatus/TerminateSimulationAtGivenTimeExample.java index d0862e2..a6d8f6d 100755 --- a/src/main/java/org/cloudsimplus/examples/simulationstatus/TerminateSimulationAtGivenTimeExample.java +++ b/src/main/java/org/cloudsimplus/examples/simulationstatus/TerminateSimulationAtGivenTimeExample.java @@ -32,8 +32,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerSpaceShared; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; @@ -122,20 +121,17 @@ private Host createHost() { final long storage = 1000000; // in Megabytes final long bw = 10000; //in Megabits/s - final var peList = new ArrayList(); //List of CPU cores + //Defines the number of Host CPU cores and the MIPS capacity of each core + final var cpuCapacity = new CoreCapacity(1, mips); - /*Creates the Host's CPU cores and defines the provisioner - used to allocate each core for requesting VMs.*/ - peList.add(new PeSimple(mips)); - - return new HostSimple(ram, bw, storage, peList); + return new HostSimple(ram, bw, storage, cpuCapacity); } private Vm createVm(DatacenterBroker broker) { final long mips = 1000; final int pesNumber = 1; // number of CPU cores - return new VmSimple(numberOfCreatedVms++, mips, pesNumber) + return new VmSimple(numberOfCreatedVms++, new CoreCapacity(pesNumber, mips)) .setRam(512) .setBw((long) 1000) .setSize((long) 10000) @@ -144,7 +140,7 @@ private Vm createVm(DatacenterBroker broker) { private Cloudlet createCloudlet(DatacenterBroker broker, Vm vm) { final long length = 10000; //in Million Instructions (MI) - final long numberOfCpuCores = vm.getPesNumber(); //cloudlet will use all the VM's CPU cores + final long numberOfCpuCores = vm.getProcessor().getCores(); //cloudlet will use all the VM's CPU cores return new CloudletSimple( numberOfCreatedCloudlets++, length, numberOfCpuCores) diff --git a/src/main/java/org/cloudsimplus/examples/sla/VmMigrationWhenCpuMetricIsViolatedExample.java b/src/main/java/org/cloudsimplus/examples/sla/VmMigrationWhenCpuMetricIsViolatedExample.java index 72a7cc9..856c273 100755 --- a/src/main/java/org/cloudsimplus/examples/sla/VmMigrationWhenCpuMetricIsViolatedExample.java +++ b/src/main/java/org/cloudsimplus/examples/sla/VmMigrationWhenCpuMetricIsViolatedExample.java @@ -36,8 +36,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.power.models.PowerModelHostSimple; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.selectionpolicies.VmSelectionPolicyMinimumUtilization; @@ -70,6 +69,13 @@ public final class VmMigrationWhenCpuMetricIsViolatedExample { private static final long VM_BW = 100000; private static final int VM_PES_NUM = 3; //number of cpus + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_PES_NUM, VM_MIPS); + private static final long CLOUDLET_LENGHT = 20000; private static final long CLOUDLET_FILESIZE = 300; private static final long CLOUDLET_OUTPUTSIZE = 300; @@ -155,7 +161,7 @@ private void createAndSubmitVms(final DatacenterBroker broker) { } private Vm createVm() { - final Vm vm = new VmSimple(vmList.size(), VM_MIPS, VM_PES_NUM); + final Vm vm = new VmSimple(vmList.size(), VM_CAPACITY); vm.setRam(VM_RAM).setBw(VM_BW).setSize(VM_SIZE) .setCloudletScheduler(new CloudletSchedulerTimeShared()); return vm; @@ -178,7 +184,6 @@ private void createAndSubmitCloudlets( maxCloudletCpuUsagePercent, progressiveCpuUsage); - final Cloudlet c = new CloudletSimple( cloudletId, CLOUDLET_LENGHT, 2) @@ -269,8 +274,8 @@ private Datacenter createDatacenter() { } private Host createHost(final int pesNumber, final long mipsByPe) { - final var peList = createPeList(pesNumber, mipsByPe); - final var host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList); + final var cpuCapacity = new CoreCapacity(pesNumber, mipsByPe); + final var host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, cpuCapacity); host.setPowerModel(new PowerModelHostSimple(1000, 700)); host.setRamProvisioner(new ResourceProvisionerSimple()); host.setBwProvisioner(new ResourceProvisionerSimple()); @@ -278,11 +283,4 @@ private Host createHost(final int pesNumber, final long mipsByPe) { return host; } - private List createPeList(final int numberOfPEs, final long mips) { - final var peList = new ArrayList(numberOfPEs); - for (int i = 0; i < numberOfPEs; i++) { - peList.add(new PeSimple(mips)); - } - return peList; - } } diff --git a/src/main/java/org/cloudsimplus/examples/synchronous/SynchronousSimulationExample1.java b/src/main/java/org/cloudsimplus/examples/synchronous/SynchronousSimulationExample1.java index 142530f..9a92360 100755 --- a/src/main/java/org/cloudsimplus/examples/synchronous/SynchronousSimulationExample1.java +++ b/src/main/java/org/cloudsimplus/examples/synchronous/SynchronousSimulationExample1.java @@ -34,8 +34,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.util.Log; import org.cloudsimplus.utilizationmodels.UtilizationModelFull; import org.cloudsimplus.vms.Vm; @@ -67,13 +66,27 @@ public class SynchronousSimulationExample1 { /// The clock is increased in the interval defined here. private static final double INTERVAL = 2; private static final int HOSTS = 2; - private static final int HOST_PES = 4; + private static final int HOST_CORES = 4; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 4; - private static final int VM_PES = 2; + private static final int VM_CORES = 2; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, 1000); private static final int CLOUDLETS = 8; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 10000; private final CloudSimPlus simulation; @@ -152,13 +165,6 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - for (int i = 0; i < HOST_PES; i++) { - //Uses a PeProvisionerSimple by default to provision PEs for VMs - peList.add(new PeSimple(1000)); - } - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes @@ -167,7 +173,7 @@ private Host createHost() { Uses ResourceProvisionerSimple by default for RAM and BW provisioning and VmSchedulerSpaceShared for VM scheduling. */ - return new HostSimple(ram, bw, storage, peList); + return new HostSimple(ram, bw, storage, HOST_CAPACITY); } /// Creates a list of VMs. @@ -175,7 +181,7 @@ private List createVms() { final var list = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets - final Vm vm = new VmSimple(1000, VM_PES); + final Vm vm = new VmSimple(VM_CAPACITY); vm.setRam(512).setBw(1000).setSize(10000); list.add(vm); } @@ -188,7 +194,7 @@ private List createCloudlets() { final var list = new ArrayList(CLOUDLETS); for (int i = 0; i < CLOUDLETS; i++) { - final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES); + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_CORES); cloudlet.setUtilizationModelCpu(new UtilizationModelFull()) .setSizes(1024) .setSubmissionDelay(i); diff --git a/src/main/java/org/cloudsimplus/examples/traces/PlanetLabExample1.java b/src/main/java/org/cloudsimplus/examples/traces/PlanetLabExample1.java index 44471f2..0f02e39 100755 --- a/src/main/java/org/cloudsimplus/examples/traces/PlanetLabExample1.java +++ b/src/main/java/org/cloudsimplus/examples/traces/PlanetLabExample1.java @@ -33,10 +33,8 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.provisioners.PeProvisionerSimple; import org.cloudsimplus.provisioners.ResourceProvisionerSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerTimeShared; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.util.TimeUtil; @@ -48,7 +46,6 @@ import java.time.LocalTime; import java.util.ArrayList; import java.util.List; -import java.util.stream.IntStream; /// An example showing how to use the [UtilizationModelPlanetLab] class /// to define Cloudlets' CPU utilization based on [PlanetLab's](https://www.planet-lab.org) trace files. @@ -58,14 +55,28 @@ /// @since CloudSim Plus 4.0.0 public class PlanetLabExample1 { private static final int HOSTS = 3; - private static final int HOST_PES = 10; + private static final int HOST_CORES = 10; + + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, 1000); private static final int VMS = 4; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; private static final int VM_MIPS = 1000; + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, VM_MIPS); + private static final int CLOUDLETS = 4; - private static final int CLOUDLET_PES = 2; + private static final int CLOUDLET_CORES = 2; private static final int CLOUDLET_LENGTH = 100000000; private static final String TRACE_FILE = "workload/planetlab/20110303/75-130-96-12_static_oxfr_ma_charter_com_irisaple_wup"; @@ -129,14 +140,10 @@ private Datacenter createDatacenter() { } private Host createHost() { - final var peList = new ArrayList(HOST_PES); - //List of Host's CPUs (Processing Elements, PEs) - IntStream.range(0, HOST_PES).forEach(i -> peList.add(new PeSimple(1000, new PeProvisionerSimple()))); - final long ram = 2048; //in Megabytes final long bw = 10000; //in Megabits/s final long storage = 1000000; //in Megabytes - final var host = new HostSimple(ram, bw, storage, peList); + final var host = new HostSimple(ram, bw, storage, HOST_CAPACITY); host .setRamProvisioner(new ResourceProvisionerSimple()) .setBwProvisioner(new ResourceProvisionerSimple()) @@ -149,7 +156,7 @@ private List createVms() { final var list = new ArrayList(VMS); for (int i = 0; i < VMS; i++) { final var vm = - new VmSimple(i, VM_MIPS, VM_PES) + new VmSimple(i, VM_CAPACITY) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); @@ -167,7 +174,7 @@ private List createCloudlets() { final var utilizationCpu = UtilizationModelPlanetLab.getInstance(TRACE_FILE, SCHEDULING_INTERVAL); for (int i = 0; i < CLOUDLETS; i++) { final var cloudlet = - new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_PES) + new CloudletSimple(i, CLOUDLET_LENGTH, CLOUDLET_CORES) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelCpu(utilizationCpu) diff --git a/src/main/java/org/cloudsimplus/examples/traces/SwfWorkloadFormatExample1.java b/src/main/java/org/cloudsimplus/examples/traces/SwfWorkloadFormatExample1.java index d288ff4..fd09fe7 100755 --- a/src/main/java/org/cloudsimplus/examples/traces/SwfWorkloadFormatExample1.java +++ b/src/main/java/org/cloudsimplus/examples/traces/SwfWorkloadFormatExample1.java @@ -35,8 +35,7 @@ import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.DatacenterBrokerEventInfo; import org.cloudsimplus.listeners.EventListener; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerSpaceShared; import org.cloudsimplus.traces.SwfWorkloadFileReader; import org.cloudsimplus.traces.TraceReaderAbstract; @@ -85,10 +84,18 @@ public class SwfWorkloadFormatExample1 { /// will be created as one cloudlet. private int maxCloudletsToCreateFromWorkloadFile = Integer.MAX_VALUE; - private final int HOST_PES = 12; + private final int HOST_CORES = 12; private static final int VM_MIPS = 10000; - private static final int VM_PES = 4; + private static final int VM_CORES = 4; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, VM_MIPS); + private static final long VM_SIZE = 2000; private static final int VM_RAM = 1000; private static final long VM_BW = 50000; @@ -161,13 +168,13 @@ private void sleep(final long seconds) { /// Creates a list of VMs according to the number of Cloudlets, /// in order to try accommodating all Cloudlets into those VMs. private void createVms() { - final double totalCloudletPes = cloudletList.stream().mapToDouble(Cloudlet::getPesNumber).sum(); - /* The number to multiply the VM_PES was chosen at random. + final double totalCloudletCores = cloudletList.stream().mapToDouble(Cloudlet::getRequiredCores).sum(); + /* The number to multiply the VM_CORES was chosen at random. * It's used to reduce the number of VMs to create. */ - final int totalVms = (int)Math.ceil(totalCloudletPes / (VM_PES*6)); + final int totalVms = (int)Math.ceil(totalCloudletCores / (VM_CORES*6)); for (int i = 0; i < totalVms; i++) { - final var vm = new VmSimple(VM_MIPS, VM_PES) + final var vm = new VmSimple(VM_CAPACITY) .setRam(VM_RAM).setBw(VM_BW).setSize(VM_SIZE) .setCloudletScheduler(new CloudletSchedulerSpaceShared()); vmlist.add(vm); @@ -207,20 +214,12 @@ private List createHosts(final long hostsNumber) { final var hostList = new ArrayList((int)hostsNumber); for (int i = 0; i < hostsNumber; i++) { - List peList = createPeList(VM_MIPS); - final var host = new HostSimple(ram, bw, storage, peList); + CoreCapacity cpuCapacity = new CoreCapacity(HOST_CORES, VM_MIPS); + final var host = new HostSimple(ram, bw, storage, cpuCapacity); hostList.add(host); } return hostList; } - private List createPeList(final long mips) { - final var peList = new ArrayList(HOST_PES); - for (int i = 0; i < HOST_PES; i++) { - peList.add(new PeSimple(mips)); - } - - return peList; - } } diff --git a/src/main/java/org/cloudsimplus/examples/traces/google/GoogleMachineEventsExample1.java b/src/main/java/org/cloudsimplus/examples/traces/google/GoogleMachineEventsExample1.java index 0de74d2..fe051ef 100755 --- a/src/main/java/org/cloudsimplus/examples/traces/google/GoogleMachineEventsExample1.java +++ b/src/main/java/org/cloudsimplus/examples/traces/google/GoogleMachineEventsExample1.java @@ -36,8 +36,7 @@ import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; import org.cloudsimplus.listeners.HostEventInfo; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.cloudlet.CloudletSchedulerSpaceShared; import org.cloudsimplus.traces.TraceReaderAbstract; import org.cloudsimplus.traces.google.GoogleMachineEventsTraceReader; @@ -172,20 +171,11 @@ private void createDatacenters() { /// @param event an object containing the trace line read, used to create the Host. /// @return private Host createHost(final MachineEvent event) { - final Host host = new HostSimple(event.getRam(), HOST_BW, HOST_STORAGE, createPesList(event.getCpuCores())); + final Host host = new HostSimple(event.getRam(), HOST_BW, HOST_STORAGE, new CoreCapacity(event.getCpuCores(), HOST_MIPS)); host.setId(event.getMachineId()); return host; } - private List createPesList(final int count) { - List cpuCoresList = new ArrayList<>(count); - for(int i = 0; i < count; i++){ - cpuCoresList.add(new PeSimple(HOST_MIPS)); - } - - return cpuCoresList; - } - /// Creates a list of VMs and Cloudlets in a given Datacenter. private List createAndSubmitVms(Datacenter datacenter) { final var list = new ArrayList(datacenter.getHostList().size()); @@ -204,7 +194,7 @@ private List createAndSubmitVms(Datacenter datacenter) { /// @param host /// @return private Vm createVm(final Host host) { - return new VmSimple(1000, host.getPesNumber()) + return new VmSimple(new CoreCapacity(host.getProcessor().getCores(), 1000)) .setRam(host.getRam().getCapacity()).setBw(HOST_BW).setSize(HOST_STORAGE) .setCloudletScheduler(new CloudletSchedulerSpaceShared()); } @@ -222,7 +212,7 @@ private void createAndSubmitCloudlets(final List vmList) { private Cloudlet createCloudlet(Vm vm) { final var utilization = new UtilizationModelFull(); - return new CloudletSimple(CLOUDLET_LENGTH, vm.getPesNumber()) + return new CloudletSimple(CLOUDLET_LENGTH, vm.getProcessor().getCores()) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModel(utilization) diff --git a/src/main/java/org/cloudsimplus/examples/traces/google/GoogleTaskEventsExample1.java b/src/main/java/org/cloudsimplus/examples/traces/google/GoogleTaskEventsExample1.java index fbf84cb..82ddddc 100755 --- a/src/main/java/org/cloudsimplus/examples/traces/google/GoogleTaskEventsExample1.java +++ b/src/main/java/org/cloudsimplus/examples/traces/google/GoogleTaskEventsExample1.java @@ -35,8 +35,7 @@ import org.cloudsimplus.datacenters.DatacenterSimple; import org.cloudsimplus.hosts.Host; import org.cloudsimplus.hosts.HostSimple; -import org.cloudsimplus.resources.Pe; -import org.cloudsimplus.resources.PeSimple; +import org.cloudsimplus.resources.CoreCapacity; import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared; import org.cloudsimplus.traces.TraceReaderAbstract; import org.cloudsimplus.traces.google.BrokerManager; @@ -91,12 +90,19 @@ public class GoogleTaskEventsExample1 { private static final int HOSTS = 10; private static final int VMS = 8; - private static final int HOST_PES = 8; + private static final int HOST_CORES = 8; private static final long HOST_RAM = 2048; //in Megabytes private static final long HOST_BW = 10000; //in Megabits/s private static final long HOST_STORAGE = 1000000; //in Megabytes private static final double HOST_MIPS = 1000; + /// The CPU capacity of every Host: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each Host copies its values into its own Processor. + /// So, changing the capacity of one Host's Processor doesn't affect the other Hosts. + /// Reusing it avoids creating one temporary object per Host (fewer allocations and less GC work in large simulations). + private static final CoreCapacity HOST_CAPACITY = new CoreCapacity(HOST_CORES, HOST_MIPS); + /// Defines a negative length for Cloudlets created from the Google Task Events Trace file, /// so that they can run indefinitely until a [CloudSimTag#CLOUDLET_FINISH] /// event is received by the [DatacenterBroker]. @@ -107,8 +113,16 @@ public class GoogleTaskEventsExample1 { /// @see GoogleTaskEventsTraceReader#setMaxCloudletsToCreate(int) private static final int MAX_CLOUDLETS = 8; - private static final long VM_PES = 4; + private static final long VM_CORES = 4; private static final int VM_MIPS = 1000; + + /// The CPU capacity of every VM: a single [CoreCapacity] object is reused for all of them. + /// That's safe because a [CoreCapacity] is immutable: it never changes after it's created, + /// and each VM copies its values into its own Processor. + /// So, changing the capacity of one VM (such as by vertical scaling) doesn't affect the other VMs. + /// Reusing it avoids creating one temporary object per VM (fewer allocations and less GC work in large simulations). + private static final CoreCapacity VM_CAPACITY = new CoreCapacity(VM_CORES, VM_MIPS); + private static final long VM_RAM = 500; //in Megabytes private static final long VM_BW = 100; //in Megabits/s private static final long VM_SIZE_MB = 1000; //in Megabytes @@ -197,7 +211,7 @@ private Cloudlet createCloudlet(final TaskEvent event) { This is different from the CPU UtilizationModel, which is defined in the "task usage" trace files. */ - final long pesNumber = positive(event.actualCpuCores(VM_PES), VM_PES); + final long pesNumber = positive(event.actualCpuCores(VM_CORES), VM_CORES); final double maxRamUsagePercent = positive(event.getResourceRequestForRam(), Conversion.HUNDRED_PERCENT); final var utilizationRam = new UtilizationModelDynamic(0, maxRamUsagePercent); @@ -244,30 +258,19 @@ private long getCloudletSizeInMB(final Cloudlet cloudlet) { } private Host createHost() { - final var peList = createPesList(HOST_PES); //Uses a ResourceProvisionerSimple for RAM and BW - final Host host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList); + final Host host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, HOST_CAPACITY); host.setVmScheduler(new VmSchedulerTimeShared()); return host; } - private List createPesList(final int count) { - final var peList = new ArrayList(count); - for(int i = 0; i < count; i++){ - //Uses a PeProvisionerSimple by default - peList.add(new PeSimple(HOST_MIPS)); - } - - return peList; - } - private List createVms() { return IntStream.range(0, VMS).mapToObj(i -> createVm()).toList(); } private Vm createVm() { //Uses a CloudletSchedulerTimeShared by default - return new VmSimple(VM_MIPS, VM_PES).setRam(VM_RAM).setBw(VM_BW).setSize(VM_SIZE_MB); + return new VmSimple(VM_CAPACITY).setRam(VM_RAM).setBw(VM_BW).setSize(VM_SIZE_MB); } private void printCloudlets(final DatacenterBroker broker) {