Skip to content

perf(operator): mimalloc allocator + label-scope the Job watch#53

Merged
passcod merged 1 commit into
mainfrom
operator-memory-reduce
Jun 4, 2026
Merged

perf(operator): mimalloc allocator + label-scope the Job watch#53
passcod merged 1 commit into
mainfrom
operator-memory-reduce

Conversation

@passcod

@passcod passcod commented Jun 4, 2026

Copy link
Copy Markdown
Member

Two related changes to reduce the operator's resident memory.

1. mimalloc as global allocator. Long-running Rust services on glibc commonly hold significantly more RSS than the live heap due to fragmentation and retained chunks. mimalloc keeps RSS closer to working-set size, which matters for a controller that runs indefinitely and was hitting tight memory limits.

2. Scope the Job watch to pgro-owned Jobs. The previous .watches(Api::<Job>::all(...), Config::default(), ...) was cluster-wide with no label selector, so kube-rs cached every Job in every namespace (CI runners, batch tasks, cert-manager renewals, etc.) in the in-memory store. Restricting to Jobs carrying the pgro.bes.au/replica label cuts the watched set to only the four Job types the operator builds — restore, snapshot-list, schema-migration, credential-reset — all of which already set that label.

Together these reduce the operator's RSS substantially in clusters with significant non-pgro Job activity, and reduce baseline RSS even in pgro-only clusters via the allocator change.

Follow-up coming separately: connection pooling for the per-reconcile postgres connections (currently 3-4 fresh TCP connections per reconcile_schema_migration).

Two related changes to bring the operator's resident memory down.

1. mimalloc as global allocator. Long-running Rust services on glibc
   commonly hold significantly more RSS than the live heap due to
   fragmentation and retained chunks. mimalloc keeps RSS closer to
   working-set size, which matters for a controller that runs
   indefinitely and was previously OOMKilled at a tight limit.

2. Scope the Job watch to pgro-owned Jobs via the
   pgro.bes.au/replica label selector. The previous watch was
   cluster-wide across all namespaces with no filter, so kube-rs
   cached every Job in the cluster — CI runners, batch tasks,
   cert-manager renewals, etc. — in the in-memory store. Restricting
   to Jobs that carry the pgro.bes.au/replica label cuts the watched
   set to only restore Jobs, snapshot-list Jobs, schema-migration
   Jobs, and credential-reset Jobs, all of which the operator builds
   with that label.

Together these reduce the operator's RSS substantially in clusters
with significant non-pgro Job activity, and reduce baseline RSS even
in pgro-only clusters via the allocator change.
@passcod passcod enabled auto-merge June 4, 2026 10:00
@passcod passcod merged commit 40234bb into main Jun 4, 2026
18 checks passed
@passcod passcod deleted the operator-memory-reduce branch June 4, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant