Mercurial > hg > ngx_http_upstream_keepalive
comparison ngx_http_upstream_keepalive_module.c @ 45:489c5d4318ff draft
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, 25 Jun 2012 22:55:53 +0400 |
parents | c53e018dbcf5 |
children |
comparison
equal
deleted
inserted
replaced
44:d9ac9ad67f45 | 45:489c5d4318ff |
---|---|
9 #include <ngx_http.h> | 9 #include <ngx_http.h> |
10 | 10 |
11 | 11 |
12 typedef struct { | 12 typedef struct { |
13 ngx_uint_t max_cached; | 13 ngx_uint_t max_cached; |
14 ngx_uint_t single; /* unsigned:1 */ | |
15 | 14 |
16 ngx_queue_t cache; | 15 ngx_queue_t cache; |
17 ngx_queue_t free; | 16 ngx_queue_t free; |
18 | 17 |
19 ngx_http_upstream_init_pt original_init_upstream; | 18 ngx_http_upstream_init_pt original_init_upstream; |
220 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, | 219 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
221 "get keepalive peer"); | 220 "get keepalive peer"); |
222 | 221 |
223 kp->failed = 0; | 222 kp->failed = 0; |
224 | 223 |
225 /* single pool of cached connections */ | 224 /* ask balancer */ |
226 | |
227 if (kp->conf->single && !ngx_queue_empty(&kp->conf->cache)) { | |
228 | |
229 q = ngx_queue_head(&kp->conf->cache); | |
230 | |
231 item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue); | |
232 c = item->connection; | |
233 | |
234 ngx_queue_remove(q); | |
235 ngx_queue_insert_head(&kp->conf->free, q); | |
236 | |
237 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, | |
238 "get keepalive peer: using connection %p", c); | |
239 | |
240 c->idle = 0; | |
241 c->log = pc->log; | |
242 c->read->log = pc->log; | |
243 c->write->log = pc->log; | |
244 #if (NGX_UPSTREAM_KEEPALIVE_PATCHED) | |
245 c->pool->log = pc->log; | |
246 #endif | |
247 | |
248 pc->connection = c; | |
249 pc->cached = 1; | |
250 | |
251 return NGX_DONE; | |
252 } | |
253 | 225 |
254 rc = kp->original_get_peer(pc, kp->data); | 226 rc = kp->original_get_peer(pc, kp->data); |
255 | 227 |
256 if (kp->conf->single || rc != NGX_OK) { | 228 if (rc != NGX_OK) { |
257 return rc; | 229 return rc; |
258 } | 230 } |
259 | 231 |
260 /* search cache for suitable connection */ | 232 /* search cache for suitable connection */ |
261 | 233 |
597 kcf->max_cached = n; | 569 kcf->max_cached = n; |
598 | 570 |
599 for (i = 2; i < cf->args->nelts; i++) { | 571 for (i = 2; i < cf->args->nelts; i++) { |
600 | 572 |
601 if (ngx_strcmp(value[i].data, "single") == 0) { | 573 if (ngx_strcmp(value[i].data, "single") == 0) { |
602 kcf->single = 1; | 574 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
575 "the \"single\" parameter is deprecated"); | |
603 continue; | 576 continue; |
604 } | 577 } |
605 | 578 |
606 goto invalid; | 579 goto invalid; |
607 } | 580 } |