mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Cache AllowedPodNumber to avoid conversions.
This commit is contained in:
parent
4eed5e07a5
commit
989202c384
@ -472,11 +472,10 @@ func PodFitsResources(pod *api.Pod, meta interface{}, nodeInfo *schedulercache.N
|
|||||||
if node == nil {
|
if node == nil {
|
||||||
return false, fmt.Errorf("node not found")
|
return false, fmt.Errorf("node not found")
|
||||||
}
|
}
|
||||||
allocatable := node.Status.Allocatable
|
allowedPodNumber := nodeInfo.AllowedPodNumber()
|
||||||
allowedPodNumber := allocatable.Pods().Value()
|
if len(nodeInfo.Pods())+1 > allowedPodNumber {
|
||||||
if int64(len(nodeInfo.Pods()))+1 > allowedPodNumber {
|
|
||||||
return false,
|
return false,
|
||||||
newInsufficientResourceError(podCountResourceName, 1, int64(len(nodeInfo.Pods())), allowedPodNumber)
|
newInsufficientResourceError(podCountResourceName, 1, int64(len(nodeInfo.Pods())), int64(allowedPodNumber))
|
||||||
}
|
}
|
||||||
|
|
||||||
var podRequest *resourceRequest
|
var podRequest *resourceRequest
|
||||||
@ -491,6 +490,7 @@ func PodFitsResources(pod *api.Pod, meta interface{}, nodeInfo *schedulercache.N
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allocatable := node.Status.Allocatable
|
||||||
totalMilliCPU := allocatable.Cpu().MilliValue()
|
totalMilliCPU := allocatable.Cpu().MilliValue()
|
||||||
totalMemory := allocatable.Memory().Value()
|
totalMemory := allocatable.Memory().Value()
|
||||||
totalNvidiaGPU := allocatable.NvidiaGPU().Value()
|
totalNvidiaGPU := allocatable.NvidiaGPU().Value()
|
||||||
@ -507,8 +507,12 @@ func PodFitsResources(pod *api.Pod, meta interface{}, nodeInfo *schedulercache.N
|
|||||||
return false,
|
return false,
|
||||||
newInsufficientResourceError(nvidiaGpuResourceName, podRequest.nvidiaGPU, nodeInfo.RequestedResource().NvidiaGPU, totalNvidiaGPU)
|
newInsufficientResourceError(nvidiaGpuResourceName, podRequest.nvidiaGPU, nodeInfo.RequestedResource().NvidiaGPU, totalNvidiaGPU)
|
||||||
}
|
}
|
||||||
glog.V(10).Infof("Schedule Pod %+v on Node %+v is allowed, Node is running only %v out of %v Pods.",
|
if glog.V(10) {
|
||||||
|
// We explicitly don't do glog.V(10).Infof() to avoid computing all the parameters if this is
|
||||||
|
// not logged. There is visible performance gain from it.
|
||||||
|
glog.Infof("Schedule Pod %+v on Node %+v is allowed, Node is running only %v out of %v Pods.",
|
||||||
podName(pod), node.Name, len(nodeInfo.Pods()), allowedPodNumber)
|
podName(pod), node.Name, len(nodeInfo.Pods()), allowedPodNumber)
|
||||||
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@ type NodeInfo struct {
|
|||||||
requestedResource *Resource
|
requestedResource *Resource
|
||||||
pods []*api.Pod
|
pods []*api.Pod
|
||||||
nonzeroRequest *Resource
|
nonzeroRequest *Resource
|
||||||
|
// We store allowedPodNumber (which is Node.Status.Allocatable.Pods().Value())
|
||||||
|
// explicitly as int, to avoid conversions and improve performance.
|
||||||
|
allowedPodNumber int
|
||||||
|
|
||||||
// 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.
|
||||||
@ -59,6 +62,7 @@ func NewNodeInfo(pods ...*api.Pod) *NodeInfo {
|
|||||||
ni := &NodeInfo{
|
ni := &NodeInfo{
|
||||||
requestedResource: &Resource{},
|
requestedResource: &Resource{},
|
||||||
nonzeroRequest: &Resource{},
|
nonzeroRequest: &Resource{},
|
||||||
|
allowedPodNumber: 0,
|
||||||
generation: 0,
|
generation: 0,
|
||||||
}
|
}
|
||||||
for _, pod := range pods {
|
for _, pod := range pods {
|
||||||
@ -83,6 +87,13 @@ func (n *NodeInfo) Pods() []*api.Pod {
|
|||||||
return n.pods
|
return n.pods
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *NodeInfo) AllowedPodNumber() int {
|
||||||
|
if n == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return n.allowedPodNumber
|
||||||
|
}
|
||||||
|
|
||||||
// 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 {
|
||||||
@ -105,6 +116,7 @@ func (n *NodeInfo) Clone() *NodeInfo {
|
|||||||
node: n.node,
|
node: n.node,
|
||||||
requestedResource: &(*n.requestedResource),
|
requestedResource: &(*n.requestedResource),
|
||||||
nonzeroRequest: &(*n.nonzeroRequest),
|
nonzeroRequest: &(*n.nonzeroRequest),
|
||||||
|
allowedPodNumber: n.allowedPodNumber,
|
||||||
pods: pods,
|
pods: pods,
|
||||||
generation: n.generation,
|
generation: n.generation,
|
||||||
}
|
}
|
||||||
@ -181,6 +193,7 @@ func calculateResource(pod *api.Pod) (cpu int64, mem int64, nvidia_gpu int64, no
|
|||||||
// Sets the overall node information.
|
// Sets the overall node information.
|
||||||
func (n *NodeInfo) SetNode(node *api.Node) error {
|
func (n *NodeInfo) SetNode(node *api.Node) error {
|
||||||
n.node = node
|
n.node = node
|
||||||
|
n.allowedPodNumber = int(node.Status.Allocatable.Pods().Value())
|
||||||
n.generation++
|
n.generation++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -192,6 +205,7 @@ func (n *NodeInfo) RemoveNode(node *api.Node) error {
|
|||||||
// and thus can potentially be observed later, even though they happened before
|
// and thus can potentially be observed later, even though they happened before
|
||||||
// node removal. This is handled correctly in cache.go file.
|
// node removal. This is handled correctly in cache.go file.
|
||||||
n.node = nil
|
n.node = nil
|
||||||
|
n.allowedPodNumber = 0
|
||||||
n.generation++
|
n.generation++
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user