Add TCP Fast Open support#1136
Conversation
875270b to
ba1bd82
Compare
|
Is this still open? Should be reviewed and closed or merged |
saghul
left a comment
There was a problem hiding this comment.
Thanks for doing this, I'm sorry it fell through the cracks. Made a first review pass. We need a test too.
5bbdc44 to
2631e4c
Compare
|
LGTM @saghul Any thoughts? |
ewindisch
left a comment
There was a problem hiding this comment.
Looking pretty good! I'm really excited for this, this will significantly benefit code I maintain (@iopipe/iopipe).
There's conflicts still and love to get an answer on the TODOs. Thanks!
|
Hi, @oerdnj. Great work and it seems stalled now. Would you mind me picking this up and push forward basing on your work? |
|
@oyyd Sure, I would be delighted if somebody would finish the work into mergeable state. Thanks! |
|
@patrickkh7788 No. I found it was a lot more complicated than imagined :-( |
|
I might need it for another different DNS server I am working on, so I’ll take a look (or somebody from my team will).
…--
Ondřej Surý <ondrej@sury.org>
On 3 Mar 2019, at 13:00, Ouyang Yadong ***@***.***> wrote:
@patrickkh7788 No. I found it was a lot more complicated than imagined :-(
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
|
JFTR The |
|
@oerdnj macOS use |
| do { | ||
| n = sendto(uv__stream_fd(stream), iov[0].iov_base, iov[0].iov_len, | ||
| MSG_FASTOPEN, (const struct sockaddr*)addr, addrlen); | ||
| } while (n == -1 && (RETRY_ON_WRITE_ERROR(errno) || errno == EINPROGRESS)); |
There was a problem hiding this comment.
The EINPROGRESS has to be handled differently than re-trying sendto() again (which only results in EALREADY).
I think when EINPROGRESS is returned, it should be handled similarly to when it happens in uv__tcp_connect(). The code as is doesn't seem to be able to handle subsequent writes to the stream until the connection is established.
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
Any updates on this PR? |
|
My recollection (it's been a while) is that this PR is unlikely to get merged anytime soon because:
|
|
Libraries not supporting a feature because it's not commonly used? Isn't that a circular argument? |
|
I’ve seen the discussion about TFO for njs, so I guess I can rebase this on top of current v1.x and try to get this merged again. |
Great! Thanks @oerdnj . That would be really helpful! |
No, because that's not the argument. Libuv is a platform abstraction layer. If Linux is the only platform that implements TFO, then it makes no sense to support that in libuv because there's nothing to abstract. The fact that it doesn't even always work on Linux is just icing on the cake. |
|
I see that Windows support is also available through the ConnectEx API. https://learn.microsoft.com/en-us/windows/win32/api/Mswsock/nc-mswsock-lpfn_connectex |
|
TIL! This doesn't sound very promising, however: So seentially we could only support that if you call |
There are already places with delayed syscalls, aren’t they? We can delay the connect system call until the first write happens. |
That could work! |
Can you elaborate on how that would work? I can parse that sentence in multiple ways, none which seem feasible or desirable. |
|
I'd assume it means to do something like: |
Well, in fact, the PR already does that on Linux. It just have been so long, that I've forgotten what I did here :). |
|
Yeah, that was one of the possible interpretations. :-) Okay, I see a couple of problems with that:
IMO, it'd be best to go in the write-before-connect direction. Clunky but no other undesirable attributes. |
The only special case needed would be that you need to start writing ( Note:
Why? The
Can you elaborate a bit more? I don't understand what you mean here.
|
|
Pretty much all downstream code currently is structured like this: uv_connect(connect_req, handle, [](...) {
uv_write(...);
// or:
uv_read_start(...);
});That won't work if the connect req doesn't do anything until the first uv_read_start() or uv_write(). Apropos:
Example: Node's http connection pool opens a bunch of connections to the host but doesn't do anything with them until there's a request ready to be sent. At the moment With your proposal, the connect() call isn't done until the request is sent. That adds latency. |
This is a preliminary effort to add TCP Fast Open support to libuv. It compiles, but it might be completely broken at the moment.
I am submitting this as PR to get a feedback if this is heading into right direction, or it should be rewritten in a completely different way.