summaryrefslogtreecommitdiffstats
path: root/docker-api
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@verizonmedia.com>2019-05-24 15:23:51 +0200
committerJon Bratseth <bratseth@verizonmedia.com>2019-05-24 15:23:51 +0200
commit43eb83f3c4625d77ffe4b3cb6f1ca3b03ca22069 (patch)
treeced1ba6193ebb01b0f810d9ad88caf67bbd020a5 /docker-api
parentf4f86814c95b08824a11ff4a872332dc7d88e91d (diff)
Nonfunctional changes only
Diffstat (limited to 'docker-api')
-rw-r--r--docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/ContainerResources.java31
1 files changed, 22 insertions, 9 deletions
diff --git a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/ContainerResources.java b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/ContainerResources.java
index d6462b823f1..1b0b6380481 100644
--- a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/ContainerResources.java
+++ b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/ContainerResources.java
@@ -7,17 +7,22 @@ import java.util.Objects;
* @author valerijf
*/
public class ContainerResources {
+
public static final ContainerResources UNLIMITED = ContainerResources.from(0, 0, 0);
private static final int CPU_PERIOD = 100_000; // 100 µs
- /** Hard limit on container's CPU usage: Implemented using Completely Fair Scheduler (CFS) by allocating a given
+ /**
+ * Hard limit on container's CPU usage: Implemented using Completely Fair Scheduler (CFS) by allocating a given
* time within a given period, Container's processes are not bound to any specific CPU, which may create significant
- * performance degradation as processes are scheduled on another CPU after exhausting the quota. */
+ * performance degradation as processes are scheduled on another CPU after exhausting the quota.
+ */
private final double cpus;
- /** Soft limit on container's CPU usage: When plenty of CPU cycles are available, all containers use as much
+ /**
+ * Soft limit on container's CPU usage: When plenty of CPU cycles are available, all containers use as much
* CPU as they need. It prioritizes container CPU resources for the available CPU cycles.
- * It does not guarantee or reserve any specific CPU access. */
+ * It does not guarantee or reserve any specific CPU access.
+ */
private final int cpuShares;
/** The maximum amount, in bytes, of memory the container can use. */
@@ -36,11 +41,20 @@ public class ContainerResources {
throw new IllegalArgumentException("memoryBytes must be a positive integer or 0 for unlimited, was " + memoryBytes);
}
+ /**
+ * Create container resources from required fields.
+ *
+ * @param cpus the amount of vcpu that should be exclusively available to this container. This is a hard limit:
+ * More than this amlunt will never be available. To allow an unlimited amount use 0.
+ * @param cpuCores the amount of vcpu that should ideally be allocated to this container if there are no other
+ * constraints on resources. To allow an unlimited amount use 0.
+ * @param memoryGb the exact amount of memory that must be available to this container.
+ * @return the container resources encapsulating the parameters
+ */
public static ContainerResources from(double cpus, double cpuCores, double memoryGb) {
- return new ContainerResources(
- cpus,
- (int) Math.round(10 * cpuCores),
- (long) ((1L << 30) * memoryGb));
+ return new ContainerResources(cpus,
+ (int) Math.round(10 * cpuCores),
+ (long) ((1L << 30) * memoryGb));
}
public double cpus() {
@@ -65,7 +79,6 @@ public class ContainerResources {
return memoryBytes;
}
-
/** Returns true iff the memory component(s) of between <code>this</code> and <code>other</code> are equal */
public boolean equalsMemory(ContainerResources other) {
return memoryBytes == other.memoryBytes;