Mercurial > hg > nginx-ranges
comparison src/http/modules/ngx_http_degradation_module.c @ 635:e67b227c8dbb default tip
Merge with current.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 25 Apr 2011 04:07:55 +0400 |
parents | 428c6e58046a |
children |
comparison
equal
deleted
inserted
replaced
578:f3a9e57d2e17 | 635:e67b227c8dbb |
---|---|
87 | 87 |
88 | 88 |
89 static ngx_int_t | 89 static ngx_int_t |
90 ngx_http_degradation_handler(ngx_http_request_t *r) | 90 ngx_http_degradation_handler(ngx_http_request_t *r) |
91 { | 91 { |
92 ngx_http_degradation_loc_conf_t *dlcf; | |
93 | |
94 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_degradation_module); | |
95 | |
96 if (dlcf->degrade && ngx_http_degraded(r)) { | |
97 return dlcf->degrade; | |
98 } | |
99 | |
100 return NGX_DECLINED; | |
101 } | |
102 | |
103 | |
104 ngx_uint_t | |
105 ngx_http_degraded(ngx_http_request_t *r) | |
106 { | |
92 time_t now; | 107 time_t now; |
108 ngx_uint_t log; | |
93 static size_t sbrk_size; | 109 static size_t sbrk_size; |
94 static time_t sbrk_time; | 110 static time_t sbrk_time; |
95 ngx_http_degradation_loc_conf_t *dlcf; | |
96 ngx_http_degradation_main_conf_t *dmcf; | 111 ngx_http_degradation_main_conf_t *dmcf; |
97 | 112 |
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); | 113 dmcf = ngx_http_get_module_main_conf(r, ngx_http_degradation_module); |
105 | 114 |
106 if (dmcf->sbrk_size) { | 115 if (dmcf->sbrk_size) { |
107 | 116 |
117 log = 0; | |
108 now = ngx_time(); | 118 now = ngx_time(); |
109 | 119 |
110 /* lock mutex */ | 120 /* lock mutex */ |
111 | 121 |
112 if (now != sbrk_time) { | 122 if (now != sbrk_time) { |
118 * use a function address to substract the loading address | 128 * use a function address to substract the loading address |
119 */ | 129 */ |
120 | 130 |
121 sbrk_size = (size_t) sbrk(0) - ((uintptr_t) ngx_palloc & ~0x3FFFFF); | 131 sbrk_size = (size_t) sbrk(0) - ((uintptr_t) ngx_palloc & ~0x3FFFFF); |
122 sbrk_time = now; | 132 sbrk_time = now; |
133 log = 1; | |
123 } | 134 } |
124 | 135 |
125 /* unlock mutex */ | 136 /* unlock mutex */ |
126 | 137 |
127 if (sbrk_size >= dmcf->sbrk_size) { | 138 if (sbrk_size >= dmcf->sbrk_size) { |
128 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 139 if (log) { |
129 "degradation sbrk: %uz", sbrk_size); | 140 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, |
130 | 141 "degradation sbrk:%uzM", |
131 return dlcf->degrade; | 142 sbrk_size / (1024 * 1024)); |
143 } | |
144 | |
145 return 1; | |
132 } | 146 } |
133 } | 147 } |
134 | 148 |
135 return NGX_DECLINED; | 149 return 0; |
136 } | 150 } |
137 | 151 |
138 | 152 |
139 static void * | 153 static void * |
140 ngx_http_degradation_create_main_conf(ngx_conf_t *cf) | 154 ngx_http_degradation_create_main_conf(ngx_conf_t *cf) |