Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch on the resource requested prioritization. #1679

Merged
merged 1 commit into from
Oct 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/guestbook/frontend-controller.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"containers": [{
"name": "php-redis",
"image": "brendanburns/php-redis",
"cpu": 100,
"memory": 10000000,
"ports": [{"containerPort": 80, "hostPort": 8000}]
}]
Expand Down
1 change: 1 addition & 0 deletions examples/guestbook/redis-master.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"containers": [{
"name": "master",
"image": "dockerfile/redis",
"cpu": 100,
"ports": [{
"containerPort": 6379,
"hostPort": 6379
Expand Down
1 change: 1 addition & 0 deletions examples/guestbook/redis-slave-controller.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"containers": [{
"name": "slave",
"image": "brendanburns/redis-slave",
"cpu": 200,
"ports": [{"containerPort": 6379, "hostPort": 6380}]
}]
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/scheduler/priorities.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ import (
"github.com/golang/glog"
)

func calculatePercentage(requested, capacity int) int {
if capacity == 0 {
return 0
}
return (requested * 100) / capacity
}

// Calculate the occupancy on a node. 'node' has information about the resources on the node.
// 'pods' is a list of pods currently scheduled on the node.
func calculateOccupancy(node api.Minion, pods []api.Pod) HostPriority {
Expand All @@ -34,8 +41,9 @@ func calculateOccupancy(node api.Minion, pods []api.Pod) HostPriority {
totalMemory += container.Memory
}
}
percentageCPU := (totalCPU * 100) / resources.GetIntegerResource(node.NodeResources.Capacity, resources.CPU, 0)
percentageMemory := (totalMemory * 100) / resources.GetIntegerResource(node.NodeResources.Capacity, resources.Memory, 0)

percentageCPU := calculatePercentage(totalCPU, resources.GetIntegerResource(node.NodeResources.Capacity, resources.CPU, 0))
percentageMemory := calculatePercentage(totalMemory, resources.GetIntegerResource(node.NodeResources.Capacity, resources.Memory, 0))
glog.V(4).Infof("Least Requested Priority, AbsoluteRequested: (%d, %d) Percentage:(%d\\%m, %d\\%)", totalCPU, totalMemory, percentageCPU, percentageMemory)

return HostPriority{
Expand Down
9 changes: 9 additions & 0 deletions pkg/scheduler/priorities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ func TestLeastRequested(t *testing.T) {
{DesiredState: cpuAndMemory, CurrentState: machine2State},
},
},
{
nodes: []api.Minion{makeMinion("machine1", 0, 0), makeMinion("machine2", 0, 0)},
expectedList: []HostPriority{{"machine1", 0}, {"machine2", 0}},
test: "zero minion resources",
pods: []api.Pod{
{DesiredState: cpuOnly, CurrentState: machine1State},
{DesiredState: cpuAndMemory, CurrentState: machine2State},
},
},
}

for _, test := range tests {
Expand Down
4 changes: 2 additions & 2 deletions plugin/pkg/scheduler/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func (factory *ConfigFactory) Create() (*scheduler.Config, error) {
// Fit is determined by resource availability
algorithm.NewResourceFitPredicate(algorithm.StaticNodeInfo{nodes}),
},
// All nodes where things fit are equally likely (Random)
algorithm.EqualPriority,
// Prioritize nodes by least requested utilization.
algorithm.LeastRequestedPriority,
&storeToPodLister{podCache}, r)

podBackoff := podBackoff{
Expand Down