Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: turn off Nagle's algorithm #41

Merged
merged 1 commit into from
Aug 10, 2023
Merged

feat: turn off Nagle's algorithm #41

merged 1 commit into from
Aug 10, 2023

Conversation

mihirn
Copy link
Contributor

@mihirn mihirn commented Aug 10, 2023

Nagle's algorithm prevents transmission of small packets as long as
there are outstanding unacknowledged packets, instead buffering data
locally. When combined with delayed acknowledgements, this can lead
to poor latency with both ends of the connection waiting for each other.

Turn off Nagle's algorithm by default to improve latency.

src/net/mod.rs Outdated
Ok(_) => Ok(Stream {
inner: StreamImpl::Tcp(s),
}),
Err(x) => Err(x),
Copy link
Contributor Author

@mihirn mihirn Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do decide that erroring out is the best option, can change this to a s.set_nodelay(true)?, but this is easier until we figure out semantics.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best-effort is probably fine, with debug logging before returning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, that's probably the best option.

Nagle's algorithm prevents transmission of small packets as long as
there are outstanding unacknowledged packets, instead buffering data
locally. When combined with delayed acknowledgements, this can lead
to poor latency with both ends of the connection waiting for each other.

Turn off Nagle's algorithm by default to improve latency.
@mihirn mihirn merged commit b674be9 into main Aug 10, 2023
23 checks passed
@mihirn mihirn deleted the msn/delay-ack branch August 10, 2023 07:06
Comment on lines +74 to +77
let res = s.set_nodelay(true);
if res.is_err() {
eprintln!("Error setting TCP_NODELAY: {:?}", res.err());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this is already merged but in the future it would be cleaner to do

if let Err(e) = s.set_nodelay(true) {
    eprintln!("Error setting TCP_NODELAY: {e:?}");
}

@swlynch99 swlynch99 mentioned this pull request Aug 10, 2023
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.

3 participants