Skip to content

Configurable concurrent resolution of subscription items - #2

Merged
amnn merged 1 commit into
amnn:v7.0.1-react-18-graphiql-4from
tpham-mysten:tpham-mysten/buffered-subscription-resolution
Jul 31, 2026
Merged

amnn merged 1 commit into
amnn:v7.0.1-react-18-graphiql-4from
tpham-mysten:tpham-mysten/buffered-subscription-resolution

Conversation

@tpham-mysten

@tpham-mysten tpham-mysten commented Jul 21, 2026 •

Copy link
Copy Markdown

What

Opt-in SchemaBuilder::subscription_resolution_concurrency(n). Default n = 1 is unchanged (serial). With n > 1, up to n subscription payloads resolve concurrently, in output order, so their per-payload DataLoader reads coalesce instead of one round trip per payload.

Why

async-graphql resolves subscription payloads serially (StreamExt::then), so a subscription emitting many payloads, each doing its own DataLoader reads, pays a round trip per payload. The usual workaround is to emit a batched list, which leaks the batch shape into the schema. Resolving payloads concurrently lets those reads coalesce like a hand-rolled batch, so an idiomatic one-item-per-payload subscription stays efficient without changing the schema. Decided in MystenLabs/sui#27140 (comment).

How

  • Derive: then becomes buffered(n) (ordered), so payloads resolve concurrently but deliver in submission order.
  • Error isolation: the request error sink moves off QueryEnvInner onto QueryEnv (Arc<Mutex<Vec<ServerError>>>), and each payload gets a fresh sink via fork_errors(). Without it, concurrently-resolved payloads would drain a shared sink and cross-contaminate errors. Queries and mutations never fork, so their behavior is unchanged.
  • Default 1 (serial); values below 1 clamp to 1.

Tests

  • test_subscription_resolution_concurrency: a barrier releases only if the payloads resolve concurrently (a timeout catches the serial case), and asserts output stays in submission order.
  • test_subscription_resolution_error_isolation: several payloads record an error behind a barrier; each response must carry exactly its own. Fails without fork_errors.
  • Existing subscription and query/mutation suites unchanged.

@tpham-mysten
tpham-mysten force-pushed the tpham-mysten/buffered-subscription-resolution branch from c54816b to 292035e Compare July 21, 2026 15:36
@tpham-mysten
tpham-mysten force-pushed the tpham-mysten/buffered-subscription-resolution branch from 292035e to 2a4ecc5 Compare July 27, 2026 15:34
@tpham-mysten tpham-mysten changed the title Resolve subscription items with bounded concurrency Configurable concurrent resolution of subscription items Jul 27, 2026
@tpham-mysten
tpham-mysten force-pushed the tpham-mysten/buffered-subscription-resolution branch 4 times, most recently from b5cb9ea to f5d40c3 Compare July 27, 2026 16:35
@tpham-mysten
tpham-mysten marked this pull request as ready for review July 28, 2026 16:54
@amnn
amnn self-requested a review July 28, 2026 17:04
tpham-mysten added a commit to MystenLabs/sui that referenced this pull request Jul 31, 2026
…rent resolution

Flip the transaction subscription schema from the batched `[TransactionEdge!]!` to
`TransactionEdge!` (one edge per payload, like checkpoint/event), and resolve payloads
concurrently via async-graphql's `buffered` (SubscriptionConfig.max_concurrent_resolutions,
default 100) so the per-payload KvLoader content reads coalesce instead of one round trip
per transaction.

Backfill scans through the shared `scan_grpc` with cvat=None (uniform with live, no
consistent reads); the scan page is derived from the resolve concurrency so one scan feeds
roughly one resolution window. Depends on amnn/async-graphql#2 for the `buffered` support;
the `[patch]` points at that PR branch until it merges into amnn's branch.

Add e2e reliability tests: live gap recovery, high-volume concurrent exactly-once + ordering,
KvLoader read coalescing under concurrency, and invalid-cursor error surfacing. Add a
serial-vs-concurrent backfill benchmark (200 txs: 401 round trips / 1.0s serial vs 5 round
trips / 79ms concurrent) plus a manual server harness.
tpham-mysten added a commit to MystenLabs/sui that referenced this pull request Jul 31, 2026
The buffered subscription support lives on a fork branch; restore the amnn base for a mergeable manifest. Build is red until amnn/async-graphql#2 lands and the lock is bumped.
tpham-mysten added a commit to MystenLabs/sui that referenced this pull request Jul 31, 2026
…rent resolution

Flip the transaction subscription schema from the batched `[TransactionEdge!]!` to
`TransactionEdge!` (one edge per payload, like checkpoint/event), and resolve payloads
concurrently via async-graphql's `buffered` (SubscriptionConfig.max_concurrent_resolutions,
default 100) so the per-payload KvLoader content reads coalesce instead of one round trip
per transaction.

Backfill scans through the shared `scan_grpc` with cvat=None (uniform with live, no
consistent reads); the scan page is derived from the resolve concurrency so one scan feeds
roughly one resolution window. Depends on amnn/async-graphql#2 for the `buffered` support;
the `[patch]` points at that PR branch until it merges into amnn's branch.

Add e2e reliability tests: live gap recovery, high-volume concurrent exactly-once + ordering,
KvLoader read coalescing under concurrency, and invalid-cursor error surfacing. Add a
serial-vs-concurrent backfill benchmark (200 txs: 401 round trips / 1.0s serial vs 5 round
trips / 79ms concurrent) plus a manual server harness.
tpham-mysten added a commit to MystenLabs/sui that referenced this pull request Jul 31, 2026
The buffered subscription support lives on a fork branch; restore the amnn base for a mergeable manifest. Build is red until amnn/async-graphql#2 lands and the lock is bumped.

@amnn amnn left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me! Just a small nit.

Not urgent but we can look to upstream this as well.

Comment thread derive/src/subscription.rs Resolved
@tpham-mysten
tpham-mysten force-pushed the tpham-mysten/buffered-subscription-resolution branch from f5d40c3 to 49ac083 Compare July 31, 2026 16:04
Subscription payloads are resolved strictly serially (StreamExt::then in the derive), so a
subscription resolving DB-backed fields does one backend round trip per payload with no DataLoader
batching across payloads.

Add a subscription_resolution_concurrency knob to SchemaBuilder (default 1, i.e. serial, so existing
behavior is unchanged). When set > 1, the derive resolves up to N subscription items concurrently with
buffered(N) (output order preserved via FuturesOrdered), so their DataLoader reads coalesce the same
way a list's do within a payload. A server opts in with
Schema::build(...).subscription_resolution_concurrency(n).

The one correctness fix it needs: all items shared a single QueryEnvInner.errors sink drained per-item,
which only works serially. Move errors from Arc<QueryEnvInner> onto QueryEnv and add fork_errors() so
each concurrently-resolved item gets its own sink. Field shadowing keeps every existing errors read
site unchanged, and queries/mutations never fork, so their behavior is untouched.

@tpham-mysten tpham-mysten left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @amnn. I just asked Claude to upstream this on async-graphql#1833

@amnn
amnn merged commit 5224a1c into amnn:v7.0.1-react-18-graphiql-4 Jul 31, 2026
tpham-mysten added a commit to MystenLabs/sui that referenced this pull request Aug 5, 2026
…27537)

## Description

Resolve subscription payloads concurrently rather than one at a time. A
single `max_concurrent_resolutions` config drives both the resolve
window (async-graphql's `subscription_resolution_concurrency`, now
[merged](amnn/async-graphql#2)) and the backfill
scan page, so a batch's matches resolve within the concurrency budget
and coalesce their content reads into one `KvLoader` round trip.

## Test plan

- e2e parity test
(`test_transaction_subscription_live_backfill_parity`): the same
transactions resolve identically whether delivered live or through the
backfill scan, plus the existing streaming/ordering/resume subscription
tests.
- Batching e2e tests:
`test_transaction_subscription_backfill_batches_matches` (a deep
backfill packs matches into multi-edge payloads) and
`test_transaction_subscription_live_batches_per_checkpoint` (each live
payload is one checkpoint's matches).
- Unit tests for the scan retry: recovers within the budget, gives up
once it is exhausted.

---

## Stack
   - #26019
   - #26094
   - #26117
   - #26170
   - #26194
   - #26202
   - #26414
   - #26453
   - #26476
   - #26487
   - #26425
   - #26495
   - #26731
   - #26714
   - #27140
   - #27537

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] gRPC:
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] Indexing Framework:
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.

2 participants