annotate src/http/modules/ngx_http_degradation_module.c @ 3772:c1e3cb4c669c

ngx_http_degraded()
author Igor Sysoev <igor@sysoev.ru>
date Mon, 04 Oct 2010 14:59:41 +0000
parents de27a5d044ff
children 147d8a86dd02
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
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
89 static ngx_uint_t ngx_degraded;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
90
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
91
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 static ngx_int_t
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93 ngx_http_degradation_handler(ngx_http_request_t *r)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 {
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
95 ngx_http_degradation_loc_conf_t *dlcf;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97 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
98
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
99 if (dlcf->degrade && ngx_http_degraded(r)) {
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
100 return dlcf->degrade;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
103 return NGX_DECLINED;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
104 }
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
105
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
106
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
107 ngx_uint_t
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
108 ngx_http_degraded(ngx_http_request_t *r)
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
109 {
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
110 time_t now;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
111 ngx_uint_t log;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
112 static size_t sbrk_size;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
113 static time_t sbrk_time;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
114 ngx_http_degradation_main_conf_t *dmcf;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
115
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116 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
117
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118 if (dmcf->sbrk_size) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
120 log = 0;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121 now = ngx_time();
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123 /* lock mutex */
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 if (now != sbrk_time) {
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 /*
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128 * ELF/i386 is loaded at 0x08000000, 128M
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129 * ELF/amd64 is loaded at 0x00400000, 4M
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 * use a function address to substract the loading address
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 sbrk_size = (size_t) sbrk(0) - ((uintptr_t) ngx_palloc & ~0x3FFFFF);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135 sbrk_time = now;
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
136 log = 1;
3326
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 /* unlock mutex */
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
141 if (sbrk_size >= dmcf->sbrk_size) {
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
142 ngx_degraded = 1;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
144 if (log) {
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
145 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0,
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
146 "degradation sbrk:%uzM",
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
147 sbrk_size / (1024 * 1024));
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
148 }
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
149
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
150 return 1;
3326
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
3772
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
154 ngx_degraded = 0;
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
155
c1e3cb4c669c ngx_http_degraded()
Igor Sysoev <igor@sysoev.ru>
parents: 3389
diff changeset
156 return 0;
3326
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
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160 static void *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161 ngx_http_degradation_create_main_conf(ngx_conf_t *cf)
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 ngx_http_degradation_main_conf_t *dmcf;
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 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
166 if (dmcf == NULL) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167 return NULL;
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
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
170 return dmcf;
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
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174 static void *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175 ngx_http_degradation_create_loc_conf(ngx_conf_t *cf)
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 ngx_http_degradation_loc_conf_t *conf;
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 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
180 if (conf == NULL) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 return NULL;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182 }
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 conf->degrade = NGX_CONF_UNSET_UINT;
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 return conf;
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
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 static char *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191 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
192 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193 ngx_http_degradation_loc_conf_t *prev = parent;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194 ngx_http_degradation_loc_conf_t *conf = child;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
195
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
196 ngx_conf_merge_uint_value(conf->degrade, prev->degrade, 0);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
197
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 return NGX_CONF_OK;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202 static char *
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203 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
204 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205 ngx_http_degradation_main_conf_t *dmcf = conf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207 ngx_str_t *value, s;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
209 value = cf->args->elts;
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 if (ngx_strncmp(value[1].data, "sbrk=", 5) == 0) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
212
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
213 s.len = value[1].len - 5;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
214 s.data = value[1].data + 5;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
216 dmcf->sbrk_size = ngx_parse_size(&s);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
217 if (dmcf->sbrk_size == (size_t) NGX_ERROR) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
219 "invalid sbrk size \"%V\"", &value[1]);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220 return NGX_CONF_ERROR;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221 }
3389
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
222
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
223 return NGX_CONF_OK;
3326
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
3389
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
226 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
227 "invalid parameter \"%V\"", &value[1]);
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
228
de27a5d044ff test degradation parameters
Igor Sysoev <igor@sysoev.ru>
parents: 3326
diff changeset
229 return NGX_CONF_ERROR;
3326
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
230 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
231
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
232
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233 static ngx_int_t
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234 ngx_http_degradation_init(ngx_conf_t *cf)
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
235 {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
236 ngx_http_handler_pt *h;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237 ngx_http_core_main_conf_t *cmcf;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239 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
240
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
241 h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers);
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242 if (h == NULL) {
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
243 return NGX_ERROR;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
244 }
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
245
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
246 *h = ngx_http_degradation_handler;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
247
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
248 return NGX_OK;
e6967a1dc8e9 ngx_http_degradation_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
249 }