Skip to content

HTTP server doesn't set TCP_NODELAY, adding ~40 ms to streamed responses #390

Done

Description

@drevantonder

Version: laravel-rust 0.1.3 (still on 0.x at 3f09859)

What happens

LimitedListener::accept in src/foundation/connections.rs hands accepted connections to hyper without setting TCP_NODELAY, and serve_on builds the listener with .tap_io(|_| ()), so it isn't set anywhere else. With Nagle's algorithm on, a small write that follows an unacknowledged one waits for the client's delayed ACK, about 40 ms on Linux.

For a Streamed::channel or SSE response this delays the small chunks, including the first, so time to first byte goes up by ~40 ms. An app can't work around it, because the listener and accepted connections are private. (Reverb's listener already sets it.)

How to reproduce

  1. A handler returning Streamed::channel that sends a few small chunks.
  2. Call it over a keep-alive connection on Linux and time the first byte.

Measured (loopback, 600 sequential calls, p50 time to first byte):

Time to first byte
0.1.3 42.17 ms
with TCP_NODELAY 0.42 ms

Non-streamed responses were unchanged. Fix in #391.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions