Mercurial > hg > nginx-vendor-current
diff src/http/modules/ngx_http_degradation_module.c @ 602:c5122335e41d NGINX_0_8_53
nginx 0.8.53
*) Feature: now the "error_page" directive allows to change a status
code in a redirect.
*) Feature: the "gzip_disable" directive supports special "degradation"
mask.
*) Bugfix: a socket leak might occurred if file AIO was used.
Thanks to Maxim Dounin.
*) Bugfix: if the first server had no "listen" directive and there was
no explicit default server, then a next server with a "listen"
directive became the default server; the bug had appeared in 0.8.21.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 18 Oct 2010 00:00:00 +0400 |
parents | 2da4537168f8 |
children | 428c6e58046a |
line wrap: on
line diff
--- a/src/http/modules/ngx_http_degradation_module.c +++ b/src/http/modules/ngx_http_degradation_module.c @@ -86,25 +86,38 @@ ngx_module_t ngx_http_degradation_modul }; +static ngx_uint_t ngx_degraded; + + static ngx_int_t ngx_http_degradation_handler(ngx_http_request_t *r) { - time_t now; - static size_t sbrk_size; - static time_t sbrk_time; - ngx_http_degradation_loc_conf_t *dlcf; - ngx_http_degradation_main_conf_t *dmcf; + ngx_http_degradation_loc_conf_t *dlcf; dlcf = ngx_http_get_module_loc_conf(r, ngx_http_degradation_module); - if (dlcf->degrade == 0) { - return NGX_DECLINED; + if (dlcf->degrade && ngx_http_degraded(r)) { + return dlcf->degrade; } + return NGX_DECLINED; +} + + +ngx_uint_t +ngx_http_degraded(ngx_http_request_t *r) +{ + time_t now; + ngx_uint_t log; + static size_t sbrk_size; + static time_t sbrk_time; + ngx_http_degradation_main_conf_t *dmcf; + dmcf = ngx_http_get_module_main_conf(r, ngx_http_degradation_module); if (dmcf->sbrk_size) { + log = 0; now = ngx_time(); /* lock mutex */ @@ -120,19 +133,27 @@ ngx_http_degradation_handler(ngx_http_re sbrk_size = (size_t) sbrk(0) - ((uintptr_t) ngx_palloc & ~0x3FFFFF); sbrk_time = now; + log = 1; } /* unlock mutex */ if (sbrk_size >= dmcf->sbrk_size) { - ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, - "degradation sbrk: %uz", sbrk_size); + ngx_degraded = 1; - return dlcf->degrade; + if (log) { + ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, + "degradation sbrk:%uzM", + sbrk_size / (1024 * 1024)); + } + + return 1; } } - return NGX_DECLINED; + ngx_degraded = 0; + + return 0; }