Merge pull request #35275 from wojtek-t/cache_conditions

Automatic merge from submit-queue

Cache additional information in schedulercache.NodeInfo to speedup scheduler

Ref #35117
This commit is contained in:
Kubernetes Submit Queue 2016-12-07 02:23:19 -08:00 committed by GitHub
commit 1b5666fc35
2 changed files with 63 additions and 35 deletions

View File

@ -1119,12 +1119,7 @@ func (c *PodAffinityChecker) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod, node
} }
func PodToleratesNodeTaints(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, []algorithm.PredicateFailureReason, error) { func PodToleratesNodeTaints(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, []algorithm.PredicateFailureReason, error) {
node := nodeInfo.Node() taints, err := nodeInfo.Taints()
if node == nil {
return false, nil, fmt.Errorf("node not found")
}
taints, err := v1.GetTaintsFromNodeAnnotations(node.Annotations)
if err != nil { if err != nil {
return false, nil, err return false, nil, err
} }
@ -1174,11 +1169,6 @@ func isPodBestEffort(pod *v1.Pod) bool {
// CheckNodeMemoryPressurePredicate checks if a pod can be scheduled on a node // CheckNodeMemoryPressurePredicate checks if a pod can be scheduled on a node
// reporting memory pressure condition. // reporting memory pressure condition.
func CheckNodeMemoryPressurePredicate(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, []algorithm.PredicateFailureReason, error) { func CheckNodeMemoryPressurePredicate(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, []algorithm.PredicateFailureReason, error) {
node := nodeInfo.Node()
if node == nil {
return false, nil, fmt.Errorf("node not found")
}
var podBestEffort bool var podBestEffort bool
if predicateMeta, ok := meta.(*predicateMetadata); ok { if predicateMeta, ok := meta.(*predicateMetadata); ok {
podBestEffort = predicateMeta.podBestEffort podBestEffort = predicateMeta.podBestEffort
@ -1186,36 +1176,24 @@ func CheckNodeMemoryPressurePredicate(pod *v1.Pod, meta interface{}, nodeInfo *s
// We couldn't parse metadata - fallback to computing it. // We couldn't parse metadata - fallback to computing it.
podBestEffort = isPodBestEffort(pod) podBestEffort = isPodBestEffort(pod)
} }
// pod is not BestEffort pod // pod is not BestEffort pod
if !podBestEffort { if !podBestEffort {
return true, nil, nil return true, nil, nil
} }
// is node under pressure? // is node under presure?
for _, cond := range node.Status.Conditions { if nodeInfo.MemoryPressureCondition() == v1.ConditionTrue {
if cond.Type == v1.NodeMemoryPressure && cond.Status == v1.ConditionTrue { return false, []algorithm.PredicateFailureReason{ErrNodeUnderMemoryPressure}, nil
return false, []algorithm.PredicateFailureReason{ErrNodeUnderMemoryPressure}, nil
}
} }
return true, nil, nil return true, nil, nil
} }
// CheckNodeDiskPressurePredicate checks if a pod can be scheduled on a node // CheckNodeDiskPressurePredicate checks if a pod can be scheduled on a node
// reporting disk pressure condition. // reporting disk pressure condition.
func CheckNodeDiskPressurePredicate(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, []algorithm.PredicateFailureReason, error) { func CheckNodeDiskPressurePredicate(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, []algorithm.PredicateFailureReason, error) {
node := nodeInfo.Node() // is node under presure?
if node == nil { if nodeInfo.DiskPressureCondition() == v1.ConditionTrue {
return false, nil, fmt.Errorf("node not found") return false, []algorithm.PredicateFailureReason{ErrNodeUnderDiskPressure}, nil
} }
// is node under pressure?
for _, cond := range node.Status.Conditions {
if cond.Type == v1.NodeDiskPressure && cond.Status == v1.ConditionTrue {
return false, []algorithm.PredicateFailureReason{ErrNodeUnderDiskPressure}, nil
}
}
return true, nil, nil return true, nil, nil
} }

View File

@ -49,6 +49,14 @@ type NodeInfo struct {
// explicitly as int, to avoid conversions and improve performance. // explicitly as int, to avoid conversions and improve performance.
allowedPodNumber int allowedPodNumber int
// Cached tains of the node for faster lookup.
taints []v1.Taint
taintsErr error
// Cached conditions of node for faster lookup.
memoryPressureCondition v1.ConditionStatus
diskPressureCondition v1.ConditionStatus
// Whenever NodeInfo changes, generation is bumped. // Whenever NodeInfo changes, generation is bumped.
// This is used to avoid cloning it if the object didn't change. // This is used to avoid cloning it if the object didn't change.
generation int64 generation int64
@ -122,6 +130,27 @@ func (n *NodeInfo) AllowedPodNumber() int {
return n.allowedPodNumber return n.allowedPodNumber
} }
func (n *NodeInfo) Taints() ([]v1.Taint, error) {
if n == nil {
return nil, nil
}
return n.taints, n.taintsErr
}
func (n *NodeInfo) MemoryPressureCondition() v1.ConditionStatus {
if n == nil {
return v1.ConditionUnknown
}
return n.memoryPressureCondition
}
func (n *NodeInfo) DiskPressureCondition() v1.ConditionStatus {
if n == nil {
return v1.ConditionUnknown
}
return n.diskPressureCondition
}
// RequestedResource returns aggregated resource request of pods on this node. // RequestedResource returns aggregated resource request of pods on this node.
func (n *NodeInfo) RequestedResource() Resource { func (n *NodeInfo) RequestedResource() Resource {
if n == nil { if n == nil {
@ -148,12 +177,15 @@ func (n *NodeInfo) AllocatableResource() Resource {
func (n *NodeInfo) Clone() *NodeInfo { func (n *NodeInfo) Clone() *NodeInfo {
clone := &NodeInfo{ clone := &NodeInfo{
node: n.node, node: n.node,
requestedResource: &(*n.requestedResource), requestedResource: &(*n.requestedResource),
nonzeroRequest: &(*n.nonzeroRequest), nonzeroRequest: &(*n.nonzeroRequest),
allocatableResource: &(*n.allocatableResource), allocatableResource: &(*n.allocatableResource),
allowedPodNumber: n.allowedPodNumber, allowedPodNumber: n.allowedPodNumber,
generation: n.generation, taintsErr: n.taintsErr,
memoryPressureCondition: n.memoryPressureCondition,
diskPressureCondition: n.diskPressureCondition,
generation: n.generation,
} }
if len(n.pods) > 0 { if len(n.pods) > 0 {
clone.pods = append([]*v1.Pod(nil), n.pods...) clone.pods = append([]*v1.Pod(nil), n.pods...)
@ -161,6 +193,9 @@ func (n *NodeInfo) Clone() *NodeInfo {
if len(n.podsWithAffinity) > 0 { if len(n.podsWithAffinity) > 0 {
clone.podsWithAffinity = append([]*v1.Pod(nil), n.podsWithAffinity...) clone.podsWithAffinity = append([]*v1.Pod(nil), n.podsWithAffinity...)
} }
if len(n.taints) > 0 {
clone.taints = append([]v1.Taint(nil), n.taints...)
}
return clone return clone
} }
@ -306,6 +341,18 @@ func (n *NodeInfo) SetNode(node *v1.Node) error {
} }
} }
} }
n.taints, n.taintsErr = v1.GetTaintsFromNodeAnnotations(node.Annotations)
for i := range node.Status.Conditions {
cond := &node.Status.Conditions[i]
switch cond.Type {
case v1.NodeMemoryPressure:
n.memoryPressureCondition = cond.Status
case v1.NodeDiskPressure:
n.diskPressureCondition = cond.Status
default:
// We ignore other conditions.
}
}
n.generation++ n.generation++
return nil return nil
} }
@ -319,6 +366,9 @@ func (n *NodeInfo) RemoveNode(node *v1.Node) error {
n.node = nil n.node = nil
n.allocatableResource = &Resource{} n.allocatableResource = &Resource{}
n.allowedPodNumber = 0 n.allowedPodNumber = 0
n.taints, n.taintsErr = nil, nil
n.memoryPressureCondition = v1.ConditionUnknown
n.diskPressureCondition = v1.ConditionUnknown
n.generation++ n.generation++
return nil return nil
} }