Skip to content

Commit

Permalink
Cpu fix (#208)
Browse files Browse the repository at this point in the history
* Updated the topology format to JSON. Updated TopologyReader.kt to handle JSON filed. Added documentation for the new format.

* applied spotless kotlin

* small update

* Updated for spotless apply

* Updated for spotless apply
  • Loading branch information
DanteNiewenhuis authored Mar 5, 2024
1 parent 5864cbc commit 960b3d8
Show file tree
Hide file tree
Showing 51 changed files with 1,602 additions and 387 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface Flavor : Resource {
/**
* The number of (virtual) processing cores to use.
*/
public val cpuCount: Int
public val coreCount: Int

/**
* The amount of RAM available to the server (in MB).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void onStateChanged(@NotNull Host host, @NotNull Server server, @NotNull
HostView hv = hostToView.get(host);
final ServiceFlavor flavor = serviceServer.getFlavor();
if (hv != null) {
hv.provisionedCores -= flavor.getCpuCount();
hv.provisionedCores -= flavor.getCoreCount();
hv.instanceCount--;
hv.availableMemory += flavor.getMemorySize();
} else {
Expand Down Expand Up @@ -237,7 +237,7 @@ public void addHost(Host host) {
HostView hv = new HostView(host);
HostModel model = host.getModel();

maxCores = Math.max(maxCores, model.cpuCount());
maxCores = Math.max(maxCores, model.coreCount());
maxMemory = Math.max(maxMemory, model.memoryCapacity());
hostToView.put(host, hv);

Expand Down Expand Up @@ -370,7 +370,7 @@ private void doSchedule() {
LOGGER.trace(
"Server {} selected for scheduling but no capacity available for it at the moment", server);

if (flavor.getMemorySize() > maxMemory || flavor.getCpuCount() > maxCores) {
if (flavor.getMemorySize() > maxMemory || flavor.getCoreCount() > maxCores) {
// Remove the incoming image
queue.poll();
serversPending--;
Expand Down Expand Up @@ -403,7 +403,7 @@ private void doSchedule() {
attemptsSuccess++;

hv.instanceCount++;
hv.provisionedCores += flavor.getCpuCount();
hv.provisionedCores += flavor.getCoreCount();
hv.availableMemory -= flavor.getMemorySize();

activeServers.put(server, host);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public final class ServiceFlavor implements Flavor {
private final ComputeService service;
private final UUID uid;
private final String name;
private final int cpuCount;
private final int coreCount;
private final long memorySize;
private final Map<String, String> labels;
private final Map<String, ?> meta;
Expand All @@ -45,22 +45,22 @@ public final class ServiceFlavor implements Flavor {
ComputeService service,
UUID uid,
String name,
int cpuCount,
int coreCount,
long memorySize,
Map<String, String> labels,
Map<String, ?> meta) {
this.service = service;
this.uid = uid;
this.name = name;
this.cpuCount = cpuCount;
this.coreCount = coreCount;
this.memorySize = memorySize;
this.labels = labels;
this.meta = meta;
}

@Override
public int getCpuCount() {
return cpuCount;
public int getCoreCount() {
return coreCount;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
* @param cpuCount The number of logical processing cores available for this host.
* @param memoryCapacity The amount of memory available for this host in MB.
*/
public record HostModel(double cpuCapacity, int cpuCount, long memoryCapacity) {}
public record HostModel(double cpuCapacity, int cpuCount, int coreCount, long memoryCapacity) {}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public fun createComputeScheduler(
seeder: RandomGenerator,
placements: Map<String, String> = emptyMap(),
): ComputeScheduler {
val cpuAllocationRatio = 16.0
val cpuAllocationRatio = 1.0
val ramAllocationRatio = 1.5
return when (name) {
"mem" ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ public class VCpuCapacityFilter : HostFilter {
val hostModel = host.host.model
val availableCapacity = hostModel.cpuCapacity / hostModel.cpuCount

return requiredCapacity == null || availableCapacity >= (requiredCapacity / server.flavor.cpuCount)
return requiredCapacity == null || availableCapacity >= (requiredCapacity / server.flavor.coreCount)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class VCpuFilter(private val allocationRatio: Double) : HostFilter {
host: HostView,
server: Server,
): Boolean {
val requested = server.flavor.cpuCount
val total = host.host.model.cpuCount
val requested = server.flavor.coreCount
val total = host.host.model.coreCount
val limit = total * allocationRatio

// Do not allow an instance to overcommit against itself, only against other instances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class VCpuCapacityWeigher(override val multiplier: Double = 1.0) : HostWe
): Double {
val model = host.host.model
val requiredCapacity = server.flavor.meta["cpu-capacity"] as? Double ?: 0.0
return model.cpuCapacity / model.cpuCount - requiredCapacity / server.flavor.cpuCount
return model.cpuCapacity / model.cpuCount - requiredCapacity / server.flavor.coreCount
}

override fun toString(): String = "VCpuWeigher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ internal class ComputeServiceTest {
scope.runSimulation {
val host = mockk<Host>(relaxUnitFun = true)

every { host.model } returns HostModel(4 * 2600.0, 4, 2048)
every { host.model } returns HostModel(4 * 2600.0, 1, 4, 2048)
every { host.state } returns HostState.UP

assertEquals(emptySet<Host>(), service.hosts)
Expand All @@ -157,7 +157,7 @@ internal class ComputeServiceTest {
scope.runSimulation {
val host = mockk<Host>(relaxUnitFun = true)

every { host.model } returns HostModel(4 * 2600.0, 4, 2048)
every { host.model } returns HostModel(4 * 2600.0, 1, 4, 2048)
every { host.state } returns HostState.DOWN

assertEquals(emptySet<Host>(), service.hosts)
Expand Down Expand Up @@ -230,7 +230,7 @@ internal class ComputeServiceTest {
scope.runSimulation {
val host = mockk<Host>(relaxUnitFun = true)

every { host.model } returns HostModel(4 * 2600.0, 4, 2048)
every { host.model } returns HostModel(4 * 2600.0, 1, 4, 2048)
every { host.state } returns HostState.UP
every { host.canFit(any()) } returns false

Expand All @@ -256,7 +256,7 @@ internal class ComputeServiceTest {
val listeners = mutableListOf<HostListener>()

every { host.uid } returns UUID.randomUUID()
every { host.model } returns HostModel(4 * 2600.0, 4, 2048)
every { host.model } returns HostModel(4 * 2600.0, 1, 4, 2048)
every { host.state } returns HostState.DOWN
every { host.addListener(any()) } answers { listeners.add(it.invocation.args[0] as HostListener) }
every { host.canFit(any()) } returns false
Expand Down Expand Up @@ -288,7 +288,7 @@ internal class ComputeServiceTest {
val listeners = mutableListOf<HostListener>()

every { host.uid } returns UUID.randomUUID()
every { host.model } returns HostModel(4 * 2600.0, 4, 2048)
every { host.model } returns HostModel(4 * 2600.0, 1, 4, 2048)
every { host.state } returns HostState.UP
every { host.addListener(any()) } answers { listeners.add(it.invocation.args[0] as HostListener) }
every { host.canFit(any()) } returns false
Expand Down Expand Up @@ -320,7 +320,7 @@ internal class ComputeServiceTest {
val listeners = mutableListOf<HostListener>()

every { host.uid } returns UUID.randomUUID()
every { host.model } returns HostModel(4 * 2600.0, 4, 2048)
every { host.model } returns HostModel(4 * 2600.0, 1, 4, 2048)
every { host.state } returns HostState.UP
every { host.canFit(any()) } returns true
every { host.addListener(any()) } answers { listeners.add(it.invocation.args[0] as HostListener) }
Expand Down Expand Up @@ -364,7 +364,7 @@ internal class ComputeServiceTest {
val listeners = mutableListOf<HostListener>()

every { host.uid } returns UUID.randomUUID()
every { host.model } returns HostModel(4 * 2600.0, 4, 2048)
every { host.model } returns HostModel(4 * 2600.0, 1, 4, 2048)
every { host.state } returns HostState.UP
every { host.canFit(any()) } returns true
every { host.addListener(any()) } answers { listeners.add(it.invocation.args[0] as HostListener) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class ServiceServerTest {
val flavor = mockk<ServiceFlavor>()
every { flavor.name } returns "c5.large"
every { flavor.uid } returns UUID.randomUUID()
every { flavor.cpuCount } returns 2
every { flavor.coreCount } returns 2
every { flavor.memorySize } returns 4096
return flavor
}
Expand Down
Loading

0 comments on commit 960b3d8

Please sign in to comment.