summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Demeester <vincent@sbr.pm>2016-04-15 08:14:59 +0200
committerVincent Demeester <vincent@sbr.pm>2016-04-15 08:14:59 +0200
commit172ca1ca8c4d5157789feb97a6424104b81a3479 (patch)
tree51dc4842c7fabdf61fb908ae3d2a9347c334efb7
parentbc0c8828e9afc32f1660a1f679ed523376c7d3d2 (diff)
parentea8c690886970b2929d52d8b61dcfb8becc24db9 (diff)
downloaddocker-172ca1ca8c4d5157789feb97a6424104b81a3479.tar.gz
Merge pull request #20924 from Microsoft/10662-CPUResourceControls
Add CPU count and maximum resource controls for Windows
-rw-r--r--daemon/daemon_unix.go5
-rw-r--r--daemon/daemon_windows.go27
-rw-r--r--daemon/oci_windows.go5
-rw-r--r--docs/reference/api/docker_remote_api_v1.24.md3
-rw-r--r--docs/reference/commandline/run.md1
-rw-r--r--runconfig/opts/parse.go2
6 files changed, 39 insertions, 4 deletions
diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go
index 86eb5ad5ce..ae0fa35cfc 100644
--- a/daemon/daemon_unix.go
+++ b/daemon/daemon_unix.go
@@ -411,6 +411,11 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi
if resources.CPUQuota > 0 && resources.CPUQuota < 1000 {
return warnings, fmt.Errorf("CPU cfs quota can not be less than 1ms (i.e. 1000)")
}
+ if resources.CPUPercent > 0 {
+ warnings = append(warnings, "%s does not support CPU percent. Percent discarded.", runtime.GOOS)
+ logrus.Warnf("%s does not support CPU percent. Percent discarded.", runtime.GOOS)
+ resources.CPUPercent = 0
+ }
// cpuset subsystem checks and adjustments
if (resources.CpusetCpus != "" || resources.CpusetMems != "") && !sysInfo.Cpuset {
diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go
index 5b49165e2e..83a1caadba 100644
--- a/daemon/daemon_windows.go
+++ b/daemon/daemon_windows.go
@@ -16,6 +16,7 @@ import (
"github.com/docker/docker/dockerversion"
"github.com/docker/docker/image"
"github.com/docker/docker/layer"
+ "github.com/docker/docker/pkg/sysinfo"
"github.com/docker/docker/reference"
"github.com/docker/docker/runconfig"
// register the windows graph driver
@@ -94,10 +95,34 @@ func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConf
return nil
}
+func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysinfo.SysInfo) ([]string, error) {
+ warnings := []string{}
+
+ // cpu subsystem checks and adjustments
+ if resources.CPUPercent < 0 || resources.CPUPercent > 100 {
+ return warnings, fmt.Errorf("Range of CPU percent is from 1 to 100")
+ }
+
+ if resources.CPUPercent > 0 && resources.CPUShares > 0 {
+ return warnings, fmt.Errorf("Conflicting options: CPU Shares and CPU Percent cannot both be set")
+ }
+
+ return warnings, nil
+}
+
// verifyPlatformContainerSettings performs platform-specific validation of the
// hostconfig and config structures.
func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) {
- return nil, nil
+
+ warnings := []string{}
+
+ w, err := verifyContainerResources(&hostConfig.Resources, nil)
+ warnings = append(warnings, w...)
+ if err != nil {
+ return warnings, err
+ }
+
+ return warnings, nil
}
// verifyDaemonSettings performs validation of daemon config struct
diff --git a/daemon/oci_windows.go b/daemon/oci_windows.go
index eefd28c7f2..be560e5c98 100644
--- a/daemon/oci_windows.go
+++ b/daemon/oci_windows.go
@@ -160,9 +160,8 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
cpuShares := uint64(c.HostConfig.CPUShares)
s.Windows.Resources = &windowsoci.Resources{
CPU: &windowsoci.CPU{
- //TODO Count: ...,
- //TODO Percent: ...,
- Shares: &cpuShares,
+ Percent: &c.HostConfig.CPUPercent,
+ Shares: &cpuShares,
},
Memory: &windowsoci.Memory{
//TODO Limit: ...,
diff --git a/docs/reference/api/docker_remote_api_v1.24.md b/docs/reference/api/docker_remote_api_v1.24.md
index 679140f243..02c5b9e772 100644
--- a/docs/reference/api/docker_remote_api_v1.24.md
+++ b/docs/reference/api/docker_remote_api_v1.24.md
@@ -282,6 +282,7 @@ Create a container
"MemorySwap": 0,
"MemoryReservation": 0,
"KernelMemory": 0,
+ "CpuPercent": 80,
"CpuShares": 512,
"CpuPeriod": 100000,
"CpuQuota": 50000,
@@ -354,6 +355,7 @@ Json Parameters:
You must use this with `memory` and make the swap value larger than `memory`.
- **MemoryReservation** - Memory soft limit in bytes.
- **KernelMemory** - Kernel memory limit in bytes.
+- **CpuPercent** - An integer value containing the usable percentage of the available CPUs. (Windows daemon only)
- **CpuShares** - An integer value containing the container's CPU Shares
(ie. the relative weight vs other containers).
- **CpuPeriod** - The length of a CPU period in microseconds.
@@ -542,6 +544,7 @@ Return low-level information on the container `id`
"ContainerIDFile": "",
"CpusetCpus": "",
"CpusetMems": "",
+ "CpuPercent": 80,
"CpuShares": 0,
"CpuPeriod": 100000,
"Devices": [],
diff --git a/docs/reference/commandline/run.md b/docs/reference/commandline/run.md
index 67e0010232..c4392d0f05 100644
--- a/docs/reference/commandline/run.md
+++ b/docs/reference/commandline/run.md
@@ -23,6 +23,7 @@ parent = "smn_cli"
--cap-drop=[] Drop Linux capabilities
--cgroup-parent="" Optional parent cgroup for the container
--cidfile="" Write the container ID to the file
+ --cpu-percent=0 Limit percentage of CPU available for execution by the container. Windows daemon only.
--cpu-period=0 Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota=0 Limit CPU CFS (Completely Fair Scheduler) quota
--cpuset-cpus="" CPUs in which to allow execution (0-3, 0,1)
diff --git a/runconfig/opts/parse.go b/runconfig/opts/parse.go
index 7c71dfcb74..a2c09dd2a8 100644
--- a/runconfig/opts/parse.go
+++ b/runconfig/opts/parse.go
@@ -78,6 +78,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
flUser = cmd.String([]string{"u", "-user"}, "", "Username or UID (format: <name|uid>[:<group|gid>])")
flWorkingDir = cmd.String([]string{"w", "-workdir"}, "", "Working directory inside the container")
flCPUShares = cmd.Int64([]string{"#c", "-cpu-shares"}, 0, "CPU shares (relative weight)")
+ flCPUPercent = cmd.Int64([]string{"-cpu-percent"}, 0, "CPU percent (Windows only)")
flCPUPeriod = cmd.Int64([]string{"-cpu-period"}, 0, "Limit CPU CFS (Completely Fair Scheduler) period")
flCPUQuota = cmd.Int64([]string{"-cpu-quota"}, 0, "Limit CPU CFS (Completely Fair Scheduler) quota")
flCpusetCpus = cmd.String([]string{"-cpuset-cpus"}, "", "CPUs in which to allow execution (0-3, 0,1)")
@@ -354,6 +355,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
MemorySwappiness: flSwappiness,
KernelMemory: KernelMemory,
OomKillDisable: flOomKillDisable,
+ CPUPercent: *flCPUPercent,
CPUShares: *flCPUShares,
CPUPeriod: *flCPUPeriod,
CpusetCpus: *flCpusetCpus,