Skip to content

perf(syncer): skip no-op commits in group membership/ownership reconcile#550

Closed
somethingnew2-0 wants to merge 1 commit into
mainfrom
pcollins/syncer-skip-noop-commits
Closed

perf(syncer): skip no-op commits in group membership/ownership reconcile#550
somethingnew2-0 wants to merge 1 commit into
mainfrom
pcollins/syncer-skip-noop-commits

Conversation

@somethingnew2-0

Copy link
Copy Markdown
Collaborator

What & why

Profiling the sync cron showed the group membership/ownership phase dominates the ~26-min run, and — surprisingly — raising --group-fetch-concurrency didn't help: Okta's /api/v1/groups* rate limit sat at ~50% utilization regardless of the setting. That rules out fetch concurrency as the bottleneck; the sync is bound by the serial per-group DB round trips in the reconcile loops.

Each group did a SELECT (current members/owners) and a commit() — two round trips per group. But in authoritative mode the reconciliation writes to Okta, not the DB, so the per-group commit() is a no-op: pure overhead, ~N wasted round trips.

This commits only when a group actually wrote to the DB (non-authoritative drift), plus once every _RECONCILE_COMMIT_EVERY (100) groups to release the read snapshot the SELECTs hold. For a steady-state authoritative run that roughly halves the per-group DB round trips.

What it deliberately does not do

  • No bulk-load of all memberships. A start-of-run snapshot would (a) balloon pod memory (relevant given past OOMs) and (b) go stale over the ~26-min run — in authoritative mode a stale view could re-push a membership a concurrent UI change had just removed. The per-group SELECT stays, so each group reads fresh committed state.
  • Freshness is safe because Postgres defaults to READ COMMITTED: even with the read transaction held open across several groups, each SELECT sees a fresh snapshot of committed data, including UI changes made mid-run. The periodic commit just bounds how long that read snapshot pins xmin.

Notes

🤖 Generated with Claude Code

The reconcile loops committed once per group, but authoritative sync
writes to Okta, not the DB, so those commits are no-ops — two DB round
trips per group (SELECT + COMMIT) where one suffices. Commit only after a
group that actually wrote to the DB (non-authoritative drift), plus every
_RECONCILE_COMMIT_EVERY groups to release the read snapshot the per-group
SELECTs hold. The per-group SELECT stays, so reads remain fresh under
READ COMMITTED — no stale start-of-run snapshot and no bulk load into
memory.

This is the change that moves the needle: measurement showed the sync is
bounded by the serial per-group DB round trips, not Okta fetch
concurrency (raising --group-fetch-concurrency had no effect against a
~50%-utilized rate limit).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@somethingnew2-0

Copy link
Copy Markdown
Collaborator Author

Not sure if I like this solution. It feels like a hack and database commits probably don't outweigh database loads of group memberships being reducing the number of requests to the database being made.

@somethingnew2-0

Copy link
Copy Markdown
Collaborator Author

Closing for now

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