fix(ec2): disable Nagle on both socat sockets of a published port forward (#6572)

socat relayed a client's second small write only after the first was
acknowledged, so delayed ACKs stretched every PostgreSQL statement close
to ~44 ms. Add nodelay (TCP_NODELAY) to both addresses: the listener's
option reaches the accepted socket in the fork child, and the connect
side covers the instance-facing one.

Closes #6176

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
Matheus Oliveira authored and GitHub committed 2026-10-25 22:43:15 -04:00
1 parent 1e89ae2908
commit f1816dbb44
3 files changed
+53 -3

No files matched your search

@@ -36,6 +36,11 @@ import java.util.function.Consumer;
* container and its SSH binding). The sidecar publishes an allocated host port and forwards
* it to the instance container's IP, so {@code curl localhost:<hostPort>} reaches the app.
*
* <p>Both socat addresses run with {@code nodelay} (TCP_NODELAY). With Nagle's algorithm left
* on, socat holds a client's second small write until the first is acknowledged, and a peer
* with delayed ACK stretches that to roughly 40 ms on the Docker network, so a request the
* client sends as two writes pays a visible stall on every round trip.
*
* <p>Because each forward is a fresh container, ports opened <em>after</em> launch via
* {@code authorize-security-group-ingress} are handled the same way as ports present at
* launch. The instance container itself is never modified.
@@ -206,8 +211,8 @@ public class Ec2PortForwardManager {
.withName(name)
.withEntrypoint(List.of("socat"))
.withCmd(List.of(
"TCP-LISTEN:" + appPort + ",fork,reuseaddr",
"TCP:" + target.ip() + ":" + appPort))
"TCP-LISTEN:" + appPort + ",fork,reuseaddr,nodelay",
"TCP:" + target.ip() + ":" + appPort + ",nodelay"))
.withPortBinding(appPort, hostPort)
.withLogRotation();
if (target.network() != null) {