mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
kubelet: Clear the podStatusChannel before invoking syncBatch
The status manager syncBatch() method processes the current state of the cache, which should include all entries in the channel. Flush the channel before we call a batch to avoid unnecessary work and to unblock pod workers when the node is congested. Discovered while investigating long shutdown intervals on the node where the status channel stayed full for tens of seconds. Add a for loop around the select statement to avoid unnecessary invocations of the wait.Forever closure each time.
This commit is contained in:
parent
8722c834e5
commit
8bc5cb01a9
@ -160,13 +160,20 @@ func (m *manager) Start() {
|
||||
syncTicker := time.Tick(syncPeriod)
|
||||
// syncPod and syncBatch share the same go routine to avoid sync races.
|
||||
go wait.Forever(func() {
|
||||
select {
|
||||
case syncRequest := <-m.podStatusChannel:
|
||||
klog.V(5).Infof("Status Manager: syncing pod: %q, with status: (%d, %v) from podStatusChannel",
|
||||
syncRequest.podUID, syncRequest.status.version, syncRequest.status.status)
|
||||
m.syncPod(syncRequest.podUID, syncRequest.status)
|
||||
case <-syncTicker:
|
||||
m.syncBatch()
|
||||
for {
|
||||
select {
|
||||
case syncRequest := <-m.podStatusChannel:
|
||||
klog.V(5).Infof("Status Manager: syncing pod: %q, with status: (%d, %v) from podStatusChannel",
|
||||
syncRequest.podUID, syncRequest.status.version, syncRequest.status.status)
|
||||
m.syncPod(syncRequest.podUID, syncRequest.status)
|
||||
case <-syncTicker:
|
||||
klog.V(5).Infof("Status Manager: syncing batch")
|
||||
// remove any entries in the status channel since the batch will handle them
|
||||
for i := len(m.podStatusChannel); i > 0; i-- {
|
||||
<-m.podStatusChannel
|
||||
}
|
||||
m.syncBatch()
|
||||
}
|
||||
}
|
||||
}, 0)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user