1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add CPU count and maximum resource controls for Windows

Signed-off-by: Darren Stahl <darst@microsoft.com>
This commit is contained in:
Darren Stahl 2016-03-04 17:24:09 -08:00
parent 3b39363495
commit ea8c690886
6 changed files with 39 additions and 4 deletions

View file

@ -408,6 +408,11 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi
if resources.CPUQuota > 0 && resources.CPUQuota < 1000 { if resources.CPUQuota > 0 && resources.CPUQuota < 1000 {
return warnings, fmt.Errorf("CPU cfs quota can not be less than 1ms (i.e. 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 // cpuset subsystem checks and adjustments
if (resources.CpusetCpus != "" || resources.CpusetMems != "") && !sysInfo.Cpuset { if (resources.CpusetCpus != "" || resources.CpusetMems != "") && !sysInfo.Cpuset {

View file

@ -16,6 +16,7 @@ import (
"github.com/docker/docker/dockerversion" "github.com/docker/docker/dockerversion"
"github.com/docker/docker/image" "github.com/docker/docker/image"
"github.com/docker/docker/layer" "github.com/docker/docker/layer"
"github.com/docker/docker/pkg/sysinfo"
"github.com/docker/docker/reference" "github.com/docker/docker/reference"
"github.com/docker/docker/runconfig" "github.com/docker/docker/runconfig"
// register the windows graph driver // register the windows graph driver
@ -95,10 +96,34 @@ func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConf
return nil 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 // verifyPlatformContainerSettings performs platform-specific validation of the
// hostconfig and config structures. // hostconfig and config structures.
func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) { 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 // verifyDaemonSettings performs validation of daemon config struct

View file

@ -158,8 +158,7 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
cpuShares := uint64(c.HostConfig.CPUShares) cpuShares := uint64(c.HostConfig.CPUShares)
s.Windows.Resources = &windowsoci.Resources{ s.Windows.Resources = &windowsoci.Resources{
CPU: &windowsoci.CPU{ CPU: &windowsoci.CPU{
//TODO Count: ..., Percent: &c.HostConfig.CPUPercent,
//TODO Percent: ...,
Shares: &cpuShares, Shares: &cpuShares,
}, },
Memory: &windowsoci.Memory{ Memory: &windowsoci.Memory{

View file

@ -293,6 +293,7 @@ Create a container
"MemorySwap": 0, "MemorySwap": 0,
"MemoryReservation": 0, "MemoryReservation": 0,
"KernelMemory": 0, "KernelMemory": 0,
"CpuPercent": 80,
"CpuShares": 512, "CpuShares": 512,
"CpuPeriod": 100000, "CpuPeriod": 100000,
"CpuQuota": 50000, "CpuQuota": 50000,
@ -353,6 +354,7 @@ Json Parameters:
You must use this with `memory` and make the swap value larger than `memory`. You must use this with `memory` and make the swap value larger than `memory`.
- **MemoryReservation** - Memory soft limit in bytes. - **MemoryReservation** - Memory soft limit in bytes.
- **KernelMemory** - Kernel memory 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 - **CpuShares** - An integer value containing the container's CPU Shares
(ie. the relative weight vs other containers). (ie. the relative weight vs other containers).
- **CpuPeriod** - The length of a CPU period in microseconds. - **CpuPeriod** - The length of a CPU period in microseconds.
@ -538,6 +540,7 @@ Return low-level information on the container `id`
"ContainerIDFile": "", "ContainerIDFile": "",
"CpusetCpus": "", "CpusetCpus": "",
"CpusetMems": "", "CpusetMems": "",
"CpuPercent": 80,
"CpuShares": 0, "CpuShares": 0,
"CpuPeriod": 100000, "CpuPeriod": 100000,
"Devices": [], "Devices": [],

View file

@ -23,6 +23,7 @@ parent = "smn_cli"
--cap-drop=[] Drop Linux capabilities --cap-drop=[] Drop Linux capabilities
--cgroup-parent="" Optional parent cgroup for the container --cgroup-parent="" Optional parent cgroup for the container
--cidfile="" Write the container ID to the file --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-period=0 Limit CPU CFS (Completely Fair Scheduler) period
--cpu-quota=0 Limit CPU CFS (Completely Fair Scheduler) quota --cpu-quota=0 Limit CPU CFS (Completely Fair Scheduler) quota
--cpuset-cpus="" CPUs in which to allow execution (0-3, 0,1) --cpuset-cpus="" CPUs in which to allow execution (0-3, 0,1)

View file

@ -76,6 +76,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>])") 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") flWorkingDir = cmd.String([]string{"w", "-workdir"}, "", "Working directory inside the container")
flCPUShares = cmd.Int64([]string{"#c", "-cpu-shares"}, 0, "CPU shares (relative weight)") 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") 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") 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)") flCpusetCpus = cmd.String([]string{"-cpuset-cpus"}, "", "CPUs in which to allow execution (0-3, 0,1)")
@ -345,6 +346,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
MemorySwappiness: flSwappiness, MemorySwappiness: flSwappiness,
KernelMemory: KernelMemory, KernelMemory: KernelMemory,
OomKillDisable: flOomKillDisable, OomKillDisable: flOomKillDisable,
CPUPercent: *flCPUPercent,
CPUShares: *flCPUShares, CPUShares: *flCPUShares,
CPUPeriod: *flCPUPeriod, CPUPeriod: *flCPUPeriod,
CpusetCpus: *flCpusetCpus, CpusetCpus: *flCpusetCpus,