Upstream keepalive: keepalive_requests directive.
The directive configures maximum number of requests allowed on
a connection kept in the cache. Once a connection reaches the number
of requests configured, it is no longer saved to the cache.
The default is 100.
Much like keepalive_requests for client connections, this is mostly
a safeguard to make sure connections are closed periodically and the
memory allocated from the connection pool is freed.
Maxim Dounin
3 years ago
11 | 11 | |
12 | 12 | typedef struct { |
13 | 13 | ngx_uint_t max_cached; |
14 | ngx_uint_t requests; | |
14 | 15 | ngx_msec_t timeout; |
15 | 16 | |
16 | 17 | ngx_queue_t cache; |
89 | 90 | ngx_conf_set_msec_slot, |
90 | 91 | NGX_HTTP_SRV_CONF_OFFSET, |
91 | 92 | offsetof(ngx_http_upstream_keepalive_srv_conf_t, timeout), |
93 | NULL }, | |
94 | ||
95 | { ngx_string("keepalive_requests"), | |
96 | NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1, | |
97 | ngx_conf_set_num_slot, | |
98 | NGX_HTTP_SRV_CONF_OFFSET, | |
99 | offsetof(ngx_http_upstream_keepalive_srv_conf_t, requests), | |
92 | 100 | NULL }, |
93 | 101 | |
94 | 102 | ngx_null_command |
141 | 149 | ngx_http_upstream_keepalive_module); |
142 | 150 | |
143 | 151 | ngx_conf_init_msec_value(kcf->timeout, 60000); |
152 | ngx_conf_init_uint_value(kcf->requests, 100); | |
144 | 153 | |
145 | 154 | if (kcf->original_init_upstream(cf, us) != NGX_OK) { |
146 | 155 | return NGX_ERROR; |
311 | 320 | goto invalid; |
312 | 321 | } |
313 | 322 | |
323 | if (c->requests >= kp->conf->requests) { | |
324 | goto invalid; | |
325 | } | |
326 | ||
314 | 327 | if (!u->keepalive) { |
315 | 328 | goto invalid; |
316 | 329 | } |
499 | 512 | */ |
500 | 513 | |
501 | 514 | conf->timeout = NGX_CONF_UNSET_MSEC; |
515 | conf->requests = NGX_CONF_UNSET_UINT; | |
502 | 516 | |
503 | 517 | return conf; |
504 | 518 | } |