axum icon indicating copy to clipboard operation
axum copied to clipboard

Set tcp nodelay on sockets

Open liss-h opened this issue 1 year ago • 3 comments

  • [x] I have looked for existing issues (including closed) about this

Feature Request

Motivation

Currently axum does not set tcp-nodelay on accepted connections. As demonstrated in this issue: https://github.com/hyperium/hyper/issues/3269 this default behaviour can heavily degrade performance in some use cases.

Proposal

Add some way to set TCP_NODELAY on the accepted connections (via TcpStream::set_nodelay).

Variants

  1. Make it the default behaviour for axum::serve by just setting it on each accepted connection
  2. Add a function to axum::serve::Serve<> (like graceful_shutdown) of which the usage could look something like this:
axum::serve(...).set_nodelay(true).await

Some Notes/Questions

As far as I understood you want to keep this part of axum relatively simple and prefer to refer to hyper-util for more complex tasks. However, this would be a relatively small change (I can create a PR if you want) so it doesn't add much code complexity and can give huge performance boosts.

So I guess questions:

  1. Do you want this at all?
  2. If you do: What would you like for an interface?

liss-h avatar Jan 16 '24 09:01 liss-h