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
@@ -170,13 +170,16 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
170
170
  uint32_t hash;
171
171
  ngx_int_t w;
172
172
  uintptr_t m;
173
- ngx_uint_t i, n, p;
173
+ ngx_uint_t n, p;
174
174
  ngx_http_upstream_rr_peer_t *peer;
175
175
 
176
176
  ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
177
177
  "get hash peer, try: %ui", pc->tries);
178
178
 
179
+ ngx_http_upstream_rr_peers_wlock(hp->rrp.peers);
180
+
179
181
  if (hp->tries > 20 || hp->rrp.peers->single) {
182
+ ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
180
183
  return hp->get_rr_peer(pc, &hp->rrp);
181
184
  }
182
185
 
@@ -208,20 +211,14 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
208
211
  hp->hash += hash;
209
212
  hp->rehash++;
210
213
 
211
- if (!hp->rrp.peers->weighted) {
212
- p = hp->hash % hp->rrp.peers->number;
213
-
214
- } else {
215
- w = hp->hash % hp->rrp.peers->total_weight;
216
-
217
- for (i = 0; i < hp->rrp.peers->number; i++) {
218
- w -= hp->rrp.peers->peer[i].weight;
219
- if (w < 0) {
220
- break;
221
- }
222
- }
214
+ w = hp->hash % hp->rrp.peers->total_weight;
215
+ peer = hp->rrp.peers->peer;
216
+ p = 0;
223
217
 
224
- p = i;
218
+ while (w >= peer->weight) {
219
+ w -= peer->weight;
220
+ peer = peer->next;
221
+ p++;
225
222
  }
226
223
 
227
224
  n = p / (8 * sizeof(uintptr_t));
@@ -234,8 +231,6 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
234
231
  ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
235
232
  "get hash peer, value:%uD, peer:%ui", hp->hash, p);
236
233
 
237
- peer = &hp->rrp.peers->peer[p];
238
-
239
234
  if (peer->down) {
240
235
  goto next;
241
236
  }
@@ -252,20 +247,25 @@ ngx_http_upstream_get_hash_peer(ngx_peer_connection_t *pc, void *data)
252
247
  next:
253
248
 
254
249
  if (++hp->tries > 20) {
250
+ ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
255
251
  return hp->get_rr_peer(pc, &hp->rrp);
256
252
  }
257
253
  }
258
254
 
259
- hp->rrp.current = p;
255
+ hp->rrp.current = peer;
260
256
 
261
257
  pc->sockaddr = peer->sockaddr;
262
258
  pc->socklen = peer->socklen;
263
259
  pc->name = &peer->name;
264
260
 
261
+ peer->conns++;
262
+
265
263
  if (now - peer->checked > peer->fail_timeout) {
266
264
  peer->checked = now;
267
265
  }
268
266
 
267
+ ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
268
+
269
269
  hp->rrp.tried[n] |= m;
270
270
 
271
271
  return NGX_OK;
@@ -277,13 +277,17 @@ ngx_http_upstream_init_chash(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *us)
277
277
  {
278
278
  u_char *host, *port, c;
279
279
  size_t host_len, port_len, size;
280
- uint32_t hash, base_hash, prev_hash;
280
+ uint32_t hash, base_hash;
281
281
  ngx_str_t *server;
282
282
  ngx_uint_t npoints, i, j;
283
283
  ngx_http_upstream_rr_peer_t *peer;
284
284
  ngx_http_upstream_rr_peers_t *peers;
285
285
  ngx_http_upstream_chash_points_t *points;
286
286
  ngx_http_upstream_hash_srv_conf_t *hcf;
287
+ union {
288
+ uint32_t value;
289
+ u_char byte[4];
290
+ } prev_hash;
287
291
 
288
292
  if (ngx_http_upstream_init_round_robin(cf, us) != NGX_OK) {
289
293
  return NGX_ERROR;
@@ -304,8 +308,7 @@ ngx_http_upstream_init_chash(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *us)
304
308
 
305
309
  points->number = 0;
306
310
 
307
- for (i = 0; i < peers->number; i++) {
308
- peer = &peers->peer[i];
311
+ for (peer = peers->peer; peer; peer = peer->next) {
309
312
  server = &peer->server;
310
313
 
311
314
  /*
@@ -351,20 +354,27 @@ ngx_http_upstream_init_chash(ngx_conf_t *cf, ngx_http_upstream_srv_conf_t *us)
351
354
  ngx_crc32_update(&base_hash, (u_char *) "", 1);
352
355
  ngx_crc32_update(&base_hash, port, port_len);
353
356
 
354
- prev_hash = 0;
357
+ prev_hash.value = 0;
355
358
  npoints = peer->weight * 160;
356
359
 
357
360
  for (j = 0; j < npoints; j++) {
358
361
  hash = base_hash;
359
362
 
360
- ngx_crc32_update(&hash, (u_char *) &prev_hash, sizeof(uint32_t));
363
+ ngx_crc32_update(&hash, prev_hash.byte, 4);
361
364
  ngx_crc32_final(hash);
362
365
 
363
366
  points->point[points->number].hash = hash;
364
367
  points->point[points->number].server = server;
365
368
  points->number++;
366
369
 
367
- prev_hash = hash;
370
+ #if (NGX_HAVE_LITTLE_ENDIAN)
371
+ prev_hash.value = hash;
372
+ #else
373
+ prev_hash.byte[0] = (u_char) (hash & 0xff);
374
+ prev_hash.byte[1] = (u_char) ((hash >> 8) & 0xff);
375
+ prev_hash.byte[2] = (u_char) ((hash >> 16) & 0xff);
376
+ prev_hash.byte[3] = (u_char) ((hash >> 24) & 0xff);
377
+ #endif
368
378
  }
369
379
  }
370
380
 
@@ -458,8 +468,13 @@ ngx_http_upstream_init_chash_peer(ngx_http_request_t *r,
458
468
  hcf = ngx_http_conf_upstream_srv_conf(us, ngx_http_upstream_hash_module);
459
469
 
460
470
  hash = ngx_crc32_long(hp->key.data, hp->key.len);
471
+
472
+ ngx_http_upstream_rr_peers_rlock(hp->rrp.peers);
473
+
461
474
  hp->hash = ngx_http_upstream_find_chash_point(hcf->points, hash);
462
475
 
476
+ ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
477
+
463
478
  return NGX_OK;
464
479
  }
465
480
 
@@ -473,7 +488,7 @@ ngx_http_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data)
473
488
  intptr_t m;
474
489
  ngx_str_t *server;
475
490
  ngx_int_t total;
476
- ngx_uint_t i, n;
491
+ ngx_uint_t i, n, best_i;
477
492
  ngx_http_upstream_rr_peer_t *peer, *best;
478
493
  ngx_http_upstream_chash_point_t *point;
479
494
  ngx_http_upstream_chash_points_t *points;
@@ -482,6 +497,8 @@ ngx_http_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data)
482
497
  ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
483
498
  "get consistent hash peer, try: %ui", pc->tries);
484
499
 
500
+ ngx_http_upstream_rr_peers_wlock(hp->rrp.peers);
501
+
485
502
  pc->cached = 0;
486
503
  pc->connection = NULL;
487
504
 
@@ -499,9 +516,13 @@ ngx_http_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data)
499
516
  hp->hash, server);
500
517
 
501
518
  best = NULL;
519
+ best_i = 0;
502
520
  total = 0;
503
521
 
504
- for (i = 0; i < hp->rrp.peers->number; i++) {
522
+ for (peer = hp->rrp.peers->peer, i = 0;
523
+ peer;
524
+ peer = peer->next, i++)
525
+ {
505
526
 
506
527
  n = i / (8 * sizeof(uintptr_t));
507
528
  m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t));
@@ -510,8 +531,6 @@ ngx_http_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data)
510
531
  continue;
511
532
  }
512
533
 
513
- peer = &hp->rrp.peers->peer[i];
514
-
515
534
  if (peer->down) {
516
535
  continue;
517
536
  }
@@ -539,39 +558,46 @@ ngx_http_upstream_get_chash_peer(ngx_peer_connection_t *pc, void *data)
539
558
 
540
559
  if (best == NULL || peer->current_weight > best->current_weight) {
541
560
  best = peer;
561
+ best_i = i;
542
562
  }
543
563
  }
544
564
 
545
565
  if (best) {
546
566
  best->current_weight -= total;
547
-
548
- i = best - &hp->rrp.peers->peer[0];
549
-
550
- hp->rrp.current = i;
551
-
552
- n = i / (8 * sizeof(uintptr_t));
553
- m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t));
554
-
555
- hp->rrp.tried[n] |= m;
556
-
557
- if (now - best->checked > best->fail_timeout) {
558
- best->checked = now;
559
- }
560
-
561
- pc->sockaddr = best->sockaddr;
562
- pc->socklen = best->socklen;
563
- pc->name = &best->name;
564
-
565
- return NGX_OK;
567
+ goto found;
566
568
  }
567
569
 
568
570
  hp->hash++;
569
571
  hp->tries++;
570
572
 
571
573
  if (hp->tries >= points->number) {
574
+ ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
572
575
  return NGX_BUSY;
573
576
  }
574
577
  }
578
+
579
+ found:
580
+
581
+ hp->rrp.current = best;
582
+
583
+ pc->sockaddr = best->sockaddr;
584
+ pc->socklen = best->socklen;
585
+ pc->name = &best->name;
586
+
587
+ best->conns++;
588
+
589
+ if (now - best->checked > best->fail_timeout) {
590
+ best->checked = now;
591
+ }
592
+
593
+ ngx_http_upstream_rr_peers_unlock(hp->rrp.peers);
594
+
595
+ n = best_i / (8 * sizeof(uintptr_t));
596
+ m = (uintptr_t) 1 << best_i % (8 * sizeof(uintptr_t));
597
+
598
+ hp->rrp.tried[n] |= m;
599
+
600
+ return NGX_OK;
575
601
  }
576
602
 
577
603
 
@@ -161,7 +161,10 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
161
161
 
162
162
  /* TODO: cached */
163
163
 
164
+ ngx_http_upstream_rr_peers_wlock(iphp->rrp.peers);
165
+
164
166
  if (iphp->tries > 20 || iphp->rrp.peers->single) {
167
+ ngx_http_upstream_rr_peers_unlock(iphp->rrp.peers);
165
168
  return iphp->get_rr_peer(pc, &iphp->rrp);
166
169
  }
167
170
 
@@ -178,20 +181,14 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
178
181
  hash = (hash * 113 + iphp->addr[i]) % 6271;
179
182
  }
180
183
 
181
- if (!iphp->rrp.peers->weighted) {
182
- p = hash % iphp->rrp.peers->number;
183
-
184
- } else {
185
- w = hash % iphp->rrp.peers->total_weight;
186
-
187
- for (i = 0; i < iphp->rrp.peers->number; i++) {
188
- w -= iphp->rrp.peers->peer[i].weight;
189
- if (w < 0) {
190
- break;
191
- }
192
- }
184
+ w = hash % iphp->rrp.peers->total_weight;
185
+ peer = iphp->rrp.peers->peer;
186
+ p = 0;
193
187
 
194
- p = i;
188
+ while (w >= peer->weight) {
189
+ w -= peer->weight;
190
+ peer = peer->next;
191
+ p++;
195
192
  }
196
193
 
197
194
  n = p / (8 * sizeof(uintptr_t));
@@ -202,51 +199,42 @@ ngx_http_upstream_get_ip_hash_peer(ngx_peer_connection_t *pc, void *data)
202
199
  }
203
200
 
204
201
  ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
205
- "get ip hash peer, hash: %ui %04XA", p, m);
206
-
207
- peer = &iphp->rrp.peers->peer[p];
208
-
209
- /* ngx_lock_mutex(iphp->rrp.peers->mutex); */
202
+ "get ip hash peer, hash: %ui %04XL", p, (uint64_t) m);
210
203
 
211
204
  if (peer->down) {
212
- goto next_try;
205
+ goto next;
213
206
  }
214
207
 
215
208
  if (peer->max_fails
216
209
  && peer->fails >= peer->max_fails
217
210
  && now - peer->checked <= peer->fail_timeout)
218
211
  {
219
- goto next_try;
212
+ goto next;
220
213
  }
221
214
 
222
215
  break;
223
216
 
224
- next_try:
225
-
226
- iphp->rrp.tried[n] |= m;
227
-
228
- /* ngx_unlock_mutex(iphp->rrp.peers->mutex); */
229
-
230
- pc->tries--;
231
-
232
217
  next:
233
218
 
234
219
  if (++iphp->tries > 20) {
220
+ ngx_http_upstream_rr_peers_unlock(iphp->rrp.peers);
235
221
  return iphp->get_rr_peer(pc, &iphp->rrp);
236
222
  }
237
223
  }
238
224
 
239
- iphp->rrp.current = p;
225
+ iphp->rrp.current = peer;
240
226
 
241
227
  pc->sockaddr = peer->sockaddr;
242
228
  pc->socklen = peer->socklen;
243
229
  pc->name = &peer->name;
244
230
 
231
+ peer->conns++;
232
+
245
233
  if (now - peer->checked > peer->fail_timeout) {
246
234
  peer->checked = now;
247
235
  }
248
236
 
249
- /* ngx_unlock_mutex(iphp->rrp.peers->mutex); */
237
+ ngx_http_upstream_rr_peers_unlock(iphp->rrp.peers);
250
238
 
251
239
  iphp->rrp.tried[n] |= m;
252
240
  iphp->hash = hash;
@@ -22,6 +22,18 @@ typedef struct {
22
22
  } ngx_http_upstream_keepalive_srv_conf_t;
23
23
 
24
24
 
25
+ typedef struct {
26
+ ngx_http_upstream_keepalive_srv_conf_t *conf;
27
+
28
+ ngx_queue_t queue;
29
+ ngx_connection_t *connection;
30
+
31
+ socklen_t socklen;
32
+ u_char sockaddr[NGX_SOCKADDRLEN];
33
+
34
+ } ngx_http_upstream_keepalive_cache_t;
35
+
36
+
25
37
  typedef struct {
26
38
  ngx_http_upstream_keepalive_srv_conf_t *conf;
27
39
 
@@ -40,18 +52,6 @@ typedef struct {
40
52
  } ngx_http_upstream_keepalive_peer_data_t;
41
53
 
42
54
 
43
- typedef struct {
44
- ngx_http_upstream_keepalive_srv_conf_t *conf;
45
-
46
- ngx_queue_t queue;
47
- ngx_connection_t *connection;
48
-
49
- socklen_t socklen;
50
- u_char sockaddr[NGX_SOCKADDRLEN];
51
-
52
- } ngx_http_upstream_keepalive_cache_t;
53
-
54
-
55
55
  static ngx_int_t ngx_http_upstream_init_keepalive_peer(ngx_http_request_t *r,
56
56
  ngx_http_upstream_srv_conf_t *us);
57
57
  static ngx_int_t ngx_http_upstream_get_keepalive_peer(ngx_peer_connection_t *pc,
@@ -63,7 +63,6 @@ static void ngx_http_upstream_keepalive_dummy_handler(ngx_event_t *ev);
63
63
  static void ngx_http_upstream_keepalive_close_handler(ngx_event_t *ev);
64
64
  static void ngx_http_upstream_keepalive_close(ngx_connection_t *c);
65
65
 
66
-
67
66
  #if (NGX_HTTP_SSL)
68
67
  static ngx_int_t ngx_http_upstream_keepalive_set_session(
69
68
  ngx_peer_connection_t *pc, void *data);
@@ -244,24 +243,28 @@ ngx_http_upstream_get_keepalive_peer(ngx_peer_connection_t *pc, void *data)
244
243
  ngx_queue_remove(q);
245
244
  ngx_queue_insert_head(&kp->conf->free, q);
246
245
 
247
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
248
- "get keepalive peer: using connection %p", c);
249
-
250
- c->idle = 0;
251
- c->sent = 0;
252
- c->log = pc->log;
253
- c->read->log = pc->log;
254
- c->write->log = pc->log;
255
- c->pool->log = pc->log;
256
-
257
- pc->connection = c;
258
- pc->cached = 1;
259
-
260
- return NGX_DONE;
246
+ goto found;
261
247
  }
262
248
  }
263
249
 
264
250
  return NGX_OK;
251
+
252
+ found:
253
+
254
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
255
+ "get keepalive peer: using connection %p", c);
256
+
257
+ c->idle = 0;
258
+ c->sent = 0;
259
+ c->log = pc->log;
260
+ c->read->log = pc->log;
261
+ c->write->log = pc->log;
262
+ c->pool->log = pc->log;
263
+
264
+ pc->connection = c;
265
+ pc->cached = 1;
266
+
267
+ return NGX_DONE;
265
268
  }
266
269
 
267
270
 
@@ -299,6 +302,14 @@ ngx_http_upstream_free_keepalive_peer(ngx_peer_connection_t *pc, void *data,
299
302
  goto invalid;
300
303
  }
301
304
 
305
+ if (!u->request_body_sent) {
306
+ goto invalid;
307
+ }
308
+
309
+ if (ngx_terminate || ngx_exiting) {
310
+ goto invalid;
311
+ }
312
+
302
313
  if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
303
314
  goto invalid;
304
315
  }
@@ -322,9 +333,10 @@ ngx_http_upstream_free_keepalive_peer(ngx_peer_connection_t *pc, void *data,
322
333
  item = ngx_queue_data(q, ngx_http_upstream_keepalive_cache_t, queue);
323
334
  }
324
335
 
325
- item->connection = c;
326
336
  ngx_queue_insert_head(&kp->conf->cache, q);
327
337
 
338
+ item->connection = c;
339
+
328
340
  pc->connection = NULL;
329
341
 
330
342
  if (c->read->timer_set) {
@@ -470,10 +482,9 @@ ngx_http_upstream_keepalive_create_conf(ngx_conf_t *cf)
470
482
  *
471
483
  * conf->original_init_upstream = NULL;
472
484
  * conf->original_init_peer = NULL;
485
+ * conf->max_cached = 0;
473
486
  */
474
487
 
475
- conf->max_cached = 1;
476
-
477
488
  return conf;
478
489
  }
479
490
 
@@ -487,18 +498,10 @@ ngx_http_upstream_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
487
498
  ngx_int_t n;
488
499
  ngx_str_t *value;
489
500
 
490
- uscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module);
491
-
492
- if (kcf->original_init_upstream) {
501
+ if (kcf->max_cached) {
493
502
  return "is duplicate";
494
503
  }
495
504
 
496
- kcf->original_init_upstream = uscf->peer.init_upstream
497
- ? uscf->peer.init_upstream
498
- : ngx_http_upstream_init_round_robin;
499
-
500
- uscf->peer.init_upstream = ngx_http_upstream_init_keepalive;
501
-
502
505
  /* read options */
503
506
 
504
507
  value = cf->args->elts;
@@ -514,5 +517,13 @@ ngx_http_upstream_keepalive(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
514
517
 
515
518
  kcf->max_cached = n;
516
519
 
520
+ uscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module);
521
+
522
+ kcf->original_init_upstream = uscf->peer.init_upstream
523
+ ? uscf->peer.init_upstream
524
+ : ngx_http_upstream_init_round_robin;
525
+
526
+ uscf->peer.init_upstream = ngx_http_upstream_init_keepalive;
527
+
517
528
  return NGX_CONF_OK;
518
529
  }