nginxtra 1.8.1.12 → 1.10.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. checksums.yaml +4 -4
  2. data/bin/nginxtra +1 -1
  3. data/bin/nginxtra_rails +1 -1
  4. data/lib/nginxtra/version.rb +1 -1
  5. data/vendor/nginx/CHANGES +363 -25
  6. data/vendor/nginx/CHANGES.ru +365 -21
  7. data/vendor/nginx/LICENSE +2 -2
  8. data/vendor/nginx/auto/cc/conf +32 -0
  9. data/vendor/nginx/auto/cc/gcc +1 -1
  10. data/vendor/nginx/auto/cc/icc +2 -2
  11. data/vendor/nginx/auto/cc/msvc +29 -8
  12. data/vendor/nginx/auto/cc/name +2 -25
  13. data/vendor/nginx/auto/cc/sunc +3 -0
  14. data/vendor/nginx/auto/endianness +7 -2
  15. data/vendor/nginx/auto/install +60 -26
  16. data/vendor/nginx/auto/lib/conf +4 -4
  17. data/vendor/nginx/auto/lib/geoip/conf +6 -1
  18. data/vendor/nginx/auto/lib/libgd/conf +6 -1
  19. data/vendor/nginx/auto/lib/libxslt/conf +11 -2
  20. data/vendor/nginx/auto/lib/make +1 -1
  21. data/vendor/nginx/auto/lib/md5/conf +2 -2
  22. data/vendor/nginx/auto/lib/md5/make +2 -2
  23. data/vendor/nginx/auto/lib/openssl/conf +52 -3
  24. data/vendor/nginx/auto/lib/openssl/make +1 -1
  25. data/vendor/nginx/auto/lib/pcre/conf +2 -2
  26. data/vendor/nginx/auto/lib/pcre/make +2 -2
  27. data/vendor/nginx/auto/lib/perl/conf +6 -3
  28. data/vendor/nginx/auto/lib/perl/make +4 -1
  29. data/vendor/nginx/auto/lib/sha1/conf +2 -2
  30. data/vendor/nginx/auto/lib/sha1/make +2 -2
  31. data/vendor/nginx/auto/lib/zlib/conf +2 -2
  32. data/vendor/nginx/auto/lib/zlib/make +2 -2
  33. data/vendor/nginx/auto/make +281 -16
  34. data/vendor/nginx/auto/module +122 -0
  35. data/vendor/nginx/auto/modules +909 -178
  36. data/vendor/nginx/auto/options +81 -19
  37. data/vendor/nginx/auto/os/conf +9 -0
  38. data/vendor/nginx/auto/os/darwin +3 -0
  39. data/vendor/nginx/auto/os/freebsd +0 -20
  40. data/vendor/nginx/auto/os/linux +0 -12
  41. data/vendor/nginx/auto/os/win32 +5 -1
  42. data/vendor/nginx/auto/sources +11 -311
  43. data/vendor/nginx/auto/summary +1 -0
  44. data/vendor/nginx/auto/types/sizeof +5 -3
  45. data/vendor/nginx/auto/types/typedef +9 -4
  46. data/vendor/nginx/auto/types/uintptr_t +7 -2
  47. data/vendor/nginx/auto/unix +72 -12
  48. data/vendor/nginx/conf/fastcgi.conf +1 -0
  49. data/vendor/nginx/conf/fastcgi_params +1 -0
  50. data/vendor/nginx/conf/scgi_params +1 -0
  51. data/vendor/nginx/conf/uwsgi_params +1 -0
  52. data/vendor/nginx/configure +1 -1
  53. data/vendor/nginx/contrib/vim/syntax/nginx.vim +2 -2
  54. data/vendor/nginx/man/nginx.8 +6 -2
  55. data/vendor/nginx/src/core/nginx.c +281 -114
  56. data/vendor/nginx/src/core/nginx.h +2 -2
  57. data/vendor/nginx/src/core/ngx_conf_file.c +54 -13
  58. data/vendor/nginx/src/core/ngx_conf_file.h +8 -52
  59. data/vendor/nginx/src/core/ngx_config.h +0 -5
  60. data/vendor/nginx/src/core/ngx_connection.c +270 -37
  61. data/vendor/nginx/src/core/ngx_connection.h +35 -12
  62. data/vendor/nginx/src/core/ngx_core.h +4 -0
  63. data/vendor/nginx/src/core/ngx_crypt.c +2 -2
  64. data/vendor/nginx/src/core/ngx_cycle.c +72 -25
  65. data/vendor/nginx/src/core/ngx_cycle.h +28 -39
  66. data/vendor/nginx/src/core/ngx_file.c +14 -5
  67. data/vendor/nginx/src/core/ngx_file.h +2 -0
  68. data/vendor/nginx/src/core/ngx_hash.c +13 -1
  69. data/vendor/nginx/src/core/ngx_inet.c +20 -18
  70. data/vendor/nginx/src/core/ngx_log.c +12 -12
  71. data/vendor/nginx/src/core/ngx_log.h +13 -6
  72. data/vendor/nginx/src/core/ngx_module.c +360 -0
  73. data/vendor/nginx/src/core/ngx_module.h +307 -0
  74. data/vendor/nginx/src/core/ngx_open_file_cache.c +2 -2
  75. data/vendor/nginx/src/core/ngx_output_chain.c +8 -4
  76. data/vendor/nginx/src/core/ngx_palloc.c +42 -44
  77. data/vendor/nginx/src/{http/ngx_http_parse_time.c → core/ngx_parse_time.c} +2 -3
  78. data/vendor/nginx/src/core/ngx_parse_time.h +22 -0
  79. data/vendor/nginx/src/core/ngx_proxy_protocol.c +50 -1
  80. data/vendor/nginx/src/core/ngx_proxy_protocol.h +3 -1
  81. data/vendor/nginx/src/core/ngx_regex.c +1 -38
  82. data/vendor/nginx/src/core/ngx_resolver.c +1814 -320
  83. data/vendor/nginx/src/core/ngx_resolver.h +67 -10
  84. data/vendor/nginx/src/core/ngx_rwlock.c +120 -0
  85. data/vendor/nginx/src/core/ngx_rwlock.h +21 -0
  86. data/vendor/nginx/src/core/ngx_slab.c +6 -5
  87. data/vendor/nginx/src/core/ngx_string.c +1 -1
  88. data/vendor/nginx/src/core/ngx_syslog.c +11 -3
  89. data/vendor/nginx/src/core/ngx_syslog.h +2 -1
  90. data/vendor/nginx/src/core/ngx_thread_pool.c +4 -0
  91. data/vendor/nginx/src/core/ngx_times.c +2 -2
  92. data/vendor/nginx/src/event/modules/ngx_devpoll_module.c +3 -1
  93. data/vendor/nginx/src/event/modules/ngx_epoll_module.c +5 -2
  94. data/vendor/nginx/src/event/modules/ngx_eventport_module.c +5 -5
  95. data/vendor/nginx/src/event/modules/ngx_kqueue_module.c +15 -8
  96. data/vendor/nginx/src/event/modules/ngx_poll_module.c +0 -10
  97. data/vendor/nginx/src/event/modules/ngx_select_module.c +0 -10
  98. data/vendor/nginx/src/event/ngx_event.c +60 -103
  99. data/vendor/nginx/src/event/ngx_event.h +22 -26
  100. data/vendor/nginx/src/event/ngx_event_accept.c +414 -88
  101. data/vendor/nginx/src/event/ngx_event_connect.c +27 -18
  102. data/vendor/nginx/src/event/ngx_event_connect.h +1 -0
  103. data/vendor/nginx/src/event/ngx_event_openssl.c +65 -25
  104. data/vendor/nginx/src/event/ngx_event_openssl.h +17 -0
  105. data/vendor/nginx/src/event/ngx_event_openssl_stapling.c +73 -7
  106. data/vendor/nginx/src/event/ngx_event_pipe.c +85 -27
  107. data/vendor/nginx/src/event/ngx_event_pipe.h +10 -0
  108. data/vendor/nginx/src/http/modules/ngx_http_auth_basic_module.c +1 -1
  109. data/vendor/nginx/src/http/modules/ngx_http_auth_request_module.c +2 -2
  110. data/vendor/nginx/src/http/modules/ngx_http_chunked_filter_module.c +2 -2
  111. data/vendor/nginx/src/http/modules/ngx_http_dav_module.c +6 -6
  112. data/vendor/nginx/src/http/modules/ngx_http_fastcgi_module.c +17 -11
  113. data/vendor/nginx/src/http/modules/ngx_http_gzip_filter_module.c +2 -2
  114. data/vendor/nginx/src/http/modules/ngx_http_headers_filter_module.c +9 -9
  115. data/vendor/nginx/src/http/modules/ngx_http_image_filter_module.c +2 -2
  116. data/vendor/nginx/src/http/modules/ngx_http_limit_conn_module.c +2 -2
  117. data/vendor/nginx/src/http/modules/ngx_http_limit_req_module.c +0 -7
  118. data/vendor/nginx/src/http/modules/ngx_http_map_module.c +6 -6
  119. data/vendor/nginx/src/http/modules/ngx_http_memcached_module.c +2 -1
  120. data/vendor/nginx/src/http/modules/ngx_http_mp4_module.c +13 -13
  121. data/vendor/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +2 -2
  122. data/vendor/nginx/src/http/modules/ngx_http_proxy_module.c +26 -21
  123. data/vendor/nginx/src/http/modules/ngx_http_random_index_module.c +1 -1
  124. data/vendor/nginx/src/http/modules/ngx_http_range_filter_module.c +26 -8
  125. data/vendor/nginx/src/http/modules/ngx_http_realip_module.c +73 -3
  126. data/vendor/nginx/src/http/modules/ngx_http_referer_module.c +1 -1
  127. data/vendor/nginx/src/http/modules/ngx_http_rewrite_module.c +6 -6
  128. data/vendor/nginx/src/http/modules/ngx_http_scgi_module.c +5 -3
  129. data/vendor/nginx/src/http/modules/ngx_http_slice_filter_module.c +526 -0
  130. data/vendor/nginx/src/http/modules/ngx_http_ssi_filter_module.c +7 -7
  131. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.c +19 -16
  132. data/vendor/nginx/src/http/modules/ngx_http_static_module.c +1 -1
  133. data/vendor/nginx/src/http/modules/ngx_http_stub_status_module.c +1 -1
  134. data/vendor/nginx/src/http/modules/ngx_http_sub_filter_module.c +373 -173
  135. data/vendor/nginx/src/http/modules/ngx_http_upstream_hash_module.c +72 -46
  136. data/vendor/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +18 -30
  137. data/vendor/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +50 -39
  138. data/vendor/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c +38 -129
  139. data/vendor/nginx/src/http/modules/ngx_http_upstream_zone_module.c +246 -0
  140. data/vendor/nginx/src/http/modules/ngx_http_uwsgi_module.c +6 -5
  141. data/vendor/nginx/src/http/modules/perl/nginx.xs +9 -9
  142. data/vendor/nginx/src/http/ngx_http.c +46 -43
  143. data/vendor/nginx/src/http/ngx_http.h +4 -9
  144. data/vendor/nginx/src/http/ngx_http_cache.h +4 -0
  145. data/vendor/nginx/src/http/ngx_http_copy_filter_module.c +13 -5
  146. data/vendor/nginx/src/http/ngx_http_core_module.c +92 -91
  147. data/vendor/nginx/src/http/ngx_http_core_module.h +12 -8
  148. data/vendor/nginx/src/http/ngx_http_file_cache.c +61 -10
  149. data/vendor/nginx/src/http/ngx_http_request.c +37 -50
  150. data/vendor/nginx/src/http/ngx_http_request.h +10 -15
  151. data/vendor/nginx/src/http/ngx_http_request_body.c +64 -88
  152. data/vendor/nginx/src/http/ngx_http_script.c +3 -3
  153. data/vendor/nginx/src/http/ngx_http_special_response.c +1 -4
  154. data/vendor/nginx/src/http/ngx_http_upstream.c +245 -109
  155. data/vendor/nginx/src/http/ngx_http_upstream.h +11 -5
  156. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.c +212 -65
  157. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.h +66 -5
  158. data/vendor/nginx/src/http/ngx_http_variables.c +28 -15
  159. data/vendor/nginx/src/http/ngx_http_write_filter_module.c +1 -1
  160. data/vendor/nginx/src/http/v2/ngx_http_v2.c +4349 -0
  161. data/vendor/nginx/src/http/v2/ngx_http_v2.h +337 -0
  162. data/vendor/nginx/src/http/v2/ngx_http_v2_filter_module.c +1391 -0
  163. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_decode.c +2714 -0
  164. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_encode.c +254 -0
  165. data/vendor/nginx/src/http/v2/ngx_http_v2_module.c +469 -0
  166. data/vendor/nginx/src/http/{ngx_http_spdy_module.h → v2/ngx_http_v2_module.h} +10 -9
  167. data/vendor/nginx/src/http/v2/ngx_http_v2_table.c +349 -0
  168. data/vendor/nginx/src/mail/ngx_mail.c +49 -82
  169. data/vendor/nginx/src/mail/ngx_mail.h +16 -23
  170. data/vendor/nginx/src/mail/ngx_mail_auth_http_module.c +1 -1
  171. data/vendor/nginx/src/mail/ngx_mail_core_module.c +60 -34
  172. data/vendor/nginx/src/mail/ngx_mail_handler.c +17 -12
  173. data/vendor/nginx/src/mail/ngx_mail_proxy_module.c +1 -14
  174. data/vendor/nginx/src/mail/ngx_mail_smtp_handler.c +1 -1
  175. data/vendor/nginx/src/mail/ngx_mail_ssl_module.c +5 -5
  176. data/vendor/nginx/src/os/unix/ngx_atomic.h +10 -10
  177. data/vendor/nginx/src/os/unix/ngx_channel.h +4 -4
  178. data/vendor/nginx/src/os/unix/ngx_darwin_config.h +2 -0
  179. data/vendor/nginx/src/os/unix/ngx_darwin_init.c +1 -0
  180. data/vendor/nginx/src/os/unix/ngx_dlopen.c +28 -0
  181. data/vendor/nginx/src/os/unix/ngx_dlopen.h +31 -0
  182. data/vendor/nginx/src/os/unix/ngx_errno.h +1 -0
  183. data/vendor/nginx/src/os/unix/ngx_file_aio_read.c +1 -1
  184. data/vendor/nginx/src/os/unix/ngx_files.c +313 -80
  185. data/vendor/nginx/src/os/unix/ngx_files.h +5 -2
  186. data/vendor/nginx/src/os/unix/ngx_freebsd_config.h +3 -1
  187. data/vendor/nginx/src/os/unix/ngx_freebsd_init.c +1 -0
  188. data/vendor/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +13 -0
  189. data/vendor/nginx/src/os/unix/ngx_linux.h +0 -2
  190. data/vendor/nginx/src/os/unix/ngx_linux_aio_read.c +1 -1
  191. data/vendor/nginx/src/os/unix/ngx_linux_config.h +2 -6
  192. data/vendor/nginx/src/os/unix/ngx_linux_init.c +1 -33
  193. data/vendor/nginx/src/os/unix/ngx_linux_sendfile_chain.c +55 -12
  194. data/vendor/nginx/src/os/unix/ngx_os.h +3 -9
  195. data/vendor/nginx/src/os/unix/ngx_posix_config.h +14 -1
  196. data/vendor/nginx/src/os/unix/ngx_posix_init.c +2 -1
  197. data/vendor/nginx/src/os/unix/ngx_process.c +1 -1
  198. data/vendor/nginx/src/os/unix/ngx_process_cycle.c +25 -51
  199. data/vendor/nginx/src/os/unix/ngx_process_cycle.h +1 -0
  200. data/vendor/nginx/src/os/unix/ngx_readv_chain.c +24 -28
  201. data/vendor/nginx/src/os/unix/ngx_recv.c +30 -79
  202. data/vendor/nginx/src/os/unix/ngx_send.c +1 -1
  203. data/vendor/nginx/src/os/unix/ngx_setaffinity.c +14 -30
  204. data/vendor/nginx/src/os/unix/ngx_setaffinity.h +15 -1
  205. data/vendor/nginx/src/os/unix/ngx_solaris_config.h +2 -0
  206. data/vendor/nginx/src/os/unix/ngx_solaris_init.c +1 -0
  207. data/vendor/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +23 -0
  208. data/vendor/nginx/src/os/unix/ngx_sunpro_amd64.il +3 -3
  209. data/vendor/nginx/src/os/unix/ngx_sunpro_x86.il +3 -3
  210. data/vendor/nginx/src/os/unix/ngx_udp_recv.c +5 -48
  211. data/vendor/nginx/src/os/unix/ngx_udp_send.c +56 -0
  212. data/vendor/nginx/src/stream/ngx_stream.c +564 -0
  213. data/vendor/nginx/src/stream/ngx_stream.h +212 -0
  214. data/vendor/nginx/src/stream/ngx_stream_access_module.c +451 -0
  215. data/vendor/nginx/src/stream/ngx_stream_core_module.c +562 -0
  216. data/vendor/nginx/src/stream/ngx_stream_handler.c +344 -0
  217. data/vendor/nginx/src/stream/ngx_stream_limit_conn_module.c +632 -0
  218. data/vendor/nginx/src/stream/ngx_stream_proxy_module.c +1674 -0
  219. data/vendor/nginx/src/stream/ngx_stream_ssl_module.c +460 -0
  220. data/vendor/nginx/src/stream/ngx_stream_ssl_module.h +49 -0
  221. data/vendor/nginx/src/stream/ngx_stream_upstream.c +464 -0
  222. data/vendor/nginx/src/stream/ngx_stream_upstream.h +107 -0
  223. data/vendor/nginx/src/stream/ngx_stream_upstream_hash_module.c +656 -0
  224. data/vendor/nginx/src/stream/ngx_stream_upstream_least_conn_module.c +307 -0
  225. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.c +702 -0
  226. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.h +139 -0
  227. data/vendor/nginx/src/stream/ngx_stream_upstream_zone_module.c +242 -0
  228. metadata +39 -15
  229. data/vendor/nginx/src/event/modules/ngx_aio_module.c +0 -171
  230. data/vendor/nginx/src/event/modules/ngx_rtsig_module.c +0 -735
  231. data/vendor/nginx/src/http/ngx_http_spdy.c +0 -3701
  232. data/vendor/nginx/src/http/ngx_http_spdy.h +0 -261
  233. data/vendor/nginx/src/http/ngx_http_spdy_filter_module.c +0 -1222
  234. data/vendor/nginx/src/http/ngx_http_spdy_module.c +0 -408
  235. data/vendor/nginx/src/os/unix/ngx_aio_read.c +0 -109
  236. data/vendor/nginx/src/os/unix/ngx_aio_read_chain.c +0 -78
  237. data/vendor/nginx/src/os/unix/ngx_aio_write.c +0 -109
  238. data/vendor/nginx/src/os/unix/ngx_aio_write_chain.c +0 -100
@@ -10,29 +10,10 @@
10
10
  #include <ngx_http.h>
11
11
 
12
12
 
13
- typedef struct {
14
- ngx_uint_t *conns;
15
- } ngx_http_upstream_least_conn_conf_t;
16
-
17
-
18
- typedef struct {
19
- /* the round robin data must be first */
20
- ngx_http_upstream_rr_peer_data_t rrp;
21
-
22
- ngx_uint_t *conns;
23
-
24
- ngx_event_get_peer_pt get_rr_peer;
25
- ngx_event_free_peer_pt free_rr_peer;
26
- } ngx_http_upstream_lc_peer_data_t;
27
-
28
-
29
13
  static ngx_int_t ngx_http_upstream_init_least_conn_peer(ngx_http_request_t *r,
30
14
  ngx_http_upstream_srv_conf_t *us);
31
15
  static ngx_int_t ngx_http_upstream_get_least_conn_peer(
32
16
  ngx_peer_connection_t *pc, void *data);
33
- static void ngx_http_upstream_free_least_conn_peer(ngx_peer_connection_t *pc,
34
- void *data, ngx_uint_t state);
35
- static void *ngx_http_upstream_least_conn_create_conf(ngx_conf_t *cf);
36
17
  static char *ngx_http_upstream_least_conn(ngx_conf_t *cf, ngx_command_t *cmd,
37
18
  void *conf);
38
19
 
@@ -57,7 +38,7 @@ static ngx_http_module_t ngx_http_upstream_least_conn_module_ctx = {
57
38
  NULL, /* create main configuration */
58
39
  NULL, /* init main configuration */
59
40
 
60
- ngx_http_upstream_least_conn_create_conf, /* create server configuration */
41
+ NULL, /* create server configuration */
61
42
  NULL, /* merge server configuration */
62
43
 
63
44
  NULL, /* create location configuration */
@@ -85,10 +66,6 @@ static ngx_int_t
85
66
  ngx_http_upstream_init_least_conn(ngx_conf_t *cf,
86
67
  ngx_http_upstream_srv_conf_t *us)
87
68
  {
88
- ngx_uint_t n;
89
- ngx_http_upstream_rr_peers_t *peers;
90
- ngx_http_upstream_least_conn_conf_t *lcf;
91
-
92
69
  ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0,
93
70
  "init least conn");
94
71
 
@@ -96,22 +73,6 @@ ngx_http_upstream_init_least_conn(ngx_conf_t *cf,
96
73
  return NGX_ERROR;
97
74
  }
98
75
 
99
- peers = us->peer.data;
100
-
101
- n = peers->number;
102
-
103
- if (peers->next) {
104
- n += peers->next->number;
105
- }
106
-
107
- lcf = ngx_http_conf_upstream_srv_conf(us,
108
- ngx_http_upstream_least_conn_module);
109
-
110
- lcf->conns = ngx_pcalloc(cf->pool, sizeof(ngx_uint_t) * n);
111
- if (lcf->conns == NULL) {
112
- return NGX_ERROR;
113
- }
114
-
115
76
  us->peer.init = ngx_http_upstream_init_least_conn_peer;
116
77
 
117
78
  return NGX_OK;
@@ -122,33 +83,14 @@ static ngx_int_t
122
83
  ngx_http_upstream_init_least_conn_peer(ngx_http_request_t *r,
123
84
  ngx_http_upstream_srv_conf_t *us)
124
85
  {
125
- ngx_http_upstream_lc_peer_data_t *lcp;
126
- ngx_http_upstream_least_conn_conf_t *lcf;
127
-
128
86
  ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
129
87
  "init least conn peer");
130
88
 
131
- lcf = ngx_http_conf_upstream_srv_conf(us,
132
- ngx_http_upstream_least_conn_module);
133
-
134
- lcp = ngx_palloc(r->pool, sizeof(ngx_http_upstream_lc_peer_data_t));
135
- if (lcp == NULL) {
136
- return NGX_ERROR;
137
- }
138
-
139
- lcp->conns = lcf->conns;
140
-
141
- r->upstream->peer.data = &lcp->rrp;
142
-
143
89
  if (ngx_http_upstream_init_round_robin_peer(r, us) != NGX_OK) {
144
90
  return NGX_ERROR;
145
91
  }
146
92
 
147
93
  r->upstream->peer.get = ngx_http_upstream_get_least_conn_peer;
148
- r->upstream->peer.free = ngx_http_upstream_free_least_conn_peer;
149
-
150
- lcp->get_rr_peer = ngx_http_upstream_get_round_robin_peer;
151
- lcp->free_rr_peer = ngx_http_upstream_free_round_robin_peer;
152
94
 
153
95
  return NGX_OK;
154
96
  }
@@ -157,7 +99,7 @@ ngx_http_upstream_init_least_conn_peer(ngx_http_request_t *r,
157
99
  static ngx_int_t
158
100
  ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
159
101
  {
160
- ngx_http_upstream_lc_peer_data_t *lcp = data;
102
+ ngx_http_upstream_rr_peer_data_t *rrp = data;
161
103
 
162
104
  time_t now;
163
105
  uintptr_t m;
@@ -169,8 +111,8 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
169
111
  ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
170
112
  "get least conn peer, try: %ui", pc->tries);
171
113
 
172
- if (lcp->rrp.peers->single) {
173
- return lcp->get_rr_peer(pc, &lcp->rrp);
114
+ if (rrp->peers->single) {
115
+ return ngx_http_upstream_get_round_robin_peer(pc, rrp);
174
116
  }
175
117
 
176
118
  pc->cached = 0;
@@ -178,7 +120,9 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
178
120
 
179
121
  now = ngx_time();
180
122
 
181
- peers = lcp->rrp.peers;
123
+ peers = rrp->peers;
124
+
125
+ ngx_http_upstream_rr_peers_wlock(peers);
182
126
 
183
127
  best = NULL;
184
128
  total = 0;
@@ -188,17 +132,18 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
188
132
  p = 0;
189
133
  #endif
190
134
 
191
- for (i = 0; i < peers->number; i++) {
135
+ for (peer = peers->peer, i = 0;
136
+ peer;
137
+ peer = peer->next, i++)
138
+ {
192
139
 
193
140
  n = i / (8 * sizeof(uintptr_t));
194
141
  m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t));
195
142
 
196
- if (lcp->rrp.tried[n] & m) {
143
+ if (rrp->tried[n] & m) {
197
144
  continue;
198
145
  }
199
146
 
200
- peer = &peers->peer[i];
201
-
202
147
  if (peer->down) {
203
148
  continue;
204
149
  }
@@ -217,15 +162,13 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
217
162
  */
218
163
 
219
164
  if (best == NULL
220
- || lcp->conns[i] * best->weight < lcp->conns[p] * peer->weight)
165
+ || peer->conns * best->weight < best->conns * peer->weight)
221
166
  {
222
167
  best = peer;
223
168
  many = 0;
224
169
  p = i;
225
170
 
226
- } else if (lcp->conns[i] * best->weight
227
- == lcp->conns[p] * peer->weight)
228
- {
171
+ } else if (peer->conns * best->weight == best->conns * peer->weight) {
229
172
  many = 1;
230
173
  }
231
174
  }
@@ -241,22 +184,22 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
241
184
  ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0,
242
185
  "get least conn peer, many");
243
186
 
244
- for (i = p; i < peers->number; i++) {
245
-
187
+ for (peer = best, i = p;
188
+ peer;
189
+ peer = peer->next, i++)
190
+ {
246
191
  n = i / (8 * sizeof(uintptr_t));
247
192
  m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t));
248
193
 
249
- if (lcp->rrp.tried[n] & m) {
194
+ if (rrp->tried[n] & m) {
250
195
  continue;
251
196
  }
252
197
 
253
- peer = &peers->peer[i];
254
-
255
198
  if (peer->down) {
256
199
  continue;
257
200
  }
258
201
 
259
- if (lcp->conns[i] * best->weight != lcp->conns[p] * peer->weight) {
202
+ if (peer->conns * best->weight != best->conns * peer->weight) {
260
203
  continue;
261
204
  }
262
205
 
@@ -291,13 +234,16 @@ ngx_http_upstream_get_least_conn_peer(ngx_peer_connection_t *pc, void *data)
291
234
  pc->socklen = best->socklen;
292
235
  pc->name = &best->name;
293
236
 
294
- lcp->rrp.current = p;
237
+ best->conns++;
238
+
239
+ rrp->current = best;
295
240
 
296
241
  n = p / (8 * sizeof(uintptr_t));
297
242
  m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t));
298
243
 
299
- lcp->rrp.tried[n] |= m;
300
- lcp->conns[p]++;
244
+ rrp->tried[n] |= m;
245
+
246
+ ngx_http_upstream_rr_peers_unlock(peers);
301
247
 
302
248
  return NGX_OK;
303
249
 
@@ -307,77 +253,40 @@ failed:
307
253
  ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0,
308
254
  "get least conn peer, backup servers");
309
255
 
310
- lcp->conns += peers->number;
311
-
312
- lcp->rrp.peers = peers->next;
256
+ rrp->peers = peers->next;
313
257
 
314
- n = (lcp->rrp.peers->number + (8 * sizeof(uintptr_t) - 1))
258
+ n = (rrp->peers->number + (8 * sizeof(uintptr_t) - 1))
315
259
  / (8 * sizeof(uintptr_t));
316
260
 
317
261
  for (i = 0; i < n; i++) {
318
- lcp->rrp.tried[i] = 0;
262
+ rrp->tried[i] = 0;
319
263
  }
320
264
 
321
- rc = ngx_http_upstream_get_least_conn_peer(pc, lcp);
265
+ ngx_http_upstream_rr_peers_unlock(peers);
266
+
267
+ rc = ngx_http_upstream_get_least_conn_peer(pc, rrp);
322
268
 
323
269
  if (rc != NGX_BUSY) {
324
270
  return rc;
325
271
  }
272
+
273
+ ngx_http_upstream_rr_peers_wlock(peers);
326
274
  }
327
275
 
328
276
  /* all peers failed, mark them as live for quick recovery */
329
277
 
330
- for (i = 0; i < peers->number; i++) {
331
- peers->peer[i].fails = 0;
278
+ for (peer = peers->peer; peer; peer = peer->next) {
279
+ peer->fails = 0;
332
280
  }
333
281
 
282
+ ngx_http_upstream_rr_peers_unlock(peers);
283
+
334
284
  pc->name = peers->name;
335
285
 
336
286
  return NGX_BUSY;
337
287
  }
338
288
 
339
289
 
340
- static void
341
- ngx_http_upstream_free_least_conn_peer(ngx_peer_connection_t *pc,
342
- void *data, ngx_uint_t state)
343
- {
344
- ngx_http_upstream_lc_peer_data_t *lcp = data;
345
-
346
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
347
- "free least conn peer %ui %ui", pc->tries, state);
348
-
349
- if (lcp->rrp.peers->single) {
350
- lcp->free_rr_peer(pc, &lcp->rrp, state);
351
- return;
352
- }
353
-
354
- lcp->conns[lcp->rrp.current]--;
355
-
356
- lcp->free_rr_peer(pc, &lcp->rrp, state);
357
- }
358
-
359
-
360
- static void *
361
- ngx_http_upstream_least_conn_create_conf(ngx_conf_t *cf)
362
- {
363
- ngx_http_upstream_least_conn_conf_t *conf;
364
-
365
- conf = ngx_pcalloc(cf->pool,
366
- sizeof(ngx_http_upstream_least_conn_conf_t));
367
- if (conf == NULL) {
368
- return NULL;
369
- }
370
-
371
- /*
372
- * set by ngx_pcalloc():
373
- *
374
- * conf->conns = NULL;
375
- */
376
-
377
- return conf;
378
- }
379
-
380
-
381
290
  static char *
382
291
  ngx_http_upstream_least_conn(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
383
292
  {
@@ -0,0 +1,246 @@
1
+
2
+ /*
3
+ * Copyright (C) Ruslan Ermilov
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #include <ngx_config.h>
9
+ #include <ngx_core.h>
10
+ #include <ngx_http.h>
11
+
12
+
13
+ static char *ngx_http_upstream_zone(ngx_conf_t *cf, ngx_command_t *cmd,
14
+ void *conf);
15
+ static ngx_int_t ngx_http_upstream_init_zone(ngx_shm_zone_t *shm_zone,
16
+ void *data);
17
+ static ngx_http_upstream_rr_peers_t *ngx_http_upstream_zone_copy_peers(
18
+ ngx_slab_pool_t *shpool, ngx_http_upstream_srv_conf_t *uscf);
19
+
20
+
21
+ static ngx_command_t ngx_http_upstream_zone_commands[] = {
22
+
23
+ { ngx_string("zone"),
24
+ NGX_HTTP_UPS_CONF|NGX_CONF_TAKE12,
25
+ ngx_http_upstream_zone,
26
+ 0,
27
+ 0,
28
+ NULL },
29
+
30
+ ngx_null_command
31
+ };
32
+
33
+
34
+ static ngx_http_module_t ngx_http_upstream_zone_module_ctx = {
35
+ NULL, /* preconfiguration */
36
+ NULL, /* postconfiguration */
37
+
38
+ NULL, /* create main configuration */
39
+ NULL, /* init main configuration */
40
+
41
+ NULL, /* create server configuration */
42
+ NULL, /* merge server configuration */
43
+
44
+ NULL, /* create location configuration */
45
+ NULL /* merge location configuration */
46
+ };
47
+
48
+
49
+ ngx_module_t ngx_http_upstream_zone_module = {
50
+ NGX_MODULE_V1,
51
+ &ngx_http_upstream_zone_module_ctx, /* module context */
52
+ ngx_http_upstream_zone_commands, /* module directives */
53
+ NGX_HTTP_MODULE, /* module type */
54
+ NULL, /* init master */
55
+ NULL, /* init module */
56
+ NULL, /* init process */
57
+ NULL, /* init thread */
58
+ NULL, /* exit thread */
59
+ NULL, /* exit process */
60
+ NULL, /* exit master */
61
+ NGX_MODULE_V1_PADDING
62
+ };
63
+
64
+
65
+ static char *
66
+ ngx_http_upstream_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
67
+ {
68
+ ssize_t size;
69
+ ngx_str_t *value;
70
+ ngx_http_upstream_srv_conf_t *uscf;
71
+ ngx_http_upstream_main_conf_t *umcf;
72
+
73
+ uscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module);
74
+ umcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_upstream_module);
75
+
76
+ value = cf->args->elts;
77
+
78
+ if (!value[1].len) {
79
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
80
+ "invalid zone name \"%V\"", &value[1]);
81
+ return NGX_CONF_ERROR;
82
+ }
83
+
84
+ if (cf->args->nelts == 3) {
85
+ size = ngx_parse_size(&value[2]);
86
+
87
+ if (size == NGX_ERROR) {
88
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
89
+ "invalid zone size \"%V\"", &value[2]);
90
+ return NGX_CONF_ERROR;
91
+ }
92
+
93
+ if (size < (ssize_t) (8 * ngx_pagesize)) {
94
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
95
+ "zone \"%V\" is too small", &value[1]);
96
+ return NGX_CONF_ERROR;
97
+ }
98
+
99
+ } else {
100
+ size = 0;
101
+ }
102
+
103
+ uscf->shm_zone = ngx_shared_memory_add(cf, &value[1], size,
104
+ &ngx_http_upstream_module);
105
+ if (uscf->shm_zone == NULL) {
106
+ return NGX_CONF_ERROR;
107
+ }
108
+
109
+ uscf->shm_zone->init = ngx_http_upstream_init_zone;
110
+ uscf->shm_zone->data = umcf;
111
+
112
+ uscf->shm_zone->noreuse = 1;
113
+
114
+ return NGX_CONF_OK;
115
+ }
116
+
117
+
118
+ static ngx_int_t
119
+ ngx_http_upstream_init_zone(ngx_shm_zone_t *shm_zone, void *data)
120
+ {
121
+ size_t len;
122
+ ngx_uint_t i;
123
+ ngx_slab_pool_t *shpool;
124
+ ngx_http_upstream_rr_peers_t *peers, **peersp;
125
+ ngx_http_upstream_srv_conf_t *uscf, **uscfp;
126
+ ngx_http_upstream_main_conf_t *umcf;
127
+
128
+ shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
129
+ umcf = shm_zone->data;
130
+ uscfp = umcf->upstreams.elts;
131
+
132
+ if (shm_zone->shm.exists) {
133
+ peers = shpool->data;
134
+
135
+ for (i = 0; i < umcf->upstreams.nelts; i++) {
136
+ uscf = uscfp[i];
137
+
138
+ if (uscf->shm_zone != shm_zone) {
139
+ continue;
140
+ }
141
+
142
+ uscf->peer.data = peers;
143
+ peers = peers->zone_next;
144
+ }
145
+
146
+ return NGX_OK;
147
+ }
148
+
149
+ len = sizeof(" in upstream zone \"\"") + shm_zone->shm.name.len;
150
+
151
+ shpool->log_ctx = ngx_slab_alloc(shpool, len);
152
+ if (shpool->log_ctx == NULL) {
153
+ return NGX_ERROR;
154
+ }
155
+
156
+ ngx_sprintf(shpool->log_ctx, " in upstream zone \"%V\"%Z",
157
+ &shm_zone->shm.name);
158
+
159
+
160
+ /* copy peers to shared memory */
161
+
162
+ peersp = (ngx_http_upstream_rr_peers_t **) (void *) &shpool->data;
163
+
164
+ for (i = 0; i < umcf->upstreams.nelts; i++) {
165
+ uscf = uscfp[i];
166
+
167
+ if (uscf->shm_zone != shm_zone) {
168
+ continue;
169
+ }
170
+
171
+ peers = ngx_http_upstream_zone_copy_peers(shpool, uscf);
172
+ if (peers == NULL) {
173
+ return NGX_ERROR;
174
+ }
175
+
176
+ *peersp = peers;
177
+ peersp = &peers->zone_next;
178
+ }
179
+
180
+ return NGX_OK;
181
+ }
182
+
183
+
184
+ static ngx_http_upstream_rr_peers_t *
185
+ ngx_http_upstream_zone_copy_peers(ngx_slab_pool_t *shpool,
186
+ ngx_http_upstream_srv_conf_t *uscf)
187
+ {
188
+ ngx_http_upstream_rr_peer_t *peer, **peerp;
189
+ ngx_http_upstream_rr_peers_t *peers, *backup;
190
+
191
+ peers = ngx_slab_alloc(shpool, sizeof(ngx_http_upstream_rr_peers_t));
192
+ if (peers == NULL) {
193
+ return NULL;
194
+ }
195
+
196
+ ngx_memcpy(peers, uscf->peer.data, sizeof(ngx_http_upstream_rr_peers_t));
197
+
198
+ peers->shpool = shpool;
199
+
200
+ for (peerp = &peers->peer; *peerp; peerp = &peer->next) {
201
+ /* pool is unlocked */
202
+ peer = ngx_slab_calloc_locked(shpool,
203
+ sizeof(ngx_http_upstream_rr_peer_t));
204
+ if (peer == NULL) {
205
+ return NULL;
206
+ }
207
+
208
+ ngx_memcpy(peer, *peerp, sizeof(ngx_http_upstream_rr_peer_t));
209
+
210
+ *peerp = peer;
211
+ }
212
+
213
+ if (peers->next == NULL) {
214
+ goto done;
215
+ }
216
+
217
+ backup = ngx_slab_alloc(shpool, sizeof(ngx_http_upstream_rr_peers_t));
218
+ if (backup == NULL) {
219
+ return NULL;
220
+ }
221
+
222
+ ngx_memcpy(backup, peers->next, sizeof(ngx_http_upstream_rr_peers_t));
223
+
224
+ backup->shpool = shpool;
225
+
226
+ for (peerp = &backup->peer; *peerp; peerp = &peer->next) {
227
+ /* pool is unlocked */
228
+ peer = ngx_slab_calloc_locked(shpool,
229
+ sizeof(ngx_http_upstream_rr_peer_t));
230
+ if (peer == NULL) {
231
+ return NULL;
232
+ }
233
+
234
+ ngx_memcpy(peer, *peerp, sizeof(ngx_http_upstream_rr_peer_t));
235
+
236
+ *peerp = peer;
237
+ }
238
+
239
+ peers->next = backup;
240
+
241
+ done:
242
+
243
+ uscf->peer.data = peers;
244
+
245
+ return peers;
246
+ }