Skip to content

look into TCP fastopen and TCP_QUICKACK #14173

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

Open
Tracked by #14178
andrewrk opened this issue Jan 3, 2023 · 3 comments
Open
Tracked by #14178

look into TCP fastopen and TCP_QUICKACK #14173

andrewrk opened this issue Jan 3, 2023 · 3 comments
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. enhancement Solving this issue will likely involve adding new logic or components to the codebase. optimization standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Jan 3, 2023

Extracted from #13980.

Here's an example of using TCP fastopen to send data along with the tcp connection:

    struct msghdr mh = {
        .msg_name = (void *)sa,
        .msg_namelen = sl,
        .msg_iovlen = 2,
        .msg_iov = (struct iovec [2]){
            { .iov_base = (uint8_t[]){ ql>>8, ql }, .iov_len = 2 },
            { .iov_base = (void *)q, .iov_len = ql } }
    };
    int fd = socket(family, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
    if (!setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, &(int){1}, sizeof(int))) {
        r = sendmsg(fd, &mh, MSG_FASTOPEN|MSG_NOSIGNAL);

TCP_QUICKACK is another option that could be enabled in setsockopt. Both options are intended to reduce latency.

This issue is to change the std lib API for making an HTTPS request to take advantage of these things, and see if we can reduce the latency of establishing a connection. For HTTP GET requests it should do the same but with the HTTP header instead of the TLS ClientHello.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. optimization breaking Implementing this issue could cause existing code to no longer compile or have different behavior. standard library This issue involves writing Zig code for the standard library. labels Jan 3, 2023
@andrewrk andrewrk added this to the 0.11.0 milestone Jan 3, 2023
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@patryk4815
Copy link

TCP_FASTOPEN feature is no longer used by any major browsers due to privacy concerns. However, for internal communication within DC environments, these privacy issues may be less relevant. Probably no one is waiting for this feature :)

@rofrol
Copy link
Contributor

rofrol commented Aug 15, 2024

More controversially, I suspect that Nagle’s algorithm just isn’t needed on modern systems, given the traffic and application mix, and the capabilities of the hardware we have today. In other words, TCP_NODELAY should be the default. That’s going to make some “write every byte” code slower than it would otherwise be, but those applications should be fixed anyway if we care about efficiency.

As this has gone around the internet, a number of folks have asked about TCP_QUICKACK. I don’t tend to reach for it for a few reasons, including lack of portability, and weird semantics (seriously, read the man page). The bigger problem is that TCP_QUICKACK doesn’t fix the fundamental problem of the kernel hanging on to data longer than my program wants it to. When I say write(), I mean write().

@michaelortmann
Copy link
Contributor

In other words, TCP_NODELAY should be the default.
Indeed, please turn off Nagle's algorithm, add TCP_NODELAY to setsockopt(fd, IPPROTO_TCP) by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. enhancement Solving this issue will likely involve adding new logic or components to the codebase. optimization standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

4 participants