Skip to content

Commit 4394086

Browse files
committed
fix(Fix number of hosts in the CostsExample):
The number of hosts was not enough to place the VMs and the simulation was in loop. Signed-off-by: Manoel Campos <[email protected]>
1 parent d9149c4 commit 4394086

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

src/main/java/org/cloudsimplus/examples/VmBootTimeAndOverheadExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private VmBootTimeAndOverheadExample() {
102102
vmList = createVms();
103103
cloudletList = createCloudlets();
104104
broker0.submitVmList(vmList);
105-
vmList.get(0).addOnUpdateProcessingListener(this::updateVmProcessingListener);
105+
vmList.getFirst().addOnUpdateProcessingListener(this::updateVmProcessingListener);
106106
broker0.submitCloudletList(cloudletList);
107107

108108
simulation.start();
@@ -172,7 +172,7 @@ private List<Vm> createVms() {
172172
.setBw(1000)
173173
.setSize(10_000)
174174
.setBootModel(new BootModel(bootModelCpu, bootModelRam))
175-
.setStartupDelay(VM_BOOT_DELAY)
175+
.setStartupDelay(VM_BOOT_DELAY*i)
176176
.setShutDownDelay(VM_SHUTDOWN_DELAY);
177177
vmList.add(vm);
178178
}

src/main/java/org/cloudsimplus/examples/costs/CostsExample1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class CostsExample1 {
6262
*/
6363
private static final int SCHEDULING_INTERVAL = 1;
6464

65-
private static final int HOSTS = 2;
65+
private static final int HOSTS = 4;
6666
private static final int HOST_PES = 8;
6767
private static final int HOST_MIPS = 1000;
6868

src/main/java/org/cloudsimplus/examples/migration/MigrationExample1.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.cloudsimplus.brokers.DatacenterBroker;
3030
import org.cloudsimplus.brokers.DatacenterBrokerSimple;
3131
import org.cloudsimplus.builders.tables.CloudletsTableBuilder;
32-
import org.cloudsimplus.builders.tables.HostHistoryTableBuilder;
3332
import org.cloudsimplus.cloudlets.Cloudlet;
3433
import org.cloudsimplus.cloudlets.CloudletSimple;
3534
import org.cloudsimplus.core.CloudSimPlus;
@@ -236,14 +235,23 @@ private MigrationExample1(){
236235
comparingLong((Cloudlet c) -> c.getVm().getHost().getId())
237236
.thenComparingLong(c -> c.getVm().getId());
238237
cloudletFinishedList.sort(cloudletComparator);
238+
239+
printHosts();
239240
new CloudletsTableBuilder(cloudletFinishedList).build();
240241
System.out.printf("%nHosts CPU usage History (when the allocated MIPS is lower than the requested, it is due to VM migration overhead)%n");
241242

242-
hostList.stream().filter(h -> h.getId() <= 2).forEach(this::printHostStateHistory);
243243
System.out.printf("Number of VM migrations: %d%n", migrationsNumber);
244244
System.out.println(getClass().getSimpleName() + " finished!");
245245
}
246246

247+
private void printHosts() {
248+
System.out.println("Host ID | CPUs | MIPS");
249+
System.out.println("---------------------");
250+
for (final var host : hostList) {
251+
System.out.printf("%7s | %4s | %s%n", host.getId(), host.getPesNumber(), (int)host.getMips());
252+
}
253+
}
254+
247255
/**
248256
* A listener method that is called when a VM migration starts.
249257
* @param info information about the happened event
@@ -307,10 +315,6 @@ private void showHostAllocatedMips(final double time, final Host host) {
307315
time, host, host.getTotalAllocatedMips(), host.getTotalMipsCapacity());
308316
}
309317

310-
private void printHostStateHistory(final Host host) {
311-
new HostHistoryTableBuilder(host).setTitle(host.toString()).build();
312-
}
313-
314318
public void createAndSubmitCloudlets(DatacenterBroker broker) {
315319
final var newCloudletList = new ArrayList<Cloudlet>(VM_PES.length);
316320
var cloudlet = Cloudlet.NULL;

0 commit comments

Comments
 (0)