Switch on the resource requested prioritization.

This commit is contained in:
Brendan Burns 2014-10-09 10:41:42 -07:00
parent b3292e947f
commit b5ec8a747b
6 changed files with 24 additions and 4 deletions

View File

@ -13,6 +13,7 @@
"containers": [{
"name": "php-redis",
"image": "brendanburns/php-redis",
"cpu": 100,
"memory": 10000000,
"ports": [{"containerPort": 80, "hostPort": 8000}]
}]

View File

@ -9,6 +9,7 @@
"containers": [{
"name": "master",
"image": "dockerfile/redis",
"cpu": 100,
"ports": [{
"containerPort": 6379,
"hostPort": 6379

View File

@ -13,6 +13,7 @@
"containers": [{
"name": "slave",
"image": "brendanburns/redis-slave",
"cpu": 200,
"ports": [{"containerPort": 6379, "hostPort": 6380}]
}]
}

View File

@ -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 {
@ -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{

View File

@ -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 {

View File

@ -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{