Repository navigation
perf(postgres): optimize task and push write paths under high concurrency - #219
Conversation
|
@codex, do full review of this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 345553ec2d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
345553e to
e672e4b
Compare
|
@codex review this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c7f02792e0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: beb77bf2c0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review this pr again |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c8c3d98553
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review this PR again |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
This does not provide enough improvements to be merged... Let's continue experimenting. |
Replace transaction/SELECT FOR UPDATE history appends with bounded revision-checked optimistic updates. - preserve concurrent history appends without long row locks - protect against delete/recreate ABA with created_sequence - add deterministic contention and recreation coverage - distinguish optimistic history snapshots in PostgreSQL diagnostics - keep retry behavior bounded under contention
|
OK, no more time for experiments. This can be merged now. Next goal is to finish #209 and fix a few tech. debt issues. After that the next minor release (0.5.0) can be published The following minor release (0.6.0) should focus on async I/O |
Motivation
Issue #206 identified PostgreSQL write saturation between concurrency 16 and 64 while connection-pool acquisition remained negligible. The goal of this PR is to remove measured SDK/SQL/schema overhead from the affected task and push write paths without weakening correctness, transaction safety, least-privilege behavior, or TCK compatibility.
What changed
PostgreSQL write-path diagnostics
postgres-writeprofile with PostgreSQL-side diagnostics for:MultiXactMember/MultiXactOffsetSLRU activity;task_history_snapshotreads from legacytask_history_lock_readattribution.EXPLAIN ANALYZEinsert probes.Push-config create/delete coordination
FOR KEY SHAREcoordination with schema-scoped transaction advisory locks.BEFORE DELETEtrigger.REPEATABLE READ/SERIALIZABLE, where a stale transaction snapshot could otherwise survive an advisory-lock wait.UPDATE.Push write amplification
ORDER BY created_sequence.(task_id, config_id)primary key as the write/conflict index.Task send path
Optimistic task-history writes
SELECT ... FOR UPDATEhistory appends with bounded optimistic revision-checked updates.created_sequencein the history CAS predicate to prevent delete/recreate ABA overwrites.Benchmark/API and local-build cleanup
PushConfig_CreateManyon the same public executor/service path used by production.Performance comparison
Sources
Main-equivalent baseline:
32015617204d1e06d66934992e73745297e93f459c7bf41eb22main:1f5ea572b7f3528ee638c5a371b83a59f5e97660Final combined PR (#219 + #221):
32860693863bc8e51fb59e8a56e9b1eceabda061dbdbeb4615a32860693755The focused table below uses five-run medians from
postgres-write, pool size 64.Focused c64 results
PushConfig_CreatePushConfig_CreateManySendMessage_CreateTaskSendMessage_FollowUpExistingTaskThe important change after folding #221 into #219 is that the previous follow-up-task regression is gone. All four focused c64 paths now have higher throughput than the main-equivalent baseline, and three of four also improve both p95 and p99.
SendMessage_CreateTasknow has substantially higher absolute throughput and materially lower tails at c64 even though its c16→c64 percentage is slightly worse because c16 improved even more strongly.Normal in-process PostgreSQL matrix
Across c1/c4/c16/c64 in the normal CI matrix, geometric-mean movement versus the main-equivalent baseline is:
PushConfig_CreatePushConfig_CreateManySendMessage_CreateTaskSendMessage_FollowUpExistingTaskSendMessage_FollowUpAtHistoryDepth/8The normal matrix therefore supports the focused result: the final combined branch no longer has a follow-up-task throughput regression, while create-task remains the largest measured gain.
Structural database evidence
The final profile also shows that the intended work was removed from the hot paths:
SendMessage_CreateTasktask reads/opSendMessage_FollowUpExistingTasktask reads/opThe remaining high-concurrency drop is most visible in push-create, but the final profile still does not point to connection-pool starvation. Residual pressure is primarily PostgreSQL-side write/WAL/buffer contention rather than avoidable SDK connection waiting.
Benchmark comparability note
This PR fixes a correctness bug in the push benchmark fixture: warmup and measured push-create IDs previously overlapped, so the main-equivalent baseline could update warmup rows instead of measuring disjoint creates.
Because of that:
GitHub-hosted runner variability also means small single-digit movements should not be overinterpreted. The focused five-repetition medians are the stronger signal for this PR.