Using both keepalive requests and timeout

Hi all,

I was curious to see if anyone used both keepalive_requests and
keepalive_timeout at the same time and knew the expected behaviour? I
was
hoping that nginx would do whichever conditions were met first.

Thank you very much in advance.

Posted at Nginx Forum:

On Wednesday 19 November 2014 14:30:59 josephlim wrote:

Hi all,

I was curious to see if anyone used both keepalive_requests and
keepalive_timeout at the same time and knew the expected behaviour? I was
hoping that nginx would do whichever conditions were met first.

Yes, you’re right.

These directives don’t interact with each other, but just impose
different
restrictions on keep-alive connections.

wbr, Valentin V. Bartenev

Hi Valentin,

Thank you for clarifying that, however now that makes me wonder about
this:
if we set our timeout value to 30s and did not set our requests value,
does
this mean that the default requests value of 100 restriction is imposed
or
does nginx only respect the timeout value explicitly declared?

Thank you again in advance

Posted at Nginx Forum:

On Wednesday 19 November 2014 14:52:19 josephlim wrote:

Hi Valentin,

Thank you for clarifying that, however now that makes me wonder about this:
if we set our timeout value to 30s and did not set our requests value, does
this mean that the default requests value of 100 restriction is imposed or
does nginx only respect the timeout value explicitly declared?

Thank you again in advance

This is actually what the default value is about.

You may look to the documentation and see that most of directives have
its own default value that is used when the directive isn’t specified
in the configuration.

http://nginx.org/r/keepalive_requests

wbr, Valentin V. Bartenev

Hi All,
I have a query, I tried setting keep alive_timeout to a non-zero
value and found it not working correctly. Are there any related
parameters for this?

//Jagannath

From: “Valentin V. Bartenev” <[email protected]mailto:[email protected]>
Organization: NGINX, Inc.
Reply-To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Date: Thursday, November 20, 2014 at 1:33 AM
To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Subject: Re: Using both keepalive requests and timeout

On Wednesday 19 November 2014 14:52:19 josephlim wrote:
Hi Valentin,
Thank you for clarifying that, however now that makes me wonder about
this:
if we set our timeout value to 30s and did not set our requests value,
does
this mean that the default requests value of 100 restriction is imposed
or
does nginx only respect the timeout value explicitly declared?
Thank you again in advance

This is actually what the default value is about.

You may look to the documentation and see that most of directives have
its own default value that is used when the directive isn’t specified
in the configuration.

http://nginx.org/r/keepalive_requests

wbr, Valentin V. Bartenev

Hi,
I tried posting data to nginx running on the same host as that of the
client(httperf) with keep alive_timeout set to a non-zero value and keep
alive_requests set to a non-zero value. I observed that, the server was
closing the connection only when the number of requests equalled the
value set by the keepalive_requests in the configuration.

What could be the reason?

From: “Valentin V. Bartenev” <[email protected]mailto:[email protected]>
Organization: Nginx, Inc.
Reply-To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Date: Thursday, November 20, 2014 at 1:56 PM
To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Subject: Re: Using both keepalive requests and timeout

On Thursday 20 November 2014 10:42:03 Das, Jagannath wrote:
Hi All,
I have a query, I tried setting keep alive_timeout to a non-zero
value
and found it not working correctly.
Are there any related parameters for this?

What do you mean by not working correctly? What’s the problem?

wbr, Valentin V. Bartenev

On Thursday 20 November 2014 14:43:46 Das, Jagannath wrote:

Hi,
I tried posting data to nginx running on the same host as that of the
client(httperf) with keep alive_timeout set to a non-zero value and keep
alive_requests set to a non-zero value. I observed that, the server was closing
the connection only when the number of requests equalled the value set by the
keepalive_requests in the configuration.

What could be the reason?

[…]

And how have you tested it? Especially, I’m very curious
how it’s possible to test it with httperf.

wbr, Valentin V. Bartenev

On Thursday 20 November 2014 10:42:03 Das, Jagannath wrote:

Hi All,
I have a query, I tried setting keep alive_timeout to a non-zero value
and found it not working correctly.
Are there any related parameters for this?

What do you mean by not working correctly? What’s the problem?

wbr, Valentin V. Bartenev

On Thursday 20 November 2014 16:37:31 Das, Jagannath wrote:

httperf --server localhost --hog --method POST --wsess=1,102,2 --print-reply
–print-request

And what keepalive_timeout you have specified? One second?

wbr, Valentin V. Bartenev

httperf --server localhost --hog --method POST --wsess=1,102,2
–print-reply --print-request

From: “Valentin V. Bartenev” <[email protected]mailto:[email protected]>
Organization: Nginx, Inc.
Reply-To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Date: Thursday, November 20, 2014 at 2:55 PM
To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Subject: Re: Using both keepalive requests and timeout

On Thursday 20 November 2014 14:43:46 Das, Jagannath wrote:
Hi,
I tried posting data to nginx running on the same host as that of the
client(httperf) with keep alive_timeout set to a non-zero value and keep
alive_requests set to a non-zero value. I observed that, the server was
closing the connection only when the number of requests equalled the
value set by the keepalive_requests in the configuration.
What could be the reason?
[…]

And how have you tested it? Especially, I’m very curious
how it’s possible to test it with httperf.

wbr, Valentin V. Bartenev

On Thursday 20 November 2014 20:40:30 Das, Jagannath wrote:

I tried with 10s, 30s, 40s .

But you have set 2s timeout between requests in httperf,
so how do you expect it to work?

It’s a timeout for inactive keep-alive connection.

If you set keepalive_timeout 10s; then a connection
will be closed after 10 seconds of inactivity, but
httperf with the --wsess=1,102,2 parameters sends
new requests every 2 seconds.

See also: RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing

wbr, Valentin V. Bartenev

I tried with 10s, 30s, 40s .

From: “Valentin V. Bartenev” <[email protected]mailto:[email protected]>
Organization: NGINX, Inc.
Reply-To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Date: Thursday, November 20, 2014 at 5:56 PM
To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Subject: Re: Using both keepalive requests and timeout

On Thursday 20 November 2014 16:37:31 Das, Jagannath wrote:
httperf --server localhost --hog --method POST --wsess=1,102,2
–print-reply --print-request

And what keepalive_timeout you have specified? One second?

wbr, Valentin V. Bartenev

Hi,
The 2s is the delay between which the requests are fired from the
client side on the same connection.

Thanks,
Jagannath

From: “Valentin V. Bartenev” <[email protected]mailto:[email protected]>
Organization: NGINX, Inc.
Reply-To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Date: Thursday, November 20, 2014 at 10:07 PM
To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Subject: Re: Using both keepalive requests and timeout

On Thursday 20 November 2014 20:40:30 Das, Jagannath wrote:
I tried with 10s, 30s, 40s .

But you have set 2s timeout between requests in httperf,
so how do you expect it to work?

It’s a timeout for inactive keep-alive connection.

If you set keepalive_timeout 10s; then a connection
will be closed after 10 seconds of inactivity, but
httperf with the --wsess=1,102,2 parameters sends
new requests every 2 seconds.

See also: RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing

wbr, Valentin V. Bartenev

It was new learning for me that keep alive_timeout is a time set for
inactivity. May be we should add that in the nginx.org wiki page.

This will actually relief a lot of people. :slight_smile:

From: “Valentin V. Bartenev” <[email protected]mailto:[email protected]>
Organization: NGINX, Inc.
Reply-To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Date: Thursday, November 20, 2014 at 10:07 PM
To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Subject: Re: Using both keepalive requests and timeout

On Thursday 20 November 2014 20:40:30 Das, Jagannath wrote:
I tried with 10s, 30s, 40s .

But you have set 2s timeout between requests in httperf,
so how do you expect it to work?

It’s a timeout for inactive keep-alive connection.

If you set keepalive_timeout 10s; then a connection
will be closed after 10 seconds of inactivity, but
httperf with the --wsess=1,102,2 parameters sends
new requests every 2 seconds.

See also: RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing

wbr, Valentin V. Bartenev

Hi Valentine,
Please confirm that keep alive_timeout is a value for inactivity by
mentioning it on the nginx.org .

Thanks,
Jagannath

From: “Valentin V. Bartenev” <[email protected]mailto:[email protected]>
Organization: NGINX, Inc.
Reply-To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Date: Thursday, November 20, 2014 at 10:07 PM
To: “[email protected]mailto:[email protected]
<[email protected]mailto:[email protected]>
Subject: Re: Using both keepalive requests and timeout

On Thursday 20 November 2014 20:40:30 Das, Jagannath wrote:
I tried with 10s, 30s, 40s .

But you have set 2s timeout between requests in httperf,
so how do you expect it to work?

It’s a timeout for inactive keep-alive connection.

If you set keepalive_timeout 10s; then a connection
will be closed after 10 seconds of inactivity, but
httperf with the --wsess=1,102,2 parameters sends
new requests every 2 seconds.

See also: RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing

wbr, Valentin V. Bartenev