Repository navigation
fix(providers): send provider replies without a 40 ms delay - #13381
Merged
Merged
Conversation
tf-provider serves each provider's gRPC over TCP without TCP_NODELAY, so every reply waited on Nagle's algorithm and OpenTofu's delayed acknowledgment: about 40 ms per provider call. Vendor tf-provider at its pinned revision and set TCP_NODELAY on accepted connections. The OpenShell contract tests drop from 227 s to 87 s run serially.
Contributor
cv
added a commit
that referenced
this pull request
Oct 17, 2026
… reply delay (#13382) ## Failure #13381 committed `crates/vendor/tf-provider/target/`: 1,908 files, about 574 MB of Cargo build output. `.gitignore` ignored only the root `/target/`, and `NOTICE.md` tells contributors to run `cargo test --manifest-path crates/vendor/tf-provider/Cargo.toml`, which creates that directory and an untracked `Cargo.lock` beside it. Every fetch of `v1` since then downloads the build output. #13381 also left one 40 ms reply delay in the tests. The fake OpenShell gateway in `crates/nemoclaw-test-fixtures/src/openshell.rs` serves without `TCP_NODELAY`, so each reply to the provider waits on Nagle's algorithm and the provider's delayed acknowledgment, the delay #13381 removed from `tf-provider`. ## Decision - Delete `crates/vendor/tf-provider/target/`. - Ignore `target/` at any depth, and `/crates/vendor/tf-provider/Cargo.lock`, which `NOTICE.md` says the copy omits. - Set `TCP_NODELAY` on each connection the fake gateway accepts, as `tf-provider` now does. - Lower the provider contract budgets in `.config/test-budgets.yaml` and the matching per-test timeouts in `.config/nextest.toml` to the measured times plus margin. This commit does not shrink the repository's history: the build output stays in `1844e321f4`. Removing it would require rewriting `v1`. ## Validation `openshell-provider` contract tests in an Ubuntu 24.04 arm64 VM (8 CPUs) with the linux_arm64 CI bundle. That VM reproduced CI's per-test times before either fix. | Build | Serial | 4 threads | |---|---|---| | Before #13381 | 171 s | 43 s | | `tf-provider` fix only (measured with the same patch) | 80 s | 19 s | | This branch | 21.2 s | 7.0 s | Also ran `cargo fmt --all --check`, Clippy for `nemoclaw-test-fixtures`, and `cargo test --manifest-path crates/vendor/tf-provider/Cargo.toml`, after which `git status` showed no untracked files. Linux CI, this PR's first run (39015106152) against `v1` after #13381 (39005227268) and before it (#13378, attempt 3): | Binary, summed | Before #13381 | After #13381 | This PR | |---|---|---|---| | `openshell-provider::contract`, amd64 / arm64 | 182.4 / 175.9 s | 106.7 / 88.0 s | 56.3 / 48.6 s | | `nemoclaw-provider::contract`, amd64 / arm64 | 55.9 / 50.3 s | 31.8 / 22.4 s | 27.5 / 23.2 s | | `fabric-provider::contract`, amd64 / arm64 | 34.3 / 36.7 s | 21.6 / 22.1 s | 13.5 / 14.4 s | New budgets, summed / per test: `openshell-provider::contract` 80 / 6 s (was 190 / 12), `nemoclaw-provider::contract` 45 / 8 s (was 110 / 10), `fabric-provider::contract` 25 / 10 s (was 40 / 22). They rest on one run per platform. `cargo test -p nemoclaw-build --test integration ci::` checks that the budgets and nextest timeouts agree.
cv
added a commit
that referenced
this pull request
Oct 19, 2026
…13445) ## Failure `kubernetes::connection::forward` relays local connections to a Kubernetes gateway through a port-forward, but it doesn't set `TCP_NODELAY` on the local connections it accepts. When a reply from the cluster arrives in pieces, such as a gRPC response's frames, each piece after the first waits for the client's delayed acknowledgment of the one before. That's about 40 ms on Linux, the same delay #13381 and #13382 removed from provider and fake-gateway replies. In an Ubuntu 24.04 arm64 VM, a fake gateway that answers each one-byte request with two writes 1 ms apart took 44 ms per round trip through `forward`, and 2.7 ms with `TCP_NODELAY`. I have not measured a real port-forward to a cluster. ## Change Set `TCP_NODELAY` on each local connection `forward` accepts. A connection that refuses the option is still relayed. ## Validation - New test `forwarded_replies_arriving_in_pieces_reach_the_client_promptly` in `crates/nemoclaw-sdk/tests/kubernetes_connection.rs` requires a median round trip under 20 ms. In the Linux VM it failed before the change (41.9 ms) and passed three times after it. macOS doesn't show the delay, so the test passes there either way. - `cargo test -p nemoclaw-sdk --test integration kubernetes`: 136 passed on Linux (VM) and macOS. - `cargo fmt --all --check` and Clippy for `nemoclaw-sdk`. ## Checked and left unchanged These were also missing `TCP_NODELAY`; the same VM showed no delay, so this PR doesn't touch them: - **Ollama proxy** (`crates/nemoclaw-ollama-proxy`): streamed chunks arrived 0.1 ms after the daemon wrote them, with and without the option, at 10, 2 and 1 ms between chunks. - **Shared HTTP test fixture** (`crates/test-support/http.rs`): it closes each connection right after replying, which sends the held body. The 135 SDK Kubernetes tests took 4.4–4.9 s before and 4.9–5.5 s after. Not measured: kube's client connects with hyper-util's `HttpConnector::new()`, which leaves `TCP_NODELAY` off on our connections to the Kubernetes API server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Failure
Every provider call from OpenTofu took about 40 ms, regardless of the work it did.
tf-provider, which serves all our providers' gRPC, listens on TCP and never setsTCP_NODELAYon accepted connections. So each small reply waits on Nagle's algorithm and OpenTofu's delayed acknowledgment.In the OpenShell contract tests, OpenTofu commands took 223 of 227 seconds: 140 applies at about 1.0 s and 120 plans at about 0.6 s. A trace of one apply shows 24 schema calls and other provider calls, each about 40 ms apart, while the provider's own schema work takes microseconds. Users pay this on every plan, apply, and destroy. The stall also pushed #13375's contract binaries over their CI test-duration budgets.
Decision
Vendor
tf-providerat its pinned revision undercrates/vendor/tf-provider, asopenshell-sdkis, and setTCP_NODELAYon each accepted connection (without_delayinsrc/server.rs). The root manifest patchestf-providerto the copy.NOTICE.mdrecords the source revision, the omitted files, and the changes. The fix is also reported upstream in aneoconsulting/tf-provider#21; remove the copy once upstream setsTCP_NODELAY.Validation
cargo test --manifest-path crates/vendor/tf-provider/Cargo.toml) failed against the unchanged behavior and passes with the fix.cargo cidoesn't run vendored crates' tests.cargo cipasses locally: 1543 unit tests and 152 lifecycle tests. The lifecycle step took 91 s, against 144 s for a comparablev1run.