summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2010-10-04 14:59:41 +0000
committerIgor Sysoev <igor@sysoev.ru>2010-10-04 14:59:41 +0000
commit81aa52829ae021dc226b4d25330c63c2ff31149a (patch)
tree9e38155cd8e237d2f9815562fd5146fe0a776917
parent61d5e5e67fa3f95526d0dc666137ebfebe6709dc (diff)
downloadnginx-81aa52829ae021dc226b4d25330c63c2ff31149a.tar.gz
ngx_http_degraded()
-rw-r--r--src/http/modules/ngx_http_degradation_module.c43
-rw-r--r--src/http/ngx_http.h4
2 files changed, 36 insertions, 11 deletions
diff --git a/src/http/modules/ngx_http_degradation_module.c b/src/http/modules/ngx_http_degradation_module.c
index b221f2215..a35733f81 100644
--- 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_module = {
};
+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_request_t *r)
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;
+
+ if (log) {
+ ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
+ "degradation sbrk:%uzM",
+ sbrk_size / (1024 * 1024));
+ }
- return dlcf->degrade;
+ return 1;
}
}
- return NGX_DECLINED;
+ ngx_degraded = 0;
+
+ return 0;
}
diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h
index 9351cb09a..e3619e148 100644
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -142,6 +142,10 @@ char *ngx_http_merge_types(ngx_conf_t *cf, ngx_array_t **keys,
ngx_int_t ngx_http_set_default_types(ngx_conf_t *cf, ngx_array_t **types,
ngx_str_t *default_type);
+#if (NGX_HTTP_DEGRADATION)
+ngx_uint_t ngx_http_degraded(ngx_http_request_t *);
+#endif
+
extern ngx_module_t ngx_http_module;