-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Labels
area/performanceIssues or PRs related to performanceIssues or PRs related to performancearea/schedulingkind/featureCategorizes issue or PR as related to a new feature.Categorizes issue or PR as related to a new feature.priority/high
Description
Problem
SchedulerCache embeds a single global sync.Mutex which is locked in both pkg/scheduler/cache/cache.go and pkg/scheduler/cache/event_handlers.go for all operations, including read-heavy code paths (e.g., Snapshot(), String(), IsJobTerminated(), parseErrTaskKey()). Informer callbacks also take the same lock in event handlers. This coarse locking increases contention and makes it easy to accidentally introduce unsafe access as the cache grows.
Why it matters
- Read-only operations block each other and block writes, increasing latency.
Snapshot()and similar methods hold the lock while doing heavy work (clone/iterate), which amplifies contention.- Global lock across handlers and cache logic makes correctness harder to reason about and increases risk of subtle race bugs.
Suggested improvements (incremental)
- Switch to
sync.RWMutexand useRLockfor clearly read-only paths (String(),IsJobTerminated(),parseErrTaskKey(), etc.). - Audit
Snapshot()and avoid mutating data under shared lock; if needed, keep write lock there or refactor to avoid mutation. - (Optional) Consider per-domain locks for
Jobs,Nodes,Queues,CSINodesStatus, etc., or serialize mutations via a worker queue.
References
pkg/scheduler/cache/cache.gopkg/scheduler/cache/event_handlers.go
Expected outcome
Reduced contention and clearer separation of read vs write paths, lowering race-condition risk and improving performance under load.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/performanceIssues or PRs related to performanceIssues or PRs related to performancearea/schedulingkind/featureCategorizes issue or PR as related to a new feature.Categorizes issue or PR as related to a new feature.priority/high