nginx (1.1.19) socket-level configuration of tcp_nodelay
I'm curious about
https://github.com/nginx/nginx/blob/master/src/core/ngx_connection.c
Specifically, line 838 in ngx_configure_listening_sockets()
:
#if 0
if (1) {
int tcp_nodelay = 1;
if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_NODELAY,
(const void *) &tcp_nodelay, sizeof(int))
== -1) //old-the current code calls an internal function to do this
{
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
"setsockopt(TCP_NODELAY) %V failed, ignored",
&ls[i].addr_text);
}
}
#endif
Using getsockopt
, I was indeed able to determine that none of my accept
sockets had TCP_NODELAY
set. Removing the preprocessor block fixed this. But why is it there? If the intention is to configure the accepted socket later and explicitly, I can't figure out where this is happening.
This app builds full responses before calling send, so traditional wisdom would be to disable nagle(enable TCP_NODELAY
), but *I figure there is either a correct way to enable TCP_NODELAY
or nginx has a very good reason for not enabling it.*
Am I correct, and if so, which is it?
(for the record, this question mostly involves
c sockets nginx tcp
add a comment |
I'm curious about
https://github.com/nginx/nginx/blob/master/src/core/ngx_connection.c
Specifically, line 838 in ngx_configure_listening_sockets()
:
#if 0
if (1) {
int tcp_nodelay = 1;
if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_NODELAY,
(const void *) &tcp_nodelay, sizeof(int))
== -1) //old-the current code calls an internal function to do this
{
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
"setsockopt(TCP_NODELAY) %V failed, ignored",
&ls[i].addr_text);
}
}
#endif
Using getsockopt
, I was indeed able to determine that none of my accept
sockets had TCP_NODELAY
set. Removing the preprocessor block fixed this. But why is it there? If the intention is to configure the accepted socket later and explicitly, I can't figure out where this is happening.
This app builds full responses before calling send, so traditional wisdom would be to disable nagle(enable TCP_NODELAY
), but *I figure there is either a correct way to enable TCP_NODELAY
or nginx has a very good reason for not enabling it.*
Am I correct, and if so, which is it?
(for the record, this question mostly involves
c sockets nginx tcp
1
The code you show sets TCP_NODELAY on the listening socket - which may be inherited by the accept()'ed sockets - but that isn't portable. The same file has angx_tcp_nodelay()
function to set TCP_NODELAY on the (non-listening) TCP sockets which are called from various places, depending on settings you have in nginx.conf
– nos
Nov 16 '18 at 20:37
@nos - I truly couldn't figure out from where. There was asendfile
type of socket where it was obvious, butnginx
has a 2-bit field in its internal structure for tcp_nodelay, and I really couldn't figure out anything consistent in how it was 1) set or 2) used. Not saying it's it not consistent. Just that if it is, I couldn't figure it out.
– zzxyz
Nov 16 '18 at 20:43
run e.ggrep -r ngx_tcp_nodelay( .
to see where it's called from.
– nos
Nov 16 '18 at 20:44
@nos - Ah yes...It's clear what to do in the new nginx. My version doesn't have that function, the file that calls it, or the setting that file reads. You've answered the important part of my question for me, which is that they probably#ifdefed
that out for portability reasons (vs a deliberate attempt to enable nagle regardless of config). Thank you.
– zzxyz
Nov 16 '18 at 20:55
the relevant file (for the socket type in question) that calls it, I should say
– zzxyz
Nov 16 '18 at 21:05
add a comment |
I'm curious about
https://github.com/nginx/nginx/blob/master/src/core/ngx_connection.c
Specifically, line 838 in ngx_configure_listening_sockets()
:
#if 0
if (1) {
int tcp_nodelay = 1;
if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_NODELAY,
(const void *) &tcp_nodelay, sizeof(int))
== -1) //old-the current code calls an internal function to do this
{
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
"setsockopt(TCP_NODELAY) %V failed, ignored",
&ls[i].addr_text);
}
}
#endif
Using getsockopt
, I was indeed able to determine that none of my accept
sockets had TCP_NODELAY
set. Removing the preprocessor block fixed this. But why is it there? If the intention is to configure the accepted socket later and explicitly, I can't figure out where this is happening.
This app builds full responses before calling send, so traditional wisdom would be to disable nagle(enable TCP_NODELAY
), but *I figure there is either a correct way to enable TCP_NODELAY
or nginx has a very good reason for not enabling it.*
Am I correct, and if so, which is it?
(for the record, this question mostly involves
c sockets nginx tcp
I'm curious about
https://github.com/nginx/nginx/blob/master/src/core/ngx_connection.c
Specifically, line 838 in ngx_configure_listening_sockets()
:
#if 0
if (1) {
int tcp_nodelay = 1;
if (setsockopt(ls[i].fd, IPPROTO_TCP, TCP_NODELAY,
(const void *) &tcp_nodelay, sizeof(int))
== -1) //old-the current code calls an internal function to do this
{
ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
"setsockopt(TCP_NODELAY) %V failed, ignored",
&ls[i].addr_text);
}
}
#endif
Using getsockopt
, I was indeed able to determine that none of my accept
sockets had TCP_NODELAY
set. Removing the preprocessor block fixed this. But why is it there? If the intention is to configure the accepted socket later and explicitly, I can't figure out where this is happening.
This app builds full responses before calling send, so traditional wisdom would be to disable nagle(enable TCP_NODELAY
), but *I figure there is either a correct way to enable TCP_NODELAY
or nginx has a very good reason for not enabling it.*
Am I correct, and if so, which is it?
(for the record, this question mostly involves
c sockets nginx tcp
c sockets nginx tcp
edited Nov 17 '18 at 0:52
asked Nov 16 '18 at 20:30
zzxyz
2,1831624
2,1831624
1
The code you show sets TCP_NODELAY on the listening socket - which may be inherited by the accept()'ed sockets - but that isn't portable. The same file has angx_tcp_nodelay()
function to set TCP_NODELAY on the (non-listening) TCP sockets which are called from various places, depending on settings you have in nginx.conf
– nos
Nov 16 '18 at 20:37
@nos - I truly couldn't figure out from where. There was asendfile
type of socket where it was obvious, butnginx
has a 2-bit field in its internal structure for tcp_nodelay, and I really couldn't figure out anything consistent in how it was 1) set or 2) used. Not saying it's it not consistent. Just that if it is, I couldn't figure it out.
– zzxyz
Nov 16 '18 at 20:43
run e.ggrep -r ngx_tcp_nodelay( .
to see where it's called from.
– nos
Nov 16 '18 at 20:44
@nos - Ah yes...It's clear what to do in the new nginx. My version doesn't have that function, the file that calls it, or the setting that file reads. You've answered the important part of my question for me, which is that they probably#ifdefed
that out for portability reasons (vs a deliberate attempt to enable nagle regardless of config). Thank you.
– zzxyz
Nov 16 '18 at 20:55
the relevant file (for the socket type in question) that calls it, I should say
– zzxyz
Nov 16 '18 at 21:05
add a comment |
1
The code you show sets TCP_NODELAY on the listening socket - which may be inherited by the accept()'ed sockets - but that isn't portable. The same file has angx_tcp_nodelay()
function to set TCP_NODELAY on the (non-listening) TCP sockets which are called from various places, depending on settings you have in nginx.conf
– nos
Nov 16 '18 at 20:37
@nos - I truly couldn't figure out from where. There was asendfile
type of socket where it was obvious, butnginx
has a 2-bit field in its internal structure for tcp_nodelay, and I really couldn't figure out anything consistent in how it was 1) set or 2) used. Not saying it's it not consistent. Just that if it is, I couldn't figure it out.
– zzxyz
Nov 16 '18 at 20:43
run e.ggrep -r ngx_tcp_nodelay( .
to see where it's called from.
– nos
Nov 16 '18 at 20:44
@nos - Ah yes...It's clear what to do in the new nginx. My version doesn't have that function, the file that calls it, or the setting that file reads. You've answered the important part of my question for me, which is that they probably#ifdefed
that out for portability reasons (vs a deliberate attempt to enable nagle regardless of config). Thank you.
– zzxyz
Nov 16 '18 at 20:55
the relevant file (for the socket type in question) that calls it, I should say
– zzxyz
Nov 16 '18 at 21:05
1
1
The code you show sets TCP_NODELAY on the listening socket - which may be inherited by the accept()'ed sockets - but that isn't portable. The same file has a
ngx_tcp_nodelay()
function to set TCP_NODELAY on the (non-listening) TCP sockets which are called from various places, depending on settings you have in nginx.conf– nos
Nov 16 '18 at 20:37
The code you show sets TCP_NODELAY on the listening socket - which may be inherited by the accept()'ed sockets - but that isn't portable. The same file has a
ngx_tcp_nodelay()
function to set TCP_NODELAY on the (non-listening) TCP sockets which are called from various places, depending on settings you have in nginx.conf– nos
Nov 16 '18 at 20:37
@nos - I truly couldn't figure out from where. There was a
sendfile
type of socket where it was obvious, but nginx
has a 2-bit field in its internal structure for tcp_nodelay, and I really couldn't figure out anything consistent in how it was 1) set or 2) used. Not saying it's it not consistent. Just that if it is, I couldn't figure it out.– zzxyz
Nov 16 '18 at 20:43
@nos - I truly couldn't figure out from where. There was a
sendfile
type of socket where it was obvious, but nginx
has a 2-bit field in its internal structure for tcp_nodelay, and I really couldn't figure out anything consistent in how it was 1) set or 2) used. Not saying it's it not consistent. Just that if it is, I couldn't figure it out.– zzxyz
Nov 16 '18 at 20:43
run e.g
grep -r ngx_tcp_nodelay( .
to see where it's called from.– nos
Nov 16 '18 at 20:44
run e.g
grep -r ngx_tcp_nodelay( .
to see where it's called from.– nos
Nov 16 '18 at 20:44
@nos - Ah yes...It's clear what to do in the new nginx. My version doesn't have that function, the file that calls it, or the setting that file reads. You've answered the important part of my question for me, which is that they probably
#ifdefed
that out for portability reasons (vs a deliberate attempt to enable nagle regardless of config). Thank you.– zzxyz
Nov 16 '18 at 20:55
@nos - Ah yes...It's clear what to do in the new nginx. My version doesn't have that function, the file that calls it, or the setting that file reads. You've answered the important part of my question for me, which is that they probably
#ifdefed
that out for portability reasons (vs a deliberate attempt to enable nagle regardless of config). Thank you.– zzxyz
Nov 16 '18 at 20:55
the relevant file (for the socket type in question) that calls it, I should say
– zzxyz
Nov 16 '18 at 21:05
the relevant file (for the socket type in question) that calls it, I should say
– zzxyz
Nov 16 '18 at 21:05
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53344953%2fnginx-1-1-19-socket-level-configuration-of-tcp-nodelay%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53344953%2fnginx-1-1-19-socket-level-configuration-of-tcp-nodelay%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
The code you show sets TCP_NODELAY on the listening socket - which may be inherited by the accept()'ed sockets - but that isn't portable. The same file has a
ngx_tcp_nodelay()
function to set TCP_NODELAY on the (non-listening) TCP sockets which are called from various places, depending on settings you have in nginx.conf– nos
Nov 16 '18 at 20:37
@nos - I truly couldn't figure out from where. There was a
sendfile
type of socket where it was obvious, butnginx
has a 2-bit field in its internal structure for tcp_nodelay, and I really couldn't figure out anything consistent in how it was 1) set or 2) used. Not saying it's it not consistent. Just that if it is, I couldn't figure it out.– zzxyz
Nov 16 '18 at 20:43
run e.g
grep -r ngx_tcp_nodelay( .
to see where it's called from.– nos
Nov 16 '18 at 20:44
@nos - Ah yes...It's clear what to do in the new nginx. My version doesn't have that function, the file that calls it, or the setting that file reads. You've answered the important part of my question for me, which is that they probably
#ifdefed
that out for portability reasons (vs a deliberate attempt to enable nagle regardless of config). Thank you.– zzxyz
Nov 16 '18 at 20:55
the relevant file (for the socket type in question) that calls it, I should say
– zzxyz
Nov 16 '18 at 21:05