Skip to content

Commit 63f60ff

Browse files
committed
Close #14
- Introduces PowerSpecFileExample after cloudsimplus/cloudsimplus#430 - Adds power consumption specification files to src/main/resources/power-specs - Refactor SwfWorkloadFormatExample1 and update docs - Update to CloudSim Plus 8.1.0 Signed-off-by: Manoel Campos <[email protected]>
1 parent 31302f1 commit 63f60ff

12 files changed

+349
-7
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
The module version defines the version of CloudSim Plus to be used.
99
This way, it cannot be a version number which doesn't exist for CloudSim Plus.
1010
-->
11-
<version>8.0.0</version>
11+
<version>8.1.0</version>
1212

1313
<name>CloudSim Plus Examples</name>
1414
<description>

src/main/java/org/cloudsimplus/examples/power/PowerExample.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
* @author Manoel Campos da Silva Filho
8888
* @since CloudSim Plus 1.2.4
8989
*
90+
* @see PowerSpecFileExample
9091
* @see VmsRamAndBwUsageExample
9192
* @see org.cloudsimplus.examples.resourceusage.VmsCpuUsageExample
9293
*/
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
/*
2+
* CloudSim Plus: A modern, highly-extensible and easier-to-use Framework for
3+
* Modeling and Simulation of Cloud Computing Infrastructures and Services.
4+
* http://cloudsimplus.org
5+
*
6+
* Copyright (C) 2015-2021 Universidade da Beira Interior (UBI, Portugal) and
7+
* the Instituto Federal de Educação Ciência e Tecnologia do Tocantins (IFTO, Brazil).
8+
*
9+
* This file is part of CloudSim Plus.
10+
*
11+
* CloudSim Plus is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU General Public License as published by
13+
* the Free Software Foundation, either version 3 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* CloudSim Plus is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with CloudSim Plus. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
package org.cloudsimplus.examples.power;
25+
26+
import org.cloudsimplus.brokers.DatacenterBroker;
27+
import org.cloudsimplus.brokers.DatacenterBrokerSimple;
28+
import org.cloudsimplus.builders.tables.CloudletsTableBuilder;
29+
import org.cloudsimplus.cloudlets.Cloudlet;
30+
import org.cloudsimplus.cloudlets.CloudletSimple;
31+
import org.cloudsimplus.core.CloudSimPlus;
32+
import org.cloudsimplus.datacenters.Datacenter;
33+
import org.cloudsimplus.datacenters.DatacenterSimple;
34+
import org.cloudsimplus.hosts.Host;
35+
import org.cloudsimplus.hosts.HostSimple;
36+
import org.cloudsimplus.power.models.PowerModelHostSpec;
37+
import org.cloudsimplus.resources.Pe;
38+
import org.cloudsimplus.resources.PeSimple;
39+
import org.cloudsimplus.schedulers.vm.VmSchedulerTimeShared;
40+
import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic;
41+
import org.cloudsimplus.utilizationmodels.UtilizationModelFull;
42+
import org.cloudsimplus.vms.HostResourceStats;
43+
import org.cloudsimplus.vms.Vm;
44+
import org.cloudsimplus.vms.VmSimple;
45+
46+
import java.util.ArrayList;
47+
import java.util.Arrays;
48+
import java.util.Comparator;
49+
import java.util.List;
50+
51+
import static java.util.Comparator.comparingLong;
52+
53+
/**
54+
* An example to show power consumption of Hosts
55+
* using the specifications from a file created based on
56+
* <a href="https://www.specs.org">www.specs.org</a> website public data.
57+
* Realize that for this goal, you define a {@link PowerModelHostSpec}
58+
* for each Host by calling {@code host.setPowerModel(powerModel)}.
59+
*
60+
* @author Manoel Campos da Silva Filho
61+
* @since CloudSim Plus 8.1.0
62+
*
63+
* @see #POWER_SPEC_FILE
64+
* @see #createPowerHost(int)
65+
* @see PowerExample
66+
*/
67+
public class PowerSpecFileExample {
68+
/**
69+
* Defines, between other things, the time intervals
70+
* to keep Hosts CPU utilization history records.
71+
*/
72+
private static final int SCHEDULING_INTERVAL = 10;
73+
private static final int HOSTS = 2;
74+
private static final int HOST_PES = 8;
75+
76+
/** Indicates the time (in seconds) the Host takes to start up. */
77+
private static final double HOST_START_UP_DELAY = 5;
78+
79+
/** Indicates the time (in seconds) the Host takes to shut down. */
80+
private static final double HOST_SHUT_DOWN_DELAY = 3;
81+
82+
/** Indicates Host power consumption (in Watts) during startup. */
83+
private static final double HOST_START_UP_POWER = 5;
84+
85+
/** Indicates Host power consumption (in Watts) during shutdown. */
86+
private static final double HOST_SHUT_DOWN_POWER = 3;
87+
88+
private static final int VMS = 4;
89+
private static final int VM_PES = 4;
90+
91+
private static final int CLOUDLETS = 8;
92+
private static final int CLOUDLET_PES = 2;
93+
private static final int CLOUDLET_LENGTH = 50000;
94+
95+
/**
96+
* The path to the file containing host power utilization specs.
97+
*/
98+
private static final String POWER_SPEC_FILE = "power-specs/PowerModelSpecPowerHpProLiantMl110G3PentiumD930.txt";
99+
100+
private final CloudSimPlus simulation;
101+
private final DatacenterBroker broker0;
102+
private List<Vm> vmList;
103+
private List<Cloudlet> cloudletList;
104+
private Datacenter datacenter0;
105+
private final List<Host> hostList;
106+
107+
/**
108+
* Indicates how hosts consume power according to CPU utilization percentage
109+
* (based on data from a power spec file).
110+
* This attribute is used just to ensure the same data will be read just once
111+
* and used for all created Hosts.
112+
*/
113+
private final PowerModelHostSpec DEF_POWER_MODEL = PowerModelHostSpec.getInstance(POWER_SPEC_FILE);
114+
115+
public static void main(String[] args) {
116+
new PowerSpecFileExample();
117+
}
118+
119+
private PowerSpecFileExample() {
120+
/*Enables just some level of log messages.
121+
Make sure to import org.cloudsimplus.util.Log;*/
122+
//Log.setLevel(ch.qos.logback.classic.Level.WARN);
123+
124+
simulation = new CloudSimPlus();
125+
hostList = new ArrayList<>(HOSTS);
126+
datacenter0 = createDatacenter();
127+
//Creates a broker that is a software acting on behalf of a cloud customer to manage his/her VMs and Cloudlets
128+
broker0 = new DatacenterBrokerSimple(simulation);
129+
130+
vmList = createVms();
131+
cloudletList = createCloudlets();
132+
broker0.submitVmList(vmList);
133+
broker0.submitCloudletList(cloudletList);
134+
135+
simulation.start();
136+
137+
System.out.println("------------------------------- SIMULATION FOR SCHEDULING INTERVAL = " + SCHEDULING_INTERVAL+" -------------------------------");
138+
final var cloudletFinishedList = broker0.getCloudletFinishedList();
139+
final Comparator<Cloudlet> hostComparator = comparingLong(cl -> cl.getVm().getHost().getId());
140+
cloudletFinishedList.sort(hostComparator.thenComparing(cl -> cl.getVm().getId()));
141+
142+
new CloudletsTableBuilder(cloudletFinishedList).build();
143+
printHostsCpuUtilizationAndPowerConsumption();
144+
}
145+
146+
/**
147+
* The Host CPU Utilization History is only computed
148+
* if VMs utilization history is enabled by calling
149+
* {@code vm.getUtilizationHistory().enable()}.
150+
*/
151+
private void printHostsCpuUtilizationAndPowerConsumption() {
152+
System.out.println();
153+
for (final Host host : hostList) {
154+
printHostCpuUtilizationAndPowerConsumption(host);
155+
}
156+
System.out.println();
157+
}
158+
159+
private void printHostCpuUtilizationAndPowerConsumption(final Host host) {
160+
final HostResourceStats cpuStats = host.getCpuUtilizationStats();
161+
162+
//The total Host's CPU utilization for the time specified by the map key
163+
final double utilizationPercentMean = cpuStats.getMean();
164+
final double watts = host.getPowerModel().getPower(utilizationPercentMean);
165+
System.out.printf(
166+
"Host %2d CPU Usage mean: %6.1f%% | Power Consumption mean: %8.0f W%n",
167+
host.getId(), utilizationPercentMean * 100, watts);
168+
}
169+
170+
/**
171+
* Creates a {@link Datacenter} and its {@link Host}s.
172+
*/
173+
private Datacenter createDatacenter() {
174+
for(int i = 0; i < HOSTS; i++) {
175+
final var host = createPowerHost(i);
176+
hostList.add(host);
177+
}
178+
179+
final var dc = new DatacenterSimple(simulation, hostList);
180+
dc.setSchedulingInterval(SCHEDULING_INTERVAL);
181+
return dc;
182+
}
183+
184+
private Host createPowerHost(final int id) {
185+
final var peList = new ArrayList<Pe>(HOST_PES);
186+
//List of Host's CPUs (Processing Elements, PEs)
187+
for (int i = 0; i < HOST_PES; i++) {
188+
peList.add(new PeSimple(1000));
189+
}
190+
191+
final long ram = 2048; //in Megabytes
192+
final long bw = 10000; //in Megabits/s
193+
final long storage = 1000000; //in Megabytes
194+
final var vmScheduler = new VmSchedulerTimeShared();
195+
196+
final var host = new HostSimple(ram, bw, storage, peList);
197+
198+
final var powerModel = new PowerModelHostSpec(DEF_POWER_MODEL.getPowerSpecs());
199+
powerModel.setStartupDelay(HOST_START_UP_DELAY)
200+
.setShutDownDelay(HOST_SHUT_DOWN_DELAY)
201+
.setStartupPower(HOST_START_UP_POWER)
202+
.setShutDownPower(HOST_SHUT_DOWN_POWER);
203+
System.out.println(Arrays.toString(powerModel.getPowerSpecs()));
204+
205+
host.setId(id)
206+
.setVmScheduler(vmScheduler)
207+
.setPowerModel(powerModel);
208+
host.enableUtilizationStats();
209+
210+
return host;
211+
}
212+
213+
/**
214+
* Creates a list of VMs.
215+
*/
216+
private List<Vm> createVms() {
217+
final var list = new ArrayList<Vm>(VMS);
218+
for (int i = 0; i < VMS; i++) {
219+
final var vm = new VmSimple(i, 1000, VM_PES);
220+
vm.setRam(512).setBw(1000).setSize(10000);
221+
list.add(vm);
222+
}
223+
224+
return list;
225+
}
226+
227+
/**
228+
* Creates a list of Cloudlets.
229+
*/
230+
private List<Cloudlet> createCloudlets() {
231+
final var cloudletList = new ArrayList<Cloudlet>(CLOUDLETS);
232+
final var utilization = new UtilizationModelDynamic(0.2);
233+
for (int i = 0; i < CLOUDLETS; i++) {
234+
//Sets half of the cloudlets with the defined length and the other half with the double of it
235+
final long length = i < CLOUDLETS / 2 ? CLOUDLET_LENGTH : CLOUDLET_LENGTH * 2;
236+
final var cloudlet =
237+
new CloudletSimple(i, length, CLOUDLET_PES)
238+
.setFileSize(1024)
239+
.setOutputSize(1024)
240+
.setUtilizationModelCpu(new UtilizationModelFull())
241+
.setUtilizationModelRam(utilization)
242+
.setUtilizationModelBw(utilization);
243+
cloudletList.add(cloudlet);
244+
}
245+
246+
return cloudletList;
247+
}
248+
}

src/main/java/org/cloudsimplus/examples/traces/SwfWorkloadFormatExample1.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
* at the developer machine and can <b>spend a long time to finish</b>,
6464
* the example allow to limit the maximum number of cloudlets to be submitted
6565
* to the DatacenterBroker.
66-
* See the {@link #maximumNumberOfCloudletsToCreateFromTheWorkloadFile} attribute for more details.
66+
* See the {@link #maxCloudletsToCreateFromWorkloadFile} attribute for more details.
6767
* </p>
6868
*
6969
* <p>
@@ -91,10 +91,10 @@ public class SwfWorkloadFormatExample1 {
9191
/**
9292
* Defines the maximum number of cloudlets to be created
9393
* from the given workload file.
94-
* The value -1 indicates that every job inside the workload file
94+
* {@link Integer#MAX_VALUE} indicates that every job inside the workload file
9595
* will be created as one cloudlet.
9696
*/
97-
private int maximumNumberOfCloudletsToCreateFromTheWorkloadFile = -1;
97+
private int maxCloudletsToCreateFromWorkloadFile = Integer.MAX_VALUE;
9898

9999
private final int HOST_PES = 12;
100100

@@ -150,7 +150,6 @@ private SwfWorkloadFormatExample1() {
150150
final var cloudletFinishedList = broker.getCloudletFinishedList();
151151
new CloudletsTableBuilder(cloudletFinishedList).build();
152152

153-
System.out.println(getClass().getSimpleName() + " finished!");
154153
System.out.printf("Simulation finished at %s. Execution time: %.2f seconds%n", LocalTime.now(), TimeUtil.elapsedSeconds(startSecs));
155154
} catch (Exception e) {
156155
System.out.printf("Error during simulation execution: %s%n", e.getMessage());
@@ -181,7 +180,7 @@ private void sleep(final long seconds) {
181180
*/
182181
private void createVms() {
183182
final double totalCloudletPes = cloudletList.stream().mapToDouble(Cloudlet::getPesNumber).sum();
184-
/* The number to multiple the VM_PES was chosen at random.
183+
/* The number to multiply the VM_PES was chosen at random.
185184
* It's used to reduce the number of VMs to create. */
186185
final int totalVms = (int)Math.ceil(totalCloudletPes / (VM_PES*6));
187186

@@ -198,7 +197,7 @@ private void createVms() {
198197

199198
private void createCloudletsFromWorkloadFile() {
200199
final var reader = SwfWorkloadFileReader.getInstance(WORKLOAD_FILENAME, VM_MIPS);
201-
reader.setMaxLinesToRead(maximumNumberOfCloudletsToCreateFromTheWorkloadFile);
200+
reader.setMaxLinesToRead(maxCloudletsToCreateFromWorkloadFile);
202201
this.cloudletList = reader.generateWorkload();
203202

204203
System.out.printf("# Created %12d Cloudlets for %s%n", this.cloudletList.size(), broker);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
105 112 118 125 131 137 147 153 157 164 169
2+
3+
*
4+
* Title: CloudSim Toolkit
5+
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
6+
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
7+
*
8+
* Copyright (c) 2009-2012, The University of Melbourne, Australia
9+
*
10+
* The power model of an HP ProLiant ML110 G3 (1 x [Pentium D930 3000 MHz, 2 cores], 4GB).
11+
* https://www.spec.org/power_ssj2008/results/res2011q1/power_ssj2008-20110127-00342.html
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
86 89.4 92.6 96 99.5 102 106 108 112 114 117
2+
3+
*
4+
* Title: CloudSim Toolkit
5+
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
6+
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
7+
*
8+
* Copyright (c) 2009-2012, The University of Melbourne, Australia
9+
*
10+
* The power model of an HP ProLiant ML110 G4 (1 x [Xeon 3040 1860 MHz, 2 cores], 4GB).
11+
* https://www.spec.org/power_ssj2008/results/res2011q1/power_ssj2008-20110127-00342.html
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
93.7 97 101 105 110 116 121 125 129 133 135
2+
3+
*
4+
* Title: CloudSim Toolkit
5+
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
6+
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
7+
*
8+
* Copyright (c) 2009-2012, The University of Melbourne, Australia
9+
*
10+
* The power model of an HP ProLiant ML110 G5 (1 x [Xeon 3075 2660 MHz, 2 cores], 4GB).
11+
* https://www.spec.org/power_ssj2008/results/res2011q1/power_ssj2008-20110124-00339.html
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
41.6 46.7 52.3 57.9 65.4 73 80.7 89.5 99.6 105 113
2+
3+
*
4+
* Title: CloudSim Toolkit
5+
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
6+
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
7+
*
8+
* Copyright (c) 2009-2012, The University of Melbourne, Australia
9+
*
10+
* The power model of an IBM server x3250 (1 x [Xeon X3470 2933 MHz, 4 cores], 8GB).
11+
* https://www.spec.org/power_ssj2008/results/res2009q4/power_ssj2008-20091104-00213.html
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
42.3 46.7 49.7 55.4 61.8 69.3 76.1 87 96.1 106 113
2+
3+
*
4+
* Title: CloudSim Toolkit
5+
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
6+
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
7+
*
8+
* Copyright (c) 2009-2012, The University of Melbourne, Australia
9+
*
10+
* The power model of an IBM server x3250 (1 x [Xeon X3480 3067 MHz, 4 cores], 8GB).
11+
* https://www.spec.org/power_ssj2008/results/res2010q4/power_ssj2008-20101001-00297.html
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
66 107 120 131 143 156 173 191 211 229 247
2+
3+
*
4+
* Title: CloudSim Toolkit
5+
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
6+
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
7+
*
8+
* Copyright (c) 2009-2012, The University of Melbourne, Australia
9+
*
10+
* The power model of an IBM server x3550 (2 x [Xeon X5670 2933 MHz, 6 cores], 12GB).
11+
* https://www.spec.org/power_ssj2008/results/res2010q2/power_ssj2008-20100315-00239.html

0 commit comments

Comments
 (0)