annotate src/http/modules/ngx_http_degradation_module.c @ 3389:de27a5d044ff

test degradation parameters
author Igor Sysoev <igor@sysoev.ru>
date Thu, 17 Dec 2009 12:45:13 +0000
parents e6967a1dc8e9
children c1e3cb4c669c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4 */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12 typedef struct {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 size_t sbrk_size;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14 } ngx_http_degradation_main_conf_t;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 typedef struct {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18 ngx_uint_t degrade;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19 } ngx_http_degradation_loc_conf_t;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 static ngx_conf_enum_t ngx_http_degrade[] = {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 { ngx_string("204"), 204 },
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 { ngx_string("444"), 444 },
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25 { ngx_null_string, 0 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 };
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29 static void *ngx_http_degradation_create_main_conf(ngx_conf_t *cf);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30 static void *ngx_http_degradation_create_loc_conf(ngx_conf_t *cf);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 static char *ngx_http_degradation_merge_loc_conf(ngx_conf_t *cf, void *parent,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 void *child);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33 static char *ngx_http_degradation(ngx_conf_t *cf, ngx_command_t *cmd,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 void *conf);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35 static ngx_int_t ngx_http_degradation_init(ngx_conf_t *cf);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38 static ngx_command_t ngx_http_degradation_commands[] = {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40 { ngx_string("degradation"),
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42 ngx_http_degradation,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
43 NGX_HTTP_MAIN_CONF_OFFSET,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 0,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45 NULL },
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
46
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
47 { ngx_string("degrade"),
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49 ngx_conf_set_enum_slot,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50 NGX_HTTP_LOC_CONF_OFFSET,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51 offsetof(ngx_http_degradation_loc_conf_t, degrade),
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52 &ngx_http_degrade },
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
53
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
54 ngx_null_command
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55 };
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 static ngx_http_module_t ngx_http_degradation_module_ctx = {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 NULL, /* preconfiguration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60 ngx_http_degradation_init, /* postconfiguration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 ngx_http_degradation_create_main_conf, /* create main configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63 NULL, /* init main configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65 NULL, /* create server configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
66 NULL, /* merge server configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68 ngx_http_degradation_create_loc_conf, /* create location configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
69 ngx_http_degradation_merge_loc_conf /* merge location configuration */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70 };
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
72
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 ngx_module_t ngx_http_degradation_module = {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74 NGX_MODULE_V1,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75 &ngx_http_degradation_module_ctx, /* module context */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 ngx_http_degradation_commands, /* module directives */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77 NGX_HTTP_MODULE, /* module type */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 NULL, /* init master */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 NULL, /* init module */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 NULL, /* init process */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81 NULL, /* init thread */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 NULL, /* exit thread */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 NULL, /* exit process */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 NULL, /* exit master */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85 NGX_MODULE_V1_PADDING
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 };
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 static ngx_int_t
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90 ngx_http_degradation_handler(ngx_http_request_t *r)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 time_t now;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93 static size_t sbrk_size;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 static time_t sbrk_time;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 ngx_http_degradation_loc_conf_t *dlcf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 ngx_http_degradation_main_conf_t *dmcf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 dlcf = ngx_http_get_module_loc_conf(r, ngx_http_degradation_module);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100 if (dlcf->degrade == 0) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 return NGX_DECLINED;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
104 dmcf = ngx_http_get_module_main_conf(r, ngx_http_degradation_module);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
105
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106 if (dmcf->sbrk_size) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108 now = ngx_time();
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
109
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110 /* lock mutex */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112 if (now != sbrk_time) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
113
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114 /*
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
115 * ELF/i386 is loaded at 0x08000000, 128M
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116 * ELF/amd64 is loaded at 0x00400000, 4M
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
117 *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118 * use a function address to substract the loading address
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119 */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121 sbrk_size = (size_t) sbrk(0) - ((uintptr_t) ngx_palloc & ~0x3FFFFF);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122 sbrk_time = now;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125 /* unlock mutex */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127 if (sbrk_size >= dmcf->sbrk_size) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129 "degradation sbrk: %uz", sbrk_size);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131 return dlcf->degrade;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135 return NGX_DECLINED;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
139 static void *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140 ngx_http_degradation_create_main_conf(ngx_conf_t *cf)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
141 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 ngx_http_degradation_main_conf_t *dmcf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144 dmcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_degradation_main_conf_t));
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 if (dmcf == NULL) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 return NULL;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149 return dmcf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153 static void *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 ngx_http_degradation_create_loc_conf(ngx_conf_t *cf)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 ngx_http_degradation_loc_conf_t *conf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158 conf = ngx_palloc(cf->pool, sizeof(ngx_http_degradation_loc_conf_t));
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159 if (conf == NULL) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160 return NULL;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
162
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
163 conf->degrade = NGX_CONF_UNSET_UINT;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165 return conf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
168
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
169 static char *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
170 ngx_http_degradation_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
171 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
172 ngx_http_degradation_loc_conf_t *prev = parent;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173 ngx_http_degradation_loc_conf_t *conf = child;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175 ngx_conf_merge_uint_value(conf->degrade, prev->degrade, 0);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
176
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177 return NGX_CONF_OK;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 static char *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182 ngx_http_degradation(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184 ngx_http_degradation_main_conf_t *dmcf = conf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186 ngx_str_t *value, s;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188 value = cf->args->elts;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190 if (ngx_strncmp(value[1].data, "sbrk=", 5) == 0) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192 s.len = value[1].len - 5;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193 s.data = value[1].data + 5;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
195 dmcf->sbrk_size = ngx_parse_size(&s);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
196 if (dmcf->sbrk_size == (size_t) NGX_ERROR) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
197 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 "invalid sbrk size \"%V\"", &value[1]);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199 return NGX_CONF_ERROR;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200 }
3389
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
201
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
202 return NGX_CONF_OK;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
204
3389
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
205 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
206 "invalid parameter \"%V\"", &value[1]);
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
207
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
208 return NGX_CONF_ERROR;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
209 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
212 static ngx_int_t
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
213 ngx_http_degradation_init(ngx_conf_t *cf)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
214 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215 ngx_http_handler_pt *h;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
216 ngx_http_core_main_conf_t *cmcf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
217
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
219
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220 h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221 if (h == NULL) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
222 return NGX_ERROR;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
223 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
225 *h = ngx_http_degradation_handler;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
226
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
227 return NGX_OK;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228 }