Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_upstream_least_conn_module.c @ 5161:a5f7d455e271 stable-1.2
Merge of r5130, r5131, r5132: support for Mercurial repositories.
*) Misc: switch to single export operation in "zip" target.
While exporting parts of the tree might be better in some cases, it
is awfully slow overseas, and also requires unlocking ssh key multiple
times. Exporting the whole repo and removing directories not needed for
zip is faster here.
It is also a required step before we can switch to Mercurial.
*) Misc: removed unused "snapshot" target.
*) Misc: support for Mercurial repositories.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 29 Mar 2013 18:09:06 +0000 |
parents | ac3690ee6c28 |
children | ee9a043765ea |
rev | line source |
---|---|
4724
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 /* |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 * Copyright (C) Maxim Dounin |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 * Copyright (C) Nginx, Inc. |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 typedef struct { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 ngx_uint_t *conns; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 } ngx_http_upstream_least_conn_conf_t; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 typedef struct { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 /* the round robin data must be first */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 ngx_http_upstream_rr_peer_data_t rrp; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 ngx_uint_t *conns; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
23 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 ngx_event_get_peer_pt get_rr_peer; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 ngx_event_free_peer_pt free_rr_peer; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 } ngx_http_upstream_lc_peer_data_t; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 static ngx_int_t ngx_http_upstream_init_least_conn_peer(ngx_http_request_t *r, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 ngx_http_upstream_srv_conf_t *us); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 static ngx_int_t ngx_http_upstream_get_least_conn_peer( |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 ngx_peer_connection_t *pc, void *data); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 static void ngx_http_upstream_free_least_conn_peer(ngx_peer_connection_t *pc, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 void *data, ngx_uint_t state); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 static void *ngx_http_upstream_least_conn_create_conf(ngx_conf_t *cf); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 static char *ngx_http_upstream_least_conn(ngx_conf_t *cf, ngx_command_t *cmd, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 void *conf); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 static ngx_command_t ngx_http_upstream_least_conn_commands[] = { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 { ngx_string("least_conn"), |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 NGX_HTTP_UPS_CONF|NGX_CONF_NOARGS, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 ngx_http_upstream_least_conn, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 0, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 0, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 NULL }, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 ngx_null_command |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 }; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 static ngx_http_module_t ngx_http_upstream_least_conn_module_ctx = { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 NULL, /* preconfiguration */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 NULL, /* postconfiguration */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 NULL, /* create main configuration */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 NULL, /* init main configuration */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 ngx_http_upstream_least_conn_create_conf, /* create server configuration */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 NULL, /* merge server configuration */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 NULL, /* create location configuration */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 NULL /* merge location configuration */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 }; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 ngx_module_t ngx_http_upstream_least_conn_module = { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 NGX_MODULE_V1, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 &ngx_http_upstream_least_conn_module_ctx, /* module context */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 ngx_http_upstream_least_conn_commands, /* module directives */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 NGX_HTTP_MODULE, /* module type */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 NULL, /* init master */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 NULL, /* init module */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 NULL, /* init process */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 NULL, /* init thread */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 NULL, /* exit thread */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 NULL, /* exit process */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 NULL, /* exit master */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 NGX_MODULE_V1_PADDING |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 }; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
82 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
83 |
4798
29928279ec9f
Merge of r4760, r4761: -Wmissing-prototypes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4724
diff
changeset
|
84 static ngx_int_t |
4724
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
85 ngx_http_upstream_init_least_conn(ngx_conf_t *cf, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
86 ngx_http_upstream_srv_conf_t *us) |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
87 { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
88 ngx_uint_t n; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
89 ngx_http_upstream_rr_peers_t *peers; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
90 ngx_http_upstream_least_conn_conf_t *lcf; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
91 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 "init least conn"); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 if (ngx_http_upstream_init_round_robin(cf, us) != NGX_OK) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 return NGX_ERROR; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
98 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 peers = us->peer.data; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 n = peers->number; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 if (peers->next) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 n += peers->next->number; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
105 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
106 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
107 lcf = ngx_http_conf_upstream_srv_conf(us, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
108 ngx_http_upstream_least_conn_module); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
109 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 lcf->conns = ngx_pcalloc(cf->pool, sizeof(ngx_uint_t) * n); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
111 if (lcf->conns == NULL) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 return NGX_ERROR; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
113 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
115 us->peer.init = ngx_http_upstream_init_least_conn_peer; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
116 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
117 return NGX_OK; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
118 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
119 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
120 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
121 static ngx_int_t |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
122 ngx_http_upstream_init_least_conn_peer(ngx_http_request_t *r, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
123 ngx_http_upstream_srv_conf_t *us) |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
124 { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
125 ngx_http_upstream_lc_peer_data_t *lcp; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
126 ngx_http_upstream_least_conn_conf_t *lcf; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
127 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
128 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
129 "init least conn peer"); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
130 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
131 lcf = ngx_http_conf_upstream_srv_conf(us, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
132 ngx_http_upstream_least_conn_module); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
133 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
134 lcp = ngx_palloc(r->pool, sizeof(ngx_http_upstream_lc_peer_data_t)); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
135 if (lcp == NULL) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
136 return NGX_ERROR; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
137 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
138 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
139 lcp->conns = lcf->conns; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
140 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
141 r->upstream->peer.data = &lcp->rrp; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
142 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
143 if (ngx_http_upstream_init_round_robin_peer(r, us) != NGX_OK) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
144 return NGX_ERROR; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
145 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
146 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
147 r->upstream->peer.get = ngx_http_upstream_get_least_conn_peer; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
148 r->upstream->peer.free = ngx_http_upstream_free_least_conn_peer; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
149 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
150 lcp->get_rr_peer = ngx_http_upstream_get_round_robin_peer; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
151 lcp->free_rr_peer = ngx_http_upstream_free_round_robin_peer; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
152 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
153 return NGX_OK; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
154 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
155 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
156 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
157 static ngx_int_t |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
158 ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data) |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
159 { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
160 ngx_http_upstream_lc_peer_data_t *lcp = data; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
161 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
162 time_t now; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
163 uintptr_t m; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
164 ngx_int_t rc, total; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
165 ngx_uint_t i, n, p, many; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
166 ngx_http_upstream_rr_peer_t *peer, *best; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
167 ngx_http_upstream_rr_peers_t *peers; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
168 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
169 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
170 "get least conn peer, try: %ui", pc->tries); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
171 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
172 if (lcp->rrp.peers->single) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
173 return lcp->get_rr_peer(pc, &lcp->rrp); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
174 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
175 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
176 pc->cached = 0; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
177 pc->connection = NULL; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
178 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
179 now = ngx_time(); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
180 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
181 peers = lcp->rrp.peers; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
182 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
183 best = NULL; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
184 total = 0; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
185 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
186 #if (NGX_SUPPRESS_WARN) |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
187 many = 0; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
188 p = 0; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
189 #endif |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
190 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
191 for (i = 0; i < peers->number; i++) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
192 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
193 n = i / (8 * sizeof(uintptr_t)); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
194 m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t)); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
195 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
196 if (lcp->rrp.tried[n] & m) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
197 continue; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
198 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
199 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
200 peer = &peers->peer[i]; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
201 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
202 if (peer->down) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
203 continue; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
204 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
205 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
206 if (peer->max_fails |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
207 && peer->fails >= peer->max_fails |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
208 && now - peer->checked <= peer->fail_timeout) |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
209 { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
210 continue; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
211 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
212 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
213 /* |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
214 * select peer with least number of connections; if there are |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
215 * multiple peers with the same number of connections, select |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
216 * based on round-robin |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
217 */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
218 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
219 if (best == NULL |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
220 || lcp->conns[i] * best->weight < lcp->conns[p] * peer->weight) |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
221 { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
222 best = peer; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
223 many = 0; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
224 p = i; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
225 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
226 } else if (lcp->conns[i] * best->weight |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
227 == lcp->conns[p] * peer->weight) |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
228 { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
229 many = 1; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
230 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
231 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
232 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
233 if (best == NULL) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
234 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
235 "get least conn peer, no peer found"); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
236 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
237 goto failed; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
238 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
239 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
240 if (many) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
241 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
242 "get least conn peer, many"); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
243 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
244 for (i = p; i < peers->number; i++) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
245 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
246 n = i / (8 * sizeof(uintptr_t)); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
247 m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t)); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
248 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
249 if (lcp->rrp.tried[n] & m) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
250 continue; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
251 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
252 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
253 peer = &peers->peer[i]; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
254 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
255 if (peer->down) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
256 continue; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
257 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
258 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
259 if (lcp->conns[i] * best->weight != lcp->conns[p] * peer->weight) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
260 continue; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
261 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
262 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
263 if (peer->max_fails |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
264 && peer->fails >= peer->max_fails |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
265 && now - peer->checked <= peer->fail_timeout) |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
266 { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
267 continue; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
268 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
269 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
270 peer->current_weight += peer->effective_weight; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
271 total += peer->effective_weight; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
272 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
273 if (peer->effective_weight < peer->weight) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
274 peer->effective_weight++; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
275 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
276 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
277 if (peer->current_weight > best->current_weight) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
278 best = peer; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
279 p = i; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
280 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
281 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
282 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
283 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
284 best->current_weight -= total; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
285 best->checked = now; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
286 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
287 pc->sockaddr = best->sockaddr; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
288 pc->socklen = best->socklen; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
289 pc->name = &best->name; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
290 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
291 lcp->rrp.current = p; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
292 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
293 n = p / (8 * sizeof(uintptr_t)); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
294 m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t)); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
295 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
296 lcp->rrp.tried[n] |= m; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
297 lcp->conns[p]++; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
298 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
299 if (pc->tries == 1 && peers->next) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
300 pc->tries += peers->next->number; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
301 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
302 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
303 return NGX_OK; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
304 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
305 failed: |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
306 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
307 if (peers->next) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
308 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
309 "get least conn peer, backup servers"); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
310 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
311 lcp->conns += peers->number; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
312 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
313 lcp->rrp.peers = peers->next; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
314 pc->tries = lcp->rrp.peers->number; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
315 |
5055
ac3690ee6c28
Merge of r4992: off-by-one with 32/64 upstream backup servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4798
diff
changeset
|
316 n = (lcp->rrp.peers->number + (8 * sizeof(uintptr_t) - 1)) |
ac3690ee6c28
Merge of r4992: off-by-one with 32/64 upstream backup servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4798
diff
changeset
|
317 / (8 * sizeof(uintptr_t)); |
ac3690ee6c28
Merge of r4992: off-by-one with 32/64 upstream backup servers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4798
diff
changeset
|
318 |
4724
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
319 for (i = 0; i < n; i++) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
320 lcp->rrp.tried[i] = 0; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
321 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
322 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
323 rc = ngx_http_upstream_get_least_conn_peer(pc, lcp); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
324 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
325 if (rc != NGX_BUSY) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
326 return rc; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
327 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
328 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
329 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
330 /* all peers failed, mark them as live for quick recovery */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
331 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
332 for (i = 0; i < peers->number; i++) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
333 peers->peer[i].fails = 0; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
334 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
335 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
336 pc->name = peers->name; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
337 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
338 return NGX_BUSY; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
339 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
340 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
341 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
342 static void |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
343 ngx_http_upstream_free_least_conn_peer(ngx_peer_connection_t *pc, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
344 void *data, ngx_uint_t state) |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
345 { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
346 ngx_http_upstream_lc_peer_data_t *lcp = data; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
347 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
348 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
349 "free least conn peer %ui %ui", pc->tries, state); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
350 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
351 if (lcp->rrp.peers->single) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
352 lcp->free_rr_peer(pc, &lcp->rrp, state); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
353 return; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
354 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
355 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
356 if (state == 0 && pc->tries == 0) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
357 return; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
358 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
359 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
360 lcp->conns[lcp->rrp.current]--; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
361 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
362 lcp->free_rr_peer(pc, &lcp->rrp, state); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
363 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
364 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
365 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
366 static void * |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
367 ngx_http_upstream_least_conn_create_conf(ngx_conf_t *cf) |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
368 { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
369 ngx_http_upstream_least_conn_conf_t *conf; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
370 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
371 conf = ngx_pcalloc(cf->pool, |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
372 sizeof(ngx_http_upstream_least_conn_conf_t)); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
373 if (conf == NULL) { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
374 return NULL; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
375 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
376 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
377 /* |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
378 * set by ngx_pcalloc(): |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
379 * |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
380 * conf->conns = NULL; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
381 */ |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
382 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
383 return conf; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
384 } |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
385 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
386 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
387 static char * |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
388 ngx_http_upstream_least_conn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
389 { |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
390 ngx_http_upstream_srv_conf_t *uscf; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
391 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
392 uscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module); |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
393 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
394 uscf->peer.init_upstream = ngx_http_upstream_init_least_conn; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
395 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
396 uscf->flags = NGX_HTTP_UPSTREAM_CREATE |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
397 |NGX_HTTP_UPSTREAM_WEIGHT |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
398 |NGX_HTTP_UPSTREAM_MAX_FAILS |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
399 |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
400 |NGX_HTTP_UPSTREAM_DOWN |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
401 |NGX_HTTP_UPSTREAM_BACKUP; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
402 |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
403 return NGX_CONF_OK; |
0141b4aec0e4
Merge of r4655, r4656, r4657, r4695, r4696: upstream changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
404 } |