Skip to content

Acknowledge server responses at once on Linux - #27

Merged
bbatsov merged 2 commits into
mainfrom
connections
Oct 20, 2026
Merged

bbatsov merged 2 commits into
mainfrom
connections

Conversation

@bbatsov

@bbatsov bbatsov commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

An eval's done waits in nREPL's socket until the client acknowledges its value, and Linux holds that acknowledgement back 40ms, so every eval on Linux paid 40ms, and since #25, every form did. On the JVM, setting TCP_QUICKACK before each read takes that away: 100 forms went from 4s to 150ms on Linux CI. babashka can't set it, so bb on Linux stays slow until nREPL's and bb's servers set TCP_NODELAY, which is where the real fix belongs.

The other commit gives connecting a 10s timeout, which needed neorepl to open its own socket anyway.

nrepl.core opens its socket without a timeout, so a host that doesn't
answer at all, like one gone from the network, took over a minute to fail.
neorepl now opens the socket itself, giving up after 10 seconds, with
TCP_NODELAY set, so its messages go out as they're written.
nREPL writes an eval's done right after its value, and its sockets go
without TCP_NODELAY, so the done waits in the server's socket until the
client acknowledges the value, which Linux holds back for up to 40ms when
the client has nothing to send. Every eval paid that once, and with an
eval's forms going out one at a time, once a form: 100 forms took 4s on
Linux CI, against 60ms on macOS.

On the JVM, neorepl sets TCP_QUICKACK on its socket before each read, as
Linux leaves quick acknowledgements again once the client sends, and the
same 100 forms take 150ms. babashka has no jdk.net.ExtendedSocketOptions,
so on Linux it waits as before, until servers set TCP_NODELAY.
@bbatsov
bbatsov marked this pull request as ready for review October 20, 2026 04:26
@bbatsov
bbatsov merged commit d09bf8e into main Oct 20, 2026
18 checks passed
@bbatsov
bbatsov deleted the connections branch October 20, 2026 04:28
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