Repository navigation
Lwt_io: options for network functions, client and server - #1061
Conversation
this way it's possible to use the high level API and still control some specific parameters for the socket, such as timeout or buffer size. TCP_NODELAY should be the default.
we should have TCP_NODELAY true by default on client sockets, and we can now set options on both the listening socket and each client socket.
this is more backward compatible
|
I'm not sure why the tests fail on freeBSD. |
This reverts commit c0bcd09.
|
After some thoughts, I think |
raphael-proust
left a comment
There was a problem hiding this comment.
I'll look at the freebsd CI failures in more details, but these are generally due to stricter process isolation on bsd than on linux.
Co-authored-by: Raphaël Proust <[email protected]>
|
Nice, thanks for the contribution! |
|
Sorry for arriving late (and after the merge), but it is generally advisable to take a conservative approach when creating a socket and, perhaps, document such an option, which is an optimisation in itself. The apparent optimisation provided by What is certain is that this type of optimisation is quite relative to the network you are on. It is also specific to what we want to do: some would recommend UDP rather than TCP+TCP_NODELAY, for example. This does not systematically invalidate the use of I am not against On another note, there is much more documentation on the Nagle algorithm as a bottleneck when writing than on congestion problems because |
|
I disagree. Nagle is the wrong default in 99% of use cases, and this still allows the user to disable it. Performance issues caused by its disabling are also easy to find (too many small packets) and fixed by buffering, which Lwt_io already does!
A user who knows they do want Nagle (who? When?) will know to disable the new option. Other users will have fewer mysterious performance issues.
|
I'm sorry, but it would be better to argue this assertion rather than say that I'm wrong... And the problem is not whether The second point may be particularly difficult to understand compared to the first, hence the more conservative approach. EDIT: And, at the very least, you should understand that the documentation as provided in this PR may not be sufficient to enable users to understand the behaviour of the TCP/IP stack when using |
|
I understand that enabling or not TCP_NODELAY is controversial, as it is as well controversially discussed on the Internet. In the end, some programming languages (such as Go) enable TCP_NODELAY by default, others don't. I haven't seen an OS that enables TCP_NODELAY by default. For what it is worth, I'd at least expect the default in Lwt_io being documented. At the moment, the docstring is: @param set_tcp_nodelay if true, [TCP_NODELAY] is set on the socket FD. This
avoids a surprising 40ms delay in some situations.
See for example https://brooker.co.za/blog/2024/05/09/nagle.html for why.It may be worth to refer to (a) the default, (b) maybe Nagle's algorithm (and the nice wikipedia article https://en.wikipedia.org/wiki/Nagle%27s_algorithm -- instead of a random rant on the Internet. Also, this should then be highlighted in the Changes of a potential new lwt release. |
|
I'm assuming your HTTP server sets it. Mine does. Go does by default. Rust's [axum does](tokio-rs/axum#2521).
Generally this doesn't affect a user of lwt_unix, the low level interface. And for a non expert user of lwt_io I am indeed very confident TCP_NODELAY is the correct default. I had to set it once afain recently when writing a basic TCP server for tests! Congestion, if it happens, happens later and I haven't seen it be as bad as the 40ms tax of forgetting TCP_NODELAY.
|
Started in #1065 , good point! |
The idea is that we should be able to use the high level API and still have
basic functionality such as TCP_NODELAY being set automatically. For more
advanced cases, optional callbacks can be used to customize the socket FDs.