Add CPU count and maximum resource controls for Windows
| ... | ... |
@@ -411,6 +411,11 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi |
| 411 | 411 |
if resources.CPUQuota > 0 && resources.CPUQuota < 1000 {
|
| 412 | 412 |
return warnings, fmt.Errorf("CPU cfs quota can not be less than 1ms (i.e. 1000)")
|
| 413 | 413 |
} |
| 414 |
+ if resources.CPUPercent > 0 {
|
|
| 415 |
+ warnings = append(warnings, "%s does not support CPU percent. Percent discarded.", runtime.GOOS) |
|
| 416 |
+ logrus.Warnf("%s does not support CPU percent. Percent discarded.", runtime.GOOS)
|
|
| 417 |
+ resources.CPUPercent = 0 |
|
| 418 |
+ } |
|
| 414 | 419 |
|
| 415 | 420 |
// cpuset subsystem checks and adjustments |
| 416 | 421 |
if (resources.CpusetCpus != "" || resources.CpusetMems != "") && !sysInfo.Cpuset {
|
| ... | ... |
@@ -16,6 +16,7 @@ import ( |
| 16 | 16 |
"github.com/docker/docker/dockerversion" |
| 17 | 17 |
"github.com/docker/docker/image" |
| 18 | 18 |
"github.com/docker/docker/layer" |
| 19 |
+ "github.com/docker/docker/pkg/sysinfo" |
|
| 19 | 20 |
"github.com/docker/docker/reference" |
| 20 | 21 |
"github.com/docker/docker/runconfig" |
| 21 | 22 |
// register the windows graph driver |
| ... | ... |
@@ -94,10 +95,34 @@ func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConf |
| 94 | 94 |
return nil |
| 95 | 95 |
} |
| 96 | 96 |
|
| 97 |
+func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysinfo.SysInfo) ([]string, error) {
|
|
| 98 |
+ warnings := []string{}
|
|
| 99 |
+ |
|
| 100 |
+ // cpu subsystem checks and adjustments |
|
| 101 |
+ if resources.CPUPercent < 0 || resources.CPUPercent > 100 {
|
|
| 102 |
+ return warnings, fmt.Errorf("Range of CPU percent is from 1 to 100")
|
|
| 103 |
+ } |
|
| 104 |
+ |
|
| 105 |
+ if resources.CPUPercent > 0 && resources.CPUShares > 0 {
|
|
| 106 |
+ return warnings, fmt.Errorf("Conflicting options: CPU Shares and CPU Percent cannot both be set")
|
|
| 107 |
+ } |
|
| 108 |
+ |
|
| 109 |
+ return warnings, nil |
|
| 110 |
+} |
|
| 111 |
+ |
|
| 97 | 112 |
// verifyPlatformContainerSettings performs platform-specific validation of the |
| 98 | 113 |
// hostconfig and config structures. |
| 99 | 114 |
func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) {
|
| 100 |
- return nil, nil |
|
| 115 |
+ |
|
| 116 |
+ warnings := []string{}
|
|
| 117 |
+ |
|
| 118 |
+ w, err := verifyContainerResources(&hostConfig.Resources, nil) |
|
| 119 |
+ warnings = append(warnings, w...) |
|
| 120 |
+ if err != nil {
|
|
| 121 |
+ return warnings, err |
|
| 122 |
+ } |
|
| 123 |
+ |
|
| 124 |
+ return warnings, nil |
|
| 101 | 125 |
} |
| 102 | 126 |
|
| 103 | 127 |
// verifyDaemonSettings performs validation of daemon config struct |
| ... | ... |
@@ -160,9 +160,8 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e |
| 160 | 160 |
cpuShares := uint64(c.HostConfig.CPUShares) |
| 161 | 161 |
s.Windows.Resources = &windowsoci.Resources{
|
| 162 | 162 |
CPU: &windowsoci.CPU{
|
| 163 |
- //TODO Count: ..., |
|
| 164 |
- //TODO Percent: ..., |
|
| 165 |
- Shares: &cpuShares, |
|
| 163 |
+ Percent: &c.HostConfig.CPUPercent, |
|
| 164 |
+ Shares: &cpuShares, |
|
| 166 | 165 |
}, |
| 167 | 166 |
Memory: &windowsoci.Memory{
|
| 168 | 167 |
//TODO Limit: ..., |
| ... | ... |
@@ -282,6 +282,7 @@ Create a container |
| 282 | 282 |
"MemorySwap": 0, |
| 283 | 283 |
"MemoryReservation": 0, |
| 284 | 284 |
"KernelMemory": 0, |
| 285 |
+ "CpuPercent": 80, |
|
| 285 | 286 |
"CpuShares": 512, |
| 286 | 287 |
"CpuPeriod": 100000, |
| 287 | 288 |
"CpuQuota": 50000, |
| ... | ... |
@@ -354,6 +355,7 @@ Json Parameters: |
| 354 | 354 |
You must use this with `memory` and make the swap value larger than `memory`. |
| 355 | 355 |
- **MemoryReservation** - Memory soft limit in bytes. |
| 356 | 356 |
- **KernelMemory** - Kernel memory limit in bytes. |
| 357 |
+- **CpuPercent** - An integer value containing the usable percentage of the available CPUs. (Windows daemon only) |
|
| 357 | 358 |
- **CpuShares** - An integer value containing the container's CPU Shares |
| 358 | 359 |
(ie. the relative weight vs other containers). |
| 359 | 360 |
- **CpuPeriod** - The length of a CPU period in microseconds. |
| ... | ... |
@@ -542,6 +544,7 @@ Return low-level information on the container `id` |
| 542 | 542 |
"ContainerIDFile": "", |
| 543 | 543 |
"CpusetCpus": "", |
| 544 | 544 |
"CpusetMems": "", |
| 545 |
+ "CpuPercent": 80, |
|
| 545 | 546 |
"CpuShares": 0, |
| 546 | 547 |
"CpuPeriod": 100000, |
| 547 | 548 |
"Devices": [], |
| ... | ... |
@@ -23,6 +23,7 @@ parent = "smn_cli" |
| 23 | 23 |
--cap-drop=[] Drop Linux capabilities |
| 24 | 24 |
--cgroup-parent="" Optional parent cgroup for the container |
| 25 | 25 |
--cidfile="" Write the container ID to the file |
| 26 |
+ --cpu-percent=0 Limit percentage of CPU available for execution by the container. Windows daemon only. |
|
| 26 | 27 |
--cpu-period=0 Limit CPU CFS (Completely Fair Scheduler) period |
| 27 | 28 |
--cpu-quota=0 Limit CPU CFS (Completely Fair Scheduler) quota |
| 28 | 29 |
--cpuset-cpus="" CPUs in which to allow execution (0-3, 0,1) |
| ... | ... |
@@ -78,6 +78,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host |
| 78 | 78 |
flUser = cmd.String([]string{"u", "-user"}, "", "Username or UID (format: <name|uid>[:<group|gid>])")
|
| 79 | 79 |
flWorkingDir = cmd.String([]string{"w", "-workdir"}, "", "Working directory inside the container")
|
| 80 | 80 |
flCPUShares = cmd.Int64([]string{"#c", "-cpu-shares"}, 0, "CPU shares (relative weight)")
|
| 81 |
+ flCPUPercent = cmd.Int64([]string{"-cpu-percent"}, 0, "CPU percent (Windows only)")
|
|
| 81 | 82 |
flCPUPeriod = cmd.Int64([]string{"-cpu-period"}, 0, "Limit CPU CFS (Completely Fair Scheduler) period")
|
| 82 | 83 |
flCPUQuota = cmd.Int64([]string{"-cpu-quota"}, 0, "Limit CPU CFS (Completely Fair Scheduler) quota")
|
| 83 | 84 |
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 |
| 354 | 354 |
MemorySwappiness: flSwappiness, |
| 355 | 355 |
KernelMemory: KernelMemory, |
| 356 | 356 |
OomKillDisable: flOomKillDisable, |
| 357 |
+ CPUPercent: *flCPUPercent, |
|
| 357 | 358 |
CPUShares: *flCPUShares, |
| 358 | 359 |
CPUPeriod: *flCPUPeriod, |
| 359 | 360 |
CpusetCpus: *flCpusetCpus, |