comparison 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
comparison
equal deleted inserted replaced
601:b2afd36d87f4 602:c5122335e41d
84 NULL, /* exit master */ 84 NULL, /* exit master */
85 NGX_MODULE_V1_PADDING 85 NGX_MODULE_V1_PADDING
86 }; 86 };
87 87
88 88
89 static ngx_uint_t ngx_degraded;
90
91
89 static ngx_int_t 92 static ngx_int_t
90 ngx_http_degradation_handler(ngx_http_request_t *r) 93 ngx_http_degradation_handler(ngx_http_request_t *r)
91 { 94 {
95 ngx_http_degradation_loc_conf_t *dlcf;
96
97 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_degradation_module);
98
99 if (dlcf->degrade && ngx_http_degraded(r)) {
100 return dlcf->degrade;
101 }
102
103 return NGX_DECLINED;
104 }
105
106
107 ngx_uint_t
108 ngx_http_degraded(ngx_http_request_t *r)
109 {
92 time_t now; 110 time_t now;
111 ngx_uint_t log;
93 static size_t sbrk_size; 112 static size_t sbrk_size;
94 static time_t sbrk_time; 113 static time_t sbrk_time;
95 ngx_http_degradation_loc_conf_t *dlcf;
96 ngx_http_degradation_main_conf_t *dmcf; 114 ngx_http_degradation_main_conf_t *dmcf;
97 115
98 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_degradation_module);
99
100 if (dlcf->degrade == 0) {
101 return NGX_DECLINED;
102 }
103
104 dmcf = ngx_http_get_module_main_conf(r, ngx_http_degradation_module); 116 dmcf = ngx_http_get_module_main_conf(r, ngx_http_degradation_module);
105 117
106 if (dmcf->sbrk_size) { 118 if (dmcf->sbrk_size) {
107 119
120 log = 0;
108 now = ngx_time(); 121 now = ngx_time();
109 122
110 /* lock mutex */ 123 /* lock mutex */
111 124
112 if (now != sbrk_time) { 125 if (now != sbrk_time) {
118 * use a function address to substract the loading address 131 * use a function address to substract the loading address
119 */ 132 */
120 133
121 sbrk_size = (size_t) sbrk(0) - ((uintptr_t) ngx_palloc & ~0x3FFFFF); 134 sbrk_size = (size_t) sbrk(0) - ((uintptr_t) ngx_palloc & ~0x3FFFFF);
122 sbrk_time = now; 135 sbrk_time = now;
136 log = 1;
123 } 137 }
124 138
125 /* unlock mutex */ 139 /* unlock mutex */
126 140
127 if (sbrk_size >= dmcf->sbrk_size) { 141 if (sbrk_size >= dmcf->sbrk_size) {
128 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 142 ngx_degraded = 1;
129 "degradation sbrk: %uz", sbrk_size); 143
130 144 if (log) {
131 return dlcf->degrade; 145 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
146 "degradation sbrk:%uzM",
147 sbrk_size / (1024 * 1024));
148 }
149
150 return 1;
132 } 151 }
133 } 152 }
134 153
135 return NGX_DECLINED; 154 ngx_degraded = 0;
155
156 return 0;
136 } 157 }
137 158
138 159
139 static void * 160 static void *
140 ngx_http_degradation_create_main_conf(ngx_conf_t *cf) 161 ngx_http_degradation_create_main_conf(ngx_conf_t *cf)