]> git.kaiwu.me - nginx.git/commitdiff
merge r2889:
authorIgor Sysoev <igor@sysoev.ru>
Mon, 22 Jun 2009 09:50:51 +0000 (09:50 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 22 Jun 2009 09:50:51 +0000 (09:50 +0000)
keepalive_requests

src/core/ngx_connection.h
src/http/ngx_http_core_module.c
src/http/ngx_http_core_module.h
src/http/ngx_http_request.c

index ac867969783f3e307e9852cbb746392fb87c5596..4c41555e156dcb1f76be707f1218278e8982d500 100644 (file)
@@ -134,6 +134,8 @@ struct ngx_connection_s {
 
     ngx_atomic_uint_t   number;
 
+    ngx_uint_t          requests;
+
     unsigned            buffered:8;
 
     unsigned            log_error:3;     /* ngx_connection_log_error_e */
index c312a05f76ff2a3026b7a9bafcc24f18c4fc1973..d9983588a8d2073a21cbb3956f2a114ebdbcb4f8 100644 (file)
@@ -426,6 +426,13 @@ static ngx_command_t  ngx_http_core_commands[] = {
       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,
@@ -1294,8 +1301,13 @@ ngx_http_update_location_config(ngx_http_request_t *r)
         r->request_body_file_log_level = NGX_LOG_WARN;
     }
 
-    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) {
@@ -2909,6 +2921,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t *cf)
     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;
@@ -3103,6 +3116,8 @@ ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
                               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,
index 76d42150a58fa13bc4de4194197b3e2254bb5ac3..23b51442fc03618d9df90090396c4e11dd03b066 100644 (file)
@@ -307,6 +307,7 @@ struct ngx_http_core_loc_conf_s {
 
     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 */
 
index f7c2ffa46b2e75208393de3cfe49903fda8a9832..f762a033fb4af4e6ea814641366b34b66e7725e7 100644 (file)
@@ -253,6 +253,8 @@ ngx_http_init_request(ngx_event_t *rev)
         return;
     }
 
+    c->requests++;
+
     hc = c->data;
 
     if (hc == NULL) {