diff options
| author | Dante Niewenhuis <d.niewenhuis@hotmail.com> | 2025-10-02 15:32:32 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-02 15:32:32 +0200 |
| commit | 48ddc082ea301f54717a8ab7c54023f73220e4eb (patch) | |
| tree | e76ee573abde2fe1d8ca874d33b34cba72e478c8 /opendc-compute/opendc-compute-simulator/src/main/java | |
| parent | 2ba57fd06560f096def01a31f8e47827f0f01da0 (diff) | |
Improved FilterScheduler using a constantly sorting array (#374)
Updated FilterScheduler.kt for performance using a constantly sorted Array
Diffstat (limited to 'opendc-compute/opendc-compute-simulator/src/main/java')
2 files changed, 24 insertions, 5 deletions
diff --git a/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java b/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java index 3f6ef73b..f1e747b3 100644 --- a/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java +++ b/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/ComputeService.java @@ -151,8 +151,10 @@ public final class ComputeService implements AutoCloseable, CarbonReceiver { if (hv != null) { if (newState == HostState.UP) { availableHosts.add(hv); + restartHosts(hv); } else { availableHosts.remove(hv); + failHosts(hv); } } @@ -184,6 +186,7 @@ public final class ComputeService implements AutoCloseable, CarbonReceiver { final ServiceFlavor flavor = task.getFlavor(); if (hv != null) { hv.provisionedCpuCores -= flavor.getCpuCoreCount(); + hv.availableCpuCores += flavor.getCpuCoreCount(); hv.instanceCount--; hv.availableMemory += flavor.getMemorySize(); hv.provisionedGpuCores -= flavor.getGpuCoreCount(); @@ -193,9 +196,7 @@ public final class ComputeService implements AutoCloseable, CarbonReceiver { host.delete(task); - if (host.isEmpty()) { - setHostEmpty(host); - } + updateHost(host); if (newState == TaskState.COMPLETED) { tasksCompleted++; @@ -298,10 +299,18 @@ public final class ComputeService implements AutoCloseable, CarbonReceiver { host.addListener(hostListener); } - public void setHostEmpty(SimHost host) { + public void updateHost(SimHost host) { HostView hv = hostToView.get(host); - this.scheduler.setHostEmpty(hv); + this.scheduler.updateHost(hv); + } + + public void failHosts(HostView hv) { + this.scheduler.failHost(hv); + } + + public void restartHosts(HostView hv) { + this.scheduler.restartHost(hv); } public void addPowerSource(SimPowerSource simPowerSource) { @@ -519,6 +528,7 @@ public final class ComputeService implements AutoCloseable, CarbonReceiver { for (Iterator<SchedulingRequest> iterator = taskQueue.iterator(); iterator.hasNext(); iterator = taskQueue.iterator()) { + final SchedulingResult result = scheduler.select(iterator); if (result.getResultType() == SchedulingResultType.EMPTY) { break; @@ -570,10 +580,13 @@ public final class ComputeService implements AutoCloseable, CarbonReceiver { hv.instanceCount++; hv.provisionedCpuCores += flavor.getCpuCoreCount(); + hv.availableCpuCores -= flavor.getCpuCoreCount(); hv.availableMemory -= flavor.getMemorySize(); hv.provisionedGpuCores += flavor.getGpuCoreCount(); activeTasks.put(task, host); + + updateHost(host); } catch (Exception cause) { LOGGER.error("Failed to deploy VM", cause); scheduler.removeTask(task, hv); diff --git a/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/HostView.java b/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/HostView.java index c07f58c7..ba4dbf64 100644 --- a/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/HostView.java +++ b/opendc-compute/opendc-compute-simulator/src/main/java/org/opendc/compute/simulator/service/HostView.java @@ -32,6 +32,7 @@ public class HostView { int instanceCount; long availableMemory; int provisionedCpuCores; + int availableCpuCores; int provisionedGpuCores; /** @@ -58,6 +59,7 @@ public class HostView { public HostView(SimHost host) { this.host = host; this.availableMemory = host.getModel().memoryCapacity(); + this.availableCpuCores = host.getModel().coreCount(); } /** @@ -88,6 +90,10 @@ public class HostView { return provisionedCpuCores; } + public int getAvailableCpuCores() { + return availableCpuCores; + } + public int getProvisionedGpuCores() { return provisionedGpuCores; } |
