Merge pull request #1679 from brendandburns/resource

Switch on the resource requested prioritization.
This commit is contained in:
Dawn Chen 2014-10-09 11:40:09 -07:00
commit ae8b193bcc
6 changed files with 24 additions and 4 deletions

View File

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

View File

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

View File

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

View File

@ -22,6 +22,13 @@ import (
"github.com/golang/glog" "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. // 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. // 'pods' is a list of pods currently scheduled on the node.
func calculateOccupancy(node api.Minion, pods []api.Pod) HostPriority { 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 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) glog.V(4).Infof("Least Requested Priority, AbsoluteRequested: (%d, %d) Percentage:(%d\\%m, %d\\%)", totalCPU, totalMemory, percentageCPU, percentageMemory)
return HostPriority{ return HostPriority{

View File

@ -100,6 +100,15 @@ func TestLeastRequested(t *testing.T) {
{DesiredState: cpuAndMemory, CurrentState: machine2State}, {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 { for _, test := range tests {

View File

@ -76,8 +76,8 @@ func (factory *ConfigFactory) Create() (*scheduler.Config, error) {
// Fit is determined by resource availability // Fit is determined by resource availability
algorithm.NewResourceFitPredicate(algorithm.StaticNodeInfo{nodes}), algorithm.NewResourceFitPredicate(algorithm.StaticNodeInfo{nodes}),
}, },
// All nodes where things fit are equally likely (Random) // Prioritize nodes by least requested utilization.
algorithm.EqualPriority, algorithm.LeastRequestedPriority,
&storeToPodLister{podCache}, r) &storeToPodLister{podCache}, r)
podBackoff := podBackoff{ podBackoff := podBackoff{