Skip to content

feat(proto): Implement noq_proto::SendStream::set_affinity - #836

Merged
matheus23 merged 14 commits into
mainfrom
matheus23/stream-affinity
Oct 23, 2026
Merged

matheus23 merged 14 commits into
mainfrom
matheus23/stream-affinity

Conversation

@matheus23

@matheus23 matheus23 commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Description

Implements setting a stream's affinity to being sent on paths. See the doc comment on SendStream::set_affinity for more information.

This is implemented via keeping multiple PendingStreamsQueues instead of just one: One queue for each possible affinity, except StreamAffinity::Block, which doesn't need a queue.

On sending in each path, we first check the any queue, and then compare it with pending streams that are pinned to our path.
Between these we compare which one is supposed to go first and use that.

When a stream changes affinity, we need to potentially move it between queues.

If a stream goes from blocked to another affinity, we don't restore its recency, instead, we give it a new one. This is as if the data the stream had queued were submitted just when switching. This is to avoid a situation in which someone suddenly unblocks a lot of small streams after a long time of being blocked and these streams suddenly jumping the queue and starving out other streams.

API Changes

  • Adds noq_proto::StreamAffinity
  • Adds noq_proto::SendStream::set_affinity

Notes & open questions

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All API changes documented.
  • cargo make passes locally.

@matheus23 matheus23 self-assigned this Oct 12, 2026
@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/noq/pr/836/docs/noq/

Last updated: 2026-10-23T10:30:29Z

@n0bot n0bot Bot added this to iroh Oct 12, 2026
@github-project-automation github-project-automation Bot moved this to 🚑 Needs Triage in iroh Oct 12, 2026

@flub flub left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Only reviewed streams/mod.rs for now.

Comment thread noq-proto/src/connection/streams/mod.rs Resolved
Comment thread noq-proto/src/connection/streams/mod.rs Resolved
Comment thread noq-proto/src/connection/streams/mod.rs Resolved
Comment thread noq-proto/src/connection/streams/mod.rs Resolved
Comment thread noq-proto/src/connection/streams/mod.rs Resolved
Comment thread noq-proto/src/connection/streams/mod.rs Resolved
Comment thread noq-proto/src/connection/streams/mod.rs Resolved
Comment thread noq-proto/src/connection/streams/mod.rs Resolved
Comment thread noq-proto/src/connection/streams/mod.rs Resolved
@matheus23
matheus23 force-pushed the matheus23/stream-affinity branch from 5ffc349 to 24a19ff Compare October 14, 2026 15:43
@matheus23
matheus23 marked this pull request as ready for review October 14, 2026 15:44
Comment thread noq-proto/src/connection/streams/mod.rs Resolved
Comment thread noq-proto/src/connection/streams/mod.rs Resolved
Comment thread noq-proto/src/connection/streams/mod.rs Resolved
Comment thread noq-proto/src/connection/streams/mod.rs Resolved
}

if was_pending {
self.pending.remove(id);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't understand how this is now a possibility that there is something to remove now? Was this a bug before?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well, this was already possible before this PR, but it just didn't matter much. We'd go through pending stream items in write_stream_frames later and if there's not actually any data, it's just cleaned up there eventually.

Now we have multiple separate queues, and making sure that when a stream completes, making sure that the pending for it is cleaned up seems like a good idea, given we might not actually look into the queue the stream is in.

Comment thread noq-proto/src/connection/mod.rs Resolved
Comment thread noq-proto/src/connection/mod.rs Resolved
Comment thread noq-proto/src/connection/mod.rs Resolved
Comment thread noq-proto/src/connection/paths.rs Resolved
calex794 added a commit to calex794/noq that referenced this pull request Oct 18, 2026
…to own n0-computer#835 baseline

Preserve fork-specific congestion check, datagram scheduling, alloc/core paths, and existing timer APIs. Include tests for Any, Sticky and Block. Experimental only; no production integration.
@flub
flub added this pull request to stack #854 October 21, 2026 12:26
@matheus23
matheus23 force-pushed the matheus23/stream-affinity branch from 87dc061 to 93ef714 Compare October 22, 2026 08:21
Base automatically changed from matheus23/deprecate-send-fairness to main October 22, 2026 09:18
@matheus23
matheus23 force-pushed the matheus23/stream-affinity branch from 93ef714 to 6941c42 Compare October 22, 2026 09:18
Comment thread Cargo.toml Resolved
Comment thread noq-proto/src/connection/paths.rs Resolved
Comment thread noq-proto/src/connection/mod.rs Resolved
Comment thread noq-proto/src/connection/mod.rs Resolved
@matheus23
matheus23 requested a review from flub October 23, 2026 10:29

@flub flub left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm i think

@matheus23
matheus23 added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit 07047ff Oct 23, 2026
34 checks passed
@matheus23
matheus23 deleted the matheus23/stream-affinity branch October 23, 2026 11:11
@github-project-automation github-project-automation Bot moved this from 🚑 Needs Triage to ✅ Done in iroh Oct 23, 2026
emrul added a commit to GetAster/noq that referenced this pull request Nov 24, 2026
* upstream/main: (24 commits)
  refactor(proto): call the std-only float math through crate-root helpers (n0-computer#848)
  refactor(proto): Avoid PathId allocation when building PATH_ACKS (n0-computer#901)
  chore: Release
  chore(deps): fix unused crates warnings of rust 1.100 (n0-computer#899)
  chore: Update issue template checkboxes (n0-computer#897)
  chore: humantime is unmaintained (n0-computer#900)
  chore(ci): fix workflows for test binaries locations (n0-computer#896)
  fix(perf): don't enable qlog feature in perf binary (n0-computer#850)
  fix(proto): track the key update boundary per path (n0-computer#869)
  tests: additional stream affinity tests (n0-computer#890)
  feat: allow streams to set an affinity for a path, simple version (n0-computer#881)
  fix(udp): handle receive errors before truncation flags in recv_single (n0-computer#884)
  chore: Upgrade async-executor and allow warnings in patchbay build (n0-computer#888)
  chore: Use shared minimal-crates worksflow (n0-computer#862)
  tests: Increase local slow-tests timeout (n0-computer#860)
  fix(proto): keep unread data when compacting an unordered stream (n0-computer#867)
  fix(proto): coalesce contiguous chunks during defragment (n0-computer#866)
  deps: Bump tokio for RUSTSEC-2026-0386 (n0-computer#868)
  feat(proto): Implement `noq_proto::SendStream::set_affinity` (n0-computer#836)
  fix(ci): bump deps for illumos (n0-computer#856)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants