Mercurial > hg > nginx
comparison src/http/modules/ngx_http_upstream_keepalive_module.c @ 4694:5b5c07dee156
Upstream keepalive: "single" parameter deprecated.
The original idea was to optimize edge cases in case of interchangeable
backends, i.e. don't establish a new connection if we have any one
cached. This causes more harm than good though, as it screws up
underlying balancer's idea about backends used and may result in
various unexpected problems.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 18 Jun 2012 14:23:42 +0000 |
parents | d620f497c50f |
children | 82336a9ce26d |
comparison
equal
deleted
inserted
replaced
4693:f1a0de6eb505 | 4694:5b5c07dee156 |
---|---|
10 #include <ngx_http.h> | 10 #include <ngx_http.h> |
11 | 11 |
12 | 12 |
13 typedef struct { | 13 typedef struct { |
14 ngx_uint_t max_cached; | 14 ngx_uint_t max_cached; |
15 ngx_uint_t single; /* unsigned:1 */ | |
16 | 15 |
17 ngx_queue_t cache; | 16 ngx_queue_t cache; |
18 ngx_queue_t free; | 17 ngx_queue_t free; |
19 | 18 |
20 ngx_http_upstream_init_pt original_init_upstream; | 19 ngx_http_upstream_init_pt original_init_upstream; |
221 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, | 220 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
222 "get keepalive peer"); | 221 "get keepalive peer"); |
223 | 222 |
224 kp->failed = 0; | 223 kp->failed = 0; |
225 | 224 |
226 /* single pool of cached connections */ | 225 /* ask balancer */ |
227 | |
228 if (kp->conf->single && !ngx_queue_empty(&kp->conf->cache)) { | |
229 | |
230 q = ngx_queue_head(&kp->conf->cache); | |
231 | |
232 item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue); | |
233 c = item->connection; | |
234 | |
235 ngx_queue_remove(q); | |
236 ngx_queue_insert_head(&kp->conf->free, q); | |
237 | |
238 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, | |
239 "get keepalive peer: using connection %p", c); | |
240 | |
241 c->idle = 0; | |
242 c->log = pc->log; | |
243 c->read->log = pc->log; | |
244 c->write->log = pc->log; | |
245 c->pool->log = pc->log; | |
246 | |
247 pc->connection = c; | |
248 pc->cached = 1; | |
249 | |
250 return NGX_DONE; | |
251 } | |
252 | 226 |
253 rc = kp->original_get_peer(pc, kp->data); | 227 rc = kp->original_get_peer(pc, kp->data); |
254 | 228 |
255 if (kp->conf->single || rc != NGX_OK) { | 229 if (rc != NGX_OK) { |
256 return rc; | 230 return rc; |
257 } | 231 } |
258 | 232 |
259 /* search cache for suitable connection */ | 233 /* search cache for suitable connection */ |
260 | 234 |
550 kcf->max_cached = n; | 524 kcf->max_cached = n; |
551 | 525 |
552 for (i = 2; i < cf->args->nelts; i++) { | 526 for (i = 2; i < cf->args->nelts; i++) { |
553 | 527 |
554 if (ngx_strcmp(value[i].data, "single") == 0) { | 528 if (ngx_strcmp(value[i].data, "single") == 0) { |
555 kcf->single = 1; | 529 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
530 "the \"single\" parameter is deprecated"); | |
556 continue; | 531 continue; |
557 } | 532 } |
558 | 533 |
559 goto invalid; | 534 goto invalid; |
560 } | 535 } |