Skip to content

Port-forward relay sets TCP_NODELAY on both of its sockets - #1350

Merged
ejc3 merged 1 commit into
mainfrom
relay-nodelay
Oct 26, 2026
Merged

ejc3 merged 1 commit into
mainfrom
relay-nodelay

Conversation

@ejc3

@ejc3 ejc3 commented Oct 26, 2026

Copy link
Copy Markdown
Owner

The port-forward relay sets TCP_NODELAY on its client and upstream sockets.

Why

The staging wall's fcvm tiles reach a browser without IPv6 through the host's IPv4 slot ports, which this relay serves (routed mode). The relay copied with Nagle on, so a write following one the peer had not acknowledged waited for the peer's delayed ACK (40 ms on Linux, longer on macOS). A renderer frame is TLS records written back to back, so every frame's tail waited.

Measured on staging from a Linux client: frame arrival minus the frame's scene time, minus each renderer's clock offset (its /health t):

over IPv6 (routed /128) over IPv4 (this relay)
fcvm tiles 1-8 55 to 90 ms 86 to 118 ms
EC2 tiles 1-8 59 to 88 ms same as IPv6

On the owner's Mac (IPv4 only) the fcvm frames arrived 142 to 191 ms after their scene time against 36 to 48 ms for EC2; about 100 ms of that is the fcvm guests' clocks, which #1343 addresses.

Change

spawn_relay_loop sets TCP_NODELAY on both streams before copy_bidirectional. A failure is logged and the relay continues as before. The endpoints keep their own settings.

Evidence

  • a_message_written_in_two_parts_crosses_the_relay_without_waiting_for_an_ack: 16 KB then 12 KB through the relay to a client with quick ACK turned off. On main all 30 messages took 40.7 to 44.9 ms (observed failing twice); with the change the median is under 15 ms.
  • make test-root FILTER="-E 'test(/tcp_proxy|port_forward|publish/)'": 93 passed (rootless, bridged and routed port forwards, clone port forwards, the stress test). make lint clean.

Contract and impact

Contract: the relay adds no coalescing delay. Host-side; staging gets it with the next fleet host AMI.

The relay behind a routed VM's published ports (and --forward-localhost
and the proxy relay) copied bytes with Nagle on. A write that follows one
the peer has not acknowledged then waits for the peer's delayed ACK: 40 ms
on Linux, longer on macOS. A renderer frame is TLS records written back
to back, so through the relay every frame's tail waited for that ACK.

Measured on the staging wall from a Linux client, frame arrival minus the
frame's scene time, renderer clock offset removed: the fcvm tiles over the
host's IPv4 slot ports (this relay) arrived 30 to 35 ms later than over
their routed IPv6 addresses; the EC2 tiles arrived the same over both.

Test: a_message_written_in_two_parts_crosses_the_relay_without_waiting_for_an_ack
writes 16 KB then 12 KB through the relay to a client with quick ACK off.
Without TCP_NODELAY every one of 30 messages took 40.7 to 44.9 ms (the
client's delayed-ACK timer); with it the test passes under 15 ms.
make test-root with tcp_proxy, port_forward and publish tests: 93 passed.
make lint clean.
@ejc3

ejc3 commented Oct 26, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@coderabbitai

coderabbitai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 22 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1560aeb1-5e89-4a73-9d8e-14af6f545724
Commits

Reviewing files that changed from the base of the PR and between 2a07796 and 12cee0a.

Files selected for processing: 1
  • src/network/tcp_proxy.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T22:15:17.063969Z 12cee0a Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 12cee0a687

ℹ️ 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".

@ejc3
ejc3 merged commit 2c965af into main Oct 26, 2026
8 of 15 checks passed
@ejc3
ejc3 deleted the relay-nodelay branch October 26, 2026 22:17
ejc3 added a commit to ejc3/aws that referenced this pull request Oct 26, 2026
ami-0084954a5dfe26bf6 (47ec5fcf) -> ami-00d8ecc3edfb8059e (2c965afe), which
adds ejc3/fcvm#1350: the relay behind a GPU host's IPv4 slot ports sets
TCP_NODELAY, so a frame's second TLS record no longer waits for the
browser's delayed ACK. The renderer source is unchanged from 31f42d03, so
the tile AMI stays.

Checked on a g4dn.metal launched from the new AMI: store restored from S3,
a routed GPU restore within 4 to 8 ms of the host for 20 s, chronyd with an
IPv6 NTP source.
ejc3 added a commit to ejc3/aws that referenced this pull request Oct 27, 2026
…P_NODELAY) (#699)

* fcvm-fleet: host and tile AMIs from ejc3/fcvm main 47ec5fcf

On the wall's staging page every fcvm tile was drawn dimmed as behind
the common time: each fcvm VM's clock was 0.2 to 1.0 s behind the host.
The host AMI (bdaa0003) predates ejc3/fcvm#1301, so its fc-agent stepped
a restored guest to the whole second, and a routed guest reached no NTP
server to correct it (ejc3/fcvm#1343).

- us-east-1 host AMI ami-0913aacc80394e1bd -> ami-0084954a5dfe26bf6,
  built from ejc3/fcvm main 47ec5fcf (fleet/ami/host, revised from the
  previous image; store under store/fcvm-fleet-host-x86_64-47ec5fcf-20261026/).
- us-east-1 tile AMI ami-08f3cc41395353a2f -> ami-07bf015c4588aebc2,
  revised from the previous image with the host AMI's renderer image
  (same image id), so both halves draw with one renderer.

Checked on a g4dn.metal launched from the new host AMI: store restored
from S3 (16 parts, 9.5 s), a routed GPU restore landed within 5 ms of the
host and chronyd selected an IPv6 NTP server; a clock set 700 ms back
was within 7 ms again 10 s after chronyd's next poll. The tile builder's
renderer reached its first frame (image phase).

Tested: python3 -S -B scripts/test-fcvm-fleet.py OK, terraform fmt -check.

* fcvm-fleet: host AMI from ejc3/fcvm main 2c965afe

ami-0084954a5dfe26bf6 (47ec5fcf) -> ami-00d8ecc3edfb8059e (2c965afe), which
adds ejc3/fcvm#1350: the relay behind a GPU host's IPv4 slot ports sets
TCP_NODELAY, so a frame's second TLS record no longer waits for the
browser's delayed ACK. The renderer source is unchanged from 31f42d03, so
the tile AMI stays.

Checked on a g4dn.metal launched from the new AMI: store restored from S3,
a routed GPU restore within 4 to 8 ms of the host for 20 s, chronyd with an
IPv6 NTP source.

---------

Co-authored-by: ejc3 <ejc3@users.noreply.github.com>
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