# HG changeset patch # User Igor Sysoev # Date 1243265916 0 # Node ID 512d164a83488c2a50c631695c56f972217000da # Parent 78277989e9eacc2c931c3a64039c7d9592edc4fc keepalive_requests diff -r 78277989e9ea -r 512d164a8348 src/core/ngx_connection.h --- a/src/core/ngx_connection.h Mon May 25 15:24:20 2009 +0000 +++ b/src/core/ngx_connection.h Mon May 25 15:38:36 2009 +0000 @@ -135,6 +135,8 @@ ngx_atomic_uint_t number; + ngx_uint_t requests; + unsigned buffered:8; unsigned log_error:3; /* ngx_connection_log_error_e */ diff -r 78277989e9ea -r 512d164a8348 src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c Mon May 25 15:24:20 2009 +0000 +++ b/src/http/ngx_http_core_module.c Mon May 25 15:38:36 2009 +0000 @@ -440,6 +440,13 @@ 0, NULL }, + { ngx_string("keepalive_requests"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, + ngx_conf_set_num_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_core_loc_conf_t, keepalive_requests), + NULL }, + { ngx_string("satisfy"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, ngx_conf_set_enum_slot, @@ -1326,8 +1333,13 @@ r->request_body_in_single_buf = clcf->client_body_in_single_buffer; - if (r->keepalive && clcf->keepalive_timeout == 0) { - r->keepalive = 0; + if (r->keepalive) { + if (clcf->keepalive_timeout == 0) { + r->keepalive = 0; + + } else if (r->connection->requests >= clcf->keepalive_requests) { + r->keepalive = 0; + } } if (!clcf->tcp_nopush) { @@ -2914,6 +2926,7 @@ lcf->limit_rate = NGX_CONF_UNSET_SIZE; lcf->keepalive_timeout = NGX_CONF_UNSET_MSEC; lcf->keepalive_header = NGX_CONF_UNSET; + lcf->keepalive_requests = NGX_CONF_UNSET_UINT; lcf->lingering_time = NGX_CONF_UNSET_MSEC; lcf->lingering_timeout = NGX_CONF_UNSET_MSEC; lcf->resolver_timeout = NGX_CONF_UNSET_MSEC; @@ -3114,6 +3127,8 @@ prev->keepalive_timeout, 75000); ngx_conf_merge_sec_value(conf->keepalive_header, prev->keepalive_header, 0); + ngx_conf_merge_uint_value(conf->keepalive_requests, + prev->keepalive_requests, 100); ngx_conf_merge_msec_value(conf->lingering_time, prev->lingering_time, 30000); ngx_conf_merge_msec_value(conf->lingering_timeout, diff -r 78277989e9ea -r 512d164a8348 src/http/ngx_http_core_module.h --- a/src/http/ngx_http_core_module.h Mon May 25 15:24:20 2009 +0000 +++ b/src/http/ngx_http_core_module.h Mon May 25 15:38:36 2009 +0000 @@ -337,6 +337,7 @@ time_t keepalive_header; /* keepalive_timeout */ + ngx_uint_t keepalive_requests; /* keepalive_requests */ ngx_uint_t satisfy; /* satisfy */ ngx_uint_t if_modified_since; /* if_modified_since */ ngx_uint_t client_body_in_file_only; /* client_body_in_file_only */ diff -r 78277989e9ea -r 512d164a8348 src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c Mon May 25 15:24:20 2009 +0000 +++ b/src/http/ngx_http_request.c Mon May 25 15:38:36 2009 +0000 @@ -259,6 +259,8 @@ return; } + c->requests++; + hc = c->data; if (hc == NULL) {