Skip to content

Commit

Permalink
Change CPUShares to CPUPercent on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Peng Yin committed Nov 15, 2017
1 parent 9436124 commit f519d40
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions agent/api/task_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package api

import (
"path/filepath"
"runtime"
"strings"

"github.com/aws/amazon-ecs-agent/agent/config"
Expand All @@ -28,6 +29,8 @@ const (
memorySwappinessDefault = -1
)

var cpus = runtime.NumCPU() * 1024

// adjustForPlatform makes Windows-specific changes to the task after unmarshal
func (task *Task) adjustForPlatform(cfg *config.Config) {
task.downcaseAllVolumePaths()
Expand Down Expand Up @@ -59,6 +62,7 @@ func getCanonicalPath(path string) string {
// passed to Docker API.
func (task *Task) platformHostConfigOverride(hostConfig *docker.HostConfig) error {
task.overrideDefaultMemorySwappiness(hostConfig)
hostConfig.CPUPercent = hostConfig.CPUShares * int64(100) / int64(cpus)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions agent/api/task_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ func TestWindowsPlatformHostConfigOverride(t *testing.T) {

task := &Task{}

hostConfig := &docker.HostConfig{}
hostConfig := &docker.HostConfig{CPUShares: 1024}

task.platformHostConfigOverride(hostConfig)

assert.Equal(t, int64(1024)/int64(cpus), hostConfig.CPUPercent)
assert.EqualValues(t, expectedMemorySwappinessDefault, hostConfig.MemorySwappiness)
}

Expand Down

0 comments on commit f519d40

Please sign in to comment.