-
Notifications
You must be signed in to change notification settings - Fork 840
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
omit setting TCP_NODELAY flag for a socket that inherits the property from an accepting socket#1568
Conversation
Thank you for the PR. Do you have a benchmark that shows the practical benefit of changing the code? The reason I ask is because per my understanding whether if FWIW, FreeBSD's man page does not mention that (whereas it says that some other options are inherited). NetBSD's man page states:
|
@kazuho FreeBSD 4.5 have TCP_NODELAY inherited from accepted socket. seems all bsd and linux(not too old version, NetBSD 1.6 guess is too old) should have the same behaviour. |
It's not only FreeBSD that we support. H2O is known to compile on other platforms as well (e.g. NetBSD, OpenBSD, Solaris, AIX, etc.). We also want to keep H2O portable to new platforms; that is why we generally stick to what is defined in POSIX. Therefore, I would highly appreciate it if you could adjust the PR so that it would work as an optimization on platforms that support inheritance of the property. For example, how about doing the following?
|
h2o_evloop_socket_create will be called with fd from pipe/eventfd/socketpair/unix domain socket.
this make sense, will try to do this. |
Yes. There's no reason to avoid doing that, since none of them would be used in a performance-sensitive way. Requiring the user of the event loop to set the flag would increase the complexity; it is better to keep the contract between the user and the event loop as simple as possible. |
edf70a4
to
a388777
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the changes. I think that we are almost done.
I have left my ideas hoping that we might be able to make the code even simpler. Please let me know what you think.
lib/common/socket/evloop.c.h
Outdated
*/ | ||
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(flag)); | ||
} | ||
|
||
return &create_socket(loop, fd, flags)->super; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just call create_socket_set_nodelay
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we can. fixed
lib/common/socket/evloop.c.h
Outdated
#endif | ||
#endif | ||
|
||
return &create_socket(listener->loop, fd, H2O_SOCKET_FLAG_IS_ACCEPTED_CONNECTION)->super; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about calling create_socket
if H2O_USE_ACCEPT4
is set, and call create_socket_set_nodelay
if otherwise? There is a #if H2O_USE_ACCEPT4 ... #else ... #endif
block right above, to which you can merge the logic.
For platforms that support inheritance of TCP_NODELAY but do not provide accept4
(maybe it's only NetBSD?), we would be taking a lock and call fcntl
in addition to accept
anyways. So I do not think that it's necessary to complicate the code in order to have this optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge logic using H2O_USE_ACCEPT4
for simplicity.
Thank you for all the work. Merged to master. |
Accepted socket can inherit "TCP_NODELAY" option form listening socket.
So we can set this option on listening socket and remove setting on accepted socket.