Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_upstream_least_conn_module.c @ 8546:d80365ca678d quic
HTTP/3: require mandatory uni streams before additional ones.
As per quic-http-34:
Endpoints SHOULD create the HTTP control stream as well as the
unidirectional streams required by mandatory extensions (such as the
QPACK encoder and decoder streams) first, and then create additional
streams as allowed by their peer.
Previously, client could create and destroy additional uni streams unlimited
number of times before creating mandatory streams.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Thu, 29 Jul 2021 10:03:36 +0300 |
parents | 29bf0dbc0a77 |
children |
rev | line source |
---|---|
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 /* |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 * Copyright (C) Maxim Dounin |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 * Copyright (C) Nginx, Inc. |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 static ngx_int_t ngx_http_upstream_init_least_conn_peer(ngx_http_request_t *r, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 ngx_http_upstream_srv_conf_t *us); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 static ngx_int_t ngx_http_upstream_get_least_conn_peer( |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 ngx_peer_connection_t *pc, void *data); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 static char *ngx_http_upstream_least_conn(ngx_conf_t *cf, ngx_command_t *cmd, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 void *conf); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 static ngx_command_t ngx_http_upstream_least_conn_commands[] = { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 { ngx_string("least_conn"), |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 NGX_HTTP_UPS_CONF|NGX_CONF_NOARGS, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 ngx_http_upstream_least_conn, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 0, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 0, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 NULL }, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 ngx_null_command |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 }; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 static ngx_http_module_t ngx_http_upstream_least_conn_module_ctx = { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 NULL, /* preconfiguration */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 NULL, /* postconfiguration */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 NULL, /* create main configuration */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 NULL, /* init main configuration */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
41 NULL, /* create server configuration */ |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 NULL, /* merge server configuration */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 NULL, /* create location configuration */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 NULL /* merge location configuration */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 }; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 ngx_module_t ngx_http_upstream_least_conn_module = { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 NGX_MODULE_V1, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 &ngx_http_upstream_least_conn_module_ctx, /* module context */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 ngx_http_upstream_least_conn_commands, /* module directives */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 NGX_HTTP_MODULE, /* module type */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 NULL, /* init master */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 NULL, /* init module */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 NULL, /* init process */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 NULL, /* init thread */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 NULL, /* exit thread */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 NULL, /* exit process */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 NULL, /* exit master */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 NGX_MODULE_V1_PADDING |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 }; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 |
4759
4c36e15651f7
Fixed compilation with -Wmissing-prototypes.
Ruslan Ermilov <ru@nginx.com>
parents:
4656
diff
changeset
|
65 static ngx_int_t |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 ngx_http_upstream_init_least_conn(ngx_conf_t *cf, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 ngx_http_upstream_srv_conf_t *us) |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 "init least conn"); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 if (ngx_http_upstream_init_round_robin(cf, us) != NGX_OK) { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 return NGX_ERROR; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 us->peer.init = ngx_http_upstream_init_least_conn_peer; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 return NGX_OK; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 static ngx_int_t |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 ngx_http_upstream_init_least_conn_peer(ngx_http_request_t *r, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
84 ngx_http_upstream_srv_conf_t *us) |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 "init least conn peer"); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 if (ngx_http_upstream_init_round_robin_peer(r, us) != NGX_OK) { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 return NGX_ERROR; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 r->upstream->peer.get = ngx_http_upstream_get_least_conn_peer; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 return NGX_OK; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 static ngx_int_t |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data) |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 { |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
102 ngx_http_upstream_rr_peer_data_t *rrp = data; |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 time_t now; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 uintptr_t m; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 ngx_int_t rc, total; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 ngx_uint_t i, n, p, many; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 ngx_http_upstream_rr_peer_t *peer, *best; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 ngx_http_upstream_rr_peers_t *peers; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
111 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 "get least conn peer, try: %ui", pc->tries); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
113 |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
114 if (rrp->peers->single) { |
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
115 return ngx_http_upstream_get_round_robin_peer(pc, rrp); |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
116 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
117 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
118 pc->cached = 0; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
119 pc->connection = NULL; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
120 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
121 now = ngx_time(); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
122 |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
123 peers = rrp->peers; |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
124 |
6102 | 125 ngx_http_upstream_rr_peers_wlock(peers); |
126 | |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
127 best = NULL; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
128 total = 0; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
129 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
130 #if (NGX_SUPPRESS_WARN) |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
131 many = 0; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
132 p = 0; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
133 #endif |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
134 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
135 for (peer = peers->peer, i = 0; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
136 peer; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
137 peer = peer->next, i++) |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
138 { |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
139 n = i / (8 * sizeof(uintptr_t)); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
140 m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t)); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
141 |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
142 if (rrp->tried[n] & m) { |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
143 continue; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
144 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
145 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
146 if (peer->down) { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
147 continue; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
148 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
149 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
150 if (peer->max_fails |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
151 && peer->fails >= peer->max_fails |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
152 && now - peer->checked <= peer->fail_timeout) |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
153 { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
154 continue; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
155 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
156 |
6705 | 157 if (peer->max_conns && peer->conns >= peer->max_conns) { |
158 continue; | |
159 } | |
160 | |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
161 /* |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
162 * select peer with least number of connections; if there are |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
163 * multiple peers with the same number of connections, select |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
164 * based on round-robin |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
165 */ |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
166 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
167 if (best == NULL |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
168 || peer->conns * best->weight < best->conns * peer->weight) |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
169 { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
170 best = peer; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
171 many = 0; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
172 p = i; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
173 |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
174 } else if (peer->conns * best->weight == best->conns * peer->weight) { |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
175 many = 1; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
176 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
177 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
178 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
179 if (best == NULL) { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
180 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
181 "get least conn peer, no peer found"); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
182 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
183 goto failed; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
184 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
185 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
186 if (many) { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
187 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
188 "get least conn peer, many"); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
189 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
190 for (peer = best, i = p; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
191 peer; |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
192 peer = peer->next, i++) |
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
193 { |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
194 n = i / (8 * sizeof(uintptr_t)); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
195 m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t)); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
196 |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
197 if (rrp->tried[n] & m) { |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
198 continue; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
199 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
200 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
201 if (peer->down) { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
202 continue; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
203 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
204 |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
205 if (peer->conns * best->weight != best->conns * peer->weight) { |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
206 continue; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
207 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
208 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
209 if (peer->max_fails |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
210 && peer->fails >= peer->max_fails |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
211 && now - peer->checked <= peer->fail_timeout) |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
212 { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
213 continue; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
214 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
215 |
6705 | 216 if (peer->max_conns && peer->conns >= peer->max_conns) { |
217 continue; | |
218 } | |
219 | |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
220 peer->current_weight += peer->effective_weight; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
221 total += peer->effective_weight; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
222 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
223 if (peer->effective_weight < peer->weight) { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
224 peer->effective_weight++; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
225 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
226 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
227 if (peer->current_weight > best->current_weight) { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
228 best = peer; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
229 p = i; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
230 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
231 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
232 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
233 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
234 best->current_weight -= total; |
5220
1d68b502088c
Upstream: fixed fail_timeout and max_fails > 1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5173
diff
changeset
|
235 |
1d68b502088c
Upstream: fixed fail_timeout and max_fails > 1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5173
diff
changeset
|
236 if (now - best->checked > best->fail_timeout) { |
1d68b502088c
Upstream: fixed fail_timeout and max_fails > 1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5173
diff
changeset
|
237 best->checked = now; |
1d68b502088c
Upstream: fixed fail_timeout and max_fails > 1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5173
diff
changeset
|
238 } |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
239 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
240 pc->sockaddr = best->sockaddr; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
241 pc->socklen = best->socklen; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
242 pc->name = &best->name; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
243 |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
244 best->conns++; |
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
245 |
6100
c44459611d91
Upstream: store peers as a linked list.
Ruslan Ermilov <ru@nginx.com>
parents:
6099
diff
changeset
|
246 rrp->current = best; |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
247 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
248 n = p / (8 * sizeof(uintptr_t)); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
249 m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t)); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
250 |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
251 rrp->tried[n] |= m; |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
252 |
6102 | 253 ngx_http_upstream_rr_peers_unlock(peers); |
254 | |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
255 return NGX_OK; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
256 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
257 failed: |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
258 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
259 if (peers->next) { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
260 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
261 "get least conn peer, backup servers"); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
262 |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
263 rrp->peers = peers->next; |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
264 |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
265 n = (rrp->peers->number + (8 * sizeof(uintptr_t) - 1)) |
4991
a384c60d55f3
Upstream: fixed state resetting when switching to backup servers.
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
266 / (8 * sizeof(uintptr_t)); |
a384c60d55f3
Upstream: fixed state resetting when switching to backup servers.
Valentin Bartenev <vbart@nginx.com>
parents:
4759
diff
changeset
|
267 |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
268 for (i = 0; i < n; i++) { |
6474 | 269 rrp->tried[i] = 0; |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
270 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
271 |
6102 | 272 ngx_http_upstream_rr_peers_unlock(peers); |
273 | |
6099
6ff0ebd6fbf4
Upstream: track the number of active connections to upstreams.
Ruslan Ermilov <ru@nginx.com>
parents:
5831
diff
changeset
|
274 rc = ngx_http_upstream_get_least_conn_peer(pc, rrp); |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
275 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
276 if (rc != NGX_BUSY) { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
277 return rc; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
278 } |
6102 | 279 |
280 ngx_http_upstream_rr_peers_wlock(peers); | |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
281 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
282 |
6102 | 283 ngx_http_upstream_rr_peers_unlock(peers); |
284 | |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
285 pc->name = peers->name; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
286 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
287 return NGX_BUSY; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
288 } |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
289 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
290 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
291 static char * |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
292 ngx_http_upstream_least_conn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
293 { |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
294 ngx_http_upstream_srv_conf_t *uscf; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
295 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
296 uscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module); |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
297 |
5173
5373be93c0be
Upstream: warn if multiple non-stackable balancers are installed.
Ruslan Ermilov <ru@nginx.com>
parents:
5133
diff
changeset
|
298 if (uscf->peer.init_upstream) { |
5373be93c0be
Upstream: warn if multiple non-stackable balancers are installed.
Ruslan Ermilov <ru@nginx.com>
parents:
5133
diff
changeset
|
299 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
5373be93c0be
Upstream: warn if multiple non-stackable balancers are installed.
Ruslan Ermilov <ru@nginx.com>
parents:
5133
diff
changeset
|
300 "load balancing method redefined"); |
5373be93c0be
Upstream: warn if multiple non-stackable balancers are installed.
Ruslan Ermilov <ru@nginx.com>
parents:
5133
diff
changeset
|
301 } |
5373be93c0be
Upstream: warn if multiple non-stackable balancers are installed.
Ruslan Ermilov <ru@nginx.com>
parents:
5133
diff
changeset
|
302 |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
303 uscf->peer.init_upstream = ngx_http_upstream_init_least_conn; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
304 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
305 uscf->flags = NGX_HTTP_UPSTREAM_CREATE |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
306 |NGX_HTTP_UPSTREAM_WEIGHT |
6705 | 307 |NGX_HTTP_UPSTREAM_MAX_CONNS |
4654
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
308 |NGX_HTTP_UPSTREAM_MAX_FAILS |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
309 |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
310 |NGX_HTTP_UPSTREAM_DOWN |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
311 |NGX_HTTP_UPSTREAM_BACKUP; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
312 |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
313 return NGX_CONF_OK; |
a2ca3a6ee680
Upstream: least_conn balancer module.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
314 } |