Skip to content

Set TCP_NODELAY on TCP connections - #186

Merged
taylor-a-barnes merged 1 commit into
MolSSI-MDI:masterfrom
paulsaxe:tcp-nodelay
Oct 19, 2026
Merged

taylor-a-barnes merged 1 commit into
MolSSI-MDI:masterfrom
paulsaxe:tcp-nodelay

Conversation

@paulsaxe

Copy link
Copy Markdown
Contributor

Every MDI message goes out as two writes: a small header, then the data. With Nagle's algorithm on, which is the default, the data waits until the header is acknowledged. The receiver delays that ACK (by up to 40 ms on Linux) while it waits for the rest of the message, so many exchanges stall. This PR sets TCP_NODELAY on the socket after connect in tcp_request_connection and after accept in tcp_accept_connection. If setsockopt fails, the connection still works, just as it does today, so the failure is ignored.

Measured cost. LAMMPS drove an ML-potential engine (Python, pymdi) over MDI: 1554 atoms, 1000 MD steps, on a Tesla T4 node. Both codes ran on the same node in the same conda environment:

Transport Loop time
-method MPI 349–353 s
-method TCP 480 s (+128 ms/step)
-method TCP with TCP_NODELAY 348–349 s

The TCP_NODELAY runs used an LD_PRELOAD shim that sets the option at exactly these two call sites. Model compute was the same in every run, so the entire difference is the stall.

Tests. With this change, the non-MPI test suite passes on macOS (arm64): pytest -k "not mpi", 24 passed, including the 10 TCP tests.

🤖 Generated with Claude Code

Each MDI message is sent as two writes, a small header and then the data.
With Nagle's algorithm on, the data waits for the header's ACK, which the
receiver delays (up to 40 ms on Linux), so many exchanges stall. Setting
TCP_NODELAY on the connecting and the accepting socket removes the stall.

Measured with LAMMPS driving an ML potential engine over MDI (1554 atoms,
1000 MD steps, Tesla T4, same node and environment): MPI 349-353 s, TCP
480 s, TCP with TCP_NODELAY 348-349 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.75%. Comparing base (3d0b72b) to head (066862f).

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@taylor-a-barnes
taylor-a-barnes merged commit 0b1b570 into MolSSI-MDI:master Oct 19, 2026
14 checks passed
@taylor-a-barnes

Copy link
Copy Markdown
Collaborator

@paulsaxe Thanks for the update! I'ts now merged.

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