Mercurial > hg > ngx_http_upstream_keepalive
changeset 3:42e64900483b
Keepalive: always save connections to cache.
Free last recently used one if there is not enough room.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 23 Oct 2008 19:11:15 +0400 |
parents | 8545bbda9e4b |
children | e18e4613b841 |
files | ngx_http_upstream_keepalive_module.c |
diffstat | 1 files changed, 18 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ngx_http_upstream_keepalive_module.c +++ b/ngx_http_upstream_keepalive_module.c @@ -224,17 +224,29 @@ ngx_http_upstream_free_keepalive_peer(ng "free keepalive peer"); if (!(state & NGX_PEER_FAILED) - && pc->connection != NULL - && !ngx_queue_empty(&kp->conf->free)) + && pc->connection != NULL) { c = pc->connection; - q = ngx_queue_head(&kp->conf->free); - ngx_queue_remove(q); + if (ngx_queue_empty(&kp->conf->free)) { + + q = ngx_queue_last(&kp->conf->cache); + ngx_queue_remove(q); + + item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, + queue); + + ngx_close_connection(item->connection); - item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue); + } else { + q = ngx_queue_head(&kp->conf->free); + ngx_queue_remove(q); + + item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, + queue); + } + item->connection = c; - ngx_queue_insert_head(&kp->conf->cache, q); pc->connection = NULL;