Action plan render once - #2067
Conversation
Since the action plan was added to the CR status write path, every status update re-renders ActionPlan.String() while building the aux status ConfigMap payload: each call reflection-dumps every diffed object (the full value is rendered, then truncated to 256 chars) and iterates the diff maps in randomized order, so the very same plan produces different bytes on every call. During a horizontal expansion, status updates are issued several times per host - thousands of renderings of a diff that lists every added shard, where 0.25.x rendered the plan exactly once per reconcile (LogActionPlan). This is a major CPU cost on the reconcile hot path (operator CPU observed pinned for the duration of large expansions). Render the plan exactly once, eagerly in MakeActionPlan, and make String() return that stable snapshot. This restores the once-per-reconcile rendering frequency that existed before the plan moved into the storage path, while keeping the storage feature. The plan is immutable after construction and every reconcile already renders it at least once for logs, so eager rendering adds no new work. Repeated String() calls become byte-stable, which also allows content comparison on the stored plan downstream. Zero-value or JSON-unmarshaled plans render as "" exactly as before. Signed-off-by: Erikas Balynas <ebalynas@paloaltonetworks.com>
|
Found this running your patch on top of 0.27.3:
Easiest way to see it is with #2070 also applied: its One line: if ap.specDiffReverse != nil && len(ap.specDiffReverse.Modified) > 0 {Happy to push that as a commit if it's easier. |
Fixes #2066.
ActionPlan.String()is called on every status update attempt while building the status storage ConfigMap data. Each call re-renders the diff from scratch: reflection-dumps every diffed object (the full value is rendered, then truncated to 256 chars) and iterates the diff maps in random order, so the same plan produces different bytes on every call. During a scale-up of a large CHI this runs thousands of times per reconcile and dominates operator CPU (details and measurements in the issue).This PR renders the plan once, eagerly in
MakeActionPlan, and makesString()return that snapshot. The plan is immutable after construction, and every reconcile already renders it at least once for logging, so this adds no new work — it just stops repeating it. Before the plan was moved into the status path, it was rendered once per reconcile (LogActionPlan); this restores that frequency while keeping the storage feature.Behavior notes:
String()now returns the same bytes on every call. The storedstatus-actionPlantext becomes a construction-time snapshot. It is write-only (never parsed back), so nothing consumes the difference."", same as before.Measured on a 156-host CHI, scaling 2 clusters 20 → 39 shards each: 0.28.0 + this change completes in 18–21 min where 0.27.1 took ~1h41m with operator CPU pinned; status update conflict retries drop ~10x.