nginxtra 1.0.15.0 → 1.2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/VERSION +1 -1
  2. data/bin/nginxtra +1 -1
  3. data/lib/nginxtra/action.rb +10 -0
  4. data/lib/nginxtra/actions/compile.rb +16 -2
  5. data/lib/nginxtra/actions/start.rb +18 -2
  6. data/lib/nginxtra/actions/status.rb +1 -10
  7. data/lib/nginxtra/actions/stop.rb +18 -0
  8. data/lib/nginxtra/cli.rb +12 -3
  9. data/lib/nginxtra/config.rb +10 -0
  10. data/src/nginx/CHANGES +311 -90
  11. data/src/nginx/CHANGES.ru +315 -88
  12. data/src/nginx/auto/lib/pcre/conf +22 -5
  13. data/src/nginx/auto/lib/pcre/make +1 -1
  14. data/src/nginx/auto/modules +14 -3
  15. data/src/nginx/auto/options +17 -3
  16. data/src/nginx/auto/os/freebsd +8 -0
  17. data/src/nginx/auto/os/linux +5 -4
  18. data/src/nginx/auto/os/solaris +2 -1
  19. data/src/nginx/auto/sources +10 -2
  20. data/src/nginx/auto/summary +2 -0
  21. data/src/nginx/auto/types/sizeof +2 -1
  22. data/src/nginx/auto/types/typedef +1 -1
  23. data/src/nginx/auto/types/uintptr_t +7 -4
  24. data/src/nginx/auto/unix +82 -21
  25. data/src/nginx/conf/fastcgi.conf +1 -0
  26. data/src/nginx/conf/fastcgi_params +1 -0
  27. data/src/nginx/conf/scgi_params +1 -0
  28. data/src/nginx/conf/uwsgi_params +1 -0
  29. data/src/nginx/man/nginx.8 +49 -49
  30. data/src/nginx/src/core/nginx.c +10 -12
  31. data/src/nginx/src/core/nginx.h +2 -2
  32. data/src/nginx/src/core/ngx_buf.c +9 -7
  33. data/src/nginx/src/core/ngx_buf.h +2 -2
  34. data/src/nginx/src/core/ngx_conf_file.c +4 -11
  35. data/src/nginx/src/core/ngx_conf_file.h +1 -1
  36. data/src/nginx/src/core/ngx_connection.c +52 -1
  37. data/src/nginx/src/core/ngx_connection.h +6 -0
  38. data/src/nginx/src/core/ngx_core.h +5 -0
  39. data/src/nginx/src/core/ngx_cycle.c +1 -1
  40. data/src/nginx/src/core/ngx_cycle.h +2 -2
  41. data/src/nginx/src/core/ngx_file.c +1 -1
  42. data/src/nginx/src/core/ngx_inet.c +11 -8
  43. data/src/nginx/src/core/ngx_murmurhash.h +1 -1
  44. data/src/nginx/src/core/ngx_open_file_cache.c +343 -38
  45. data/src/nginx/src/core/ngx_open_file_cache.h +10 -0
  46. data/src/nginx/src/core/ngx_output_chain.c +2 -1
  47. data/src/nginx/src/core/ngx_parse.h +0 -3
  48. data/src/nginx/src/core/ngx_rbtree.c +1 -2
  49. data/src/nginx/src/core/ngx_regex.c +263 -5
  50. data/src/nginx/src/core/ngx_regex.h +6 -2
  51. data/src/nginx/src/core/ngx_resolver.c +88 -21
  52. data/src/nginx/src/core/ngx_resolver.h +7 -8
  53. data/src/nginx/src/core/ngx_shmtx.c +69 -44
  54. data/src/nginx/src/core/ngx_shmtx.h +12 -1
  55. data/src/nginx/src/core/ngx_slab.c +3 -3
  56. data/src/nginx/src/core/ngx_slab.h +1 -1
  57. data/src/nginx/src/core/ngx_string.c +19 -16
  58. data/src/nginx/src/core/ngx_times.c +2 -2
  59. data/src/nginx/src/event/modules/ngx_epoll_module.c +2 -2
  60. data/src/nginx/src/event/modules/ngx_eventport_module.c +1 -1
  61. data/src/nginx/src/event/modules/ngx_kqueue_module.c +1 -1
  62. data/src/nginx/src/event/ngx_event.c +25 -17
  63. data/src/nginx/src/event/ngx_event_openssl.c +3 -1
  64. data/src/nginx/src/event/ngx_event_pipe.c +108 -85
  65. data/src/nginx/src/event/ngx_event_pipe.h +1 -2
  66. data/src/nginx/src/event/ngx_event_timer.c +2 -3
  67. data/src/nginx/src/http/modules/ngx_http_access_module.c +9 -4
  68. data/src/nginx/src/http/modules/ngx_http_browser_module.c +5 -3
  69. data/src/nginx/src/http/modules/ngx_http_chunked_filter_module.c +1 -1
  70. data/src/nginx/src/http/modules/ngx_http_degradation_module.c +1 -1
  71. data/src/nginx/src/http/modules/ngx_http_fastcgi_module.c +144 -22
  72. data/src/nginx/src/http/modules/ngx_http_flv_module.c +8 -0
  73. data/src/nginx/src/http/modules/ngx_http_geo_module.c +3 -3
  74. data/src/nginx/src/http/modules/ngx_http_gzip_filter_module.c +20 -6
  75. data/src/nginx/src/http/modules/ngx_http_gzip_static_module.c +8 -0
  76. data/src/nginx/src/http/modules/ngx_http_headers_filter_module.c +23 -27
  77. data/src/nginx/src/http/modules/ngx_http_image_filter_module.c +1 -3
  78. data/src/nginx/src/http/modules/ngx_http_index_module.c +24 -0
  79. data/src/nginx/src/http/modules/ngx_http_limit_conn_module.c +747 -0
  80. data/src/nginx/src/http/modules/ngx_http_limit_req_module.c +289 -133
  81. data/src/nginx/src/http/modules/ngx_http_log_module.c +34 -6
  82. data/src/nginx/src/http/modules/ngx_http_memcached_module.c +19 -3
  83. data/src/nginx/src/http/modules/ngx_http_mp4_module.c +8 -0
  84. data/src/nginx/src/http/modules/ngx_http_proxy_module.c +1446 -239
  85. data/src/nginx/src/http/modules/ngx_http_realip_module.c +4 -10
  86. data/src/nginx/src/http/modules/ngx_http_scgi_module.c +90 -21
  87. data/src/nginx/src/http/modules/ngx_http_split_clients_module.c +8 -11
  88. data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.c +16 -6
  89. data/src/nginx/src/http/modules/ngx_http_static_module.c +8 -0
  90. data/src/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +2 -2
  91. data/src/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +570 -0
  92. data/src/nginx/src/http/modules/ngx_http_userid_filter_module.c +1 -5
  93. data/src/nginx/src/http/modules/ngx_http_uwsgi_module.c +77 -26
  94. data/src/nginx/src/http/modules/ngx_http_xslt_filter_module.c +171 -37
  95. data/src/nginx/src/http/modules/perl/nginx.pm +2 -1
  96. data/src/nginx/src/http/modules/perl/nginx.xs +4 -0
  97. data/src/nginx/src/http/ngx_http.c +8 -1
  98. data/src/nginx/src/http/ngx_http.h +1 -0
  99. data/src/nginx/src/http/ngx_http_busy_lock.c +2 -2
  100. data/src/nginx/src/http/ngx_http_cache.h +12 -1
  101. data/src/nginx/src/http/ngx_http_copy_filter_module.c +4 -3
  102. data/src/nginx/src/http/ngx_http_core_module.c +303 -37
  103. data/src/nginx/src/http/ngx_http_core_module.h +15 -0
  104. data/src/nginx/src/http/ngx_http_file_cache.c +226 -52
  105. data/src/nginx/src/http/ngx_http_parse.c +69 -3
  106. data/src/nginx/src/http/ngx_http_postpone_filter_module.c +4 -4
  107. data/src/nginx/src/http/ngx_http_request.c +61 -27
  108. data/src/nginx/src/http/ngx_http_request.h +3 -3
  109. data/src/nginx/src/http/ngx_http_request_body.c +1 -1
  110. data/src/nginx/src/http/ngx_http_script.c +6 -0
  111. data/src/nginx/src/http/ngx_http_upstream.c +200 -47
  112. data/src/nginx/src/http/ngx_http_upstream.h +20 -1
  113. data/src/nginx/src/http/ngx_http_upstream_round_robin.c +22 -6
  114. data/src/nginx/src/http/ngx_http_upstream_round_robin.h +1 -0
  115. data/src/nginx/src/http/ngx_http_variables.c +123 -4
  116. data/src/nginx/src/mail/ngx_mail.c +13 -0
  117. data/src/nginx/src/mail/ngx_mail.h +12 -0
  118. data/src/nginx/src/mail/ngx_mail_core_module.c +100 -15
  119. data/src/nginx/src/os/unix/ngx_daemon.c +2 -1
  120. data/src/nginx/src/os/unix/ngx_darwin.h +3 -0
  121. data/src/nginx/src/os/unix/ngx_darwin_config.h +1 -0
  122. data/src/nginx/src/os/unix/ngx_darwin_init.c +30 -0
  123. data/src/nginx/src/os/unix/ngx_darwin_sendfile_chain.c +11 -5
  124. data/src/nginx/src/os/unix/ngx_errno.h +5 -0
  125. data/src/nginx/src/os/unix/ngx_files.h +50 -1
  126. data/src/nginx/src/os/unix/ngx_freebsd.h +2 -1
  127. data/src/nginx/src/os/unix/ngx_freebsd_config.h +2 -0
  128. data/src/nginx/src/os/unix/ngx_freebsd_init.c +4 -3
  129. data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.c +2 -2
  130. data/src/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +12 -6
  131. data/src/nginx/src/os/unix/ngx_gcc_atomic_sparc64.h +1 -1
  132. data/src/nginx/src/os/unix/ngx_linux_config.h +1 -0
  133. data/src/nginx/src/os/unix/ngx_linux_sendfile_chain.c +6 -4
  134. data/src/nginx/src/os/unix/ngx_os.h +0 -1
  135. data/src/nginx/src/os/unix/ngx_posix_config.h +3 -0
  136. data/src/nginx/src/os/unix/ngx_process.c +50 -11
  137. data/src/nginx/src/os/unix/ngx_process.h +1 -0
  138. data/src/nginx/src/os/unix/ngx_process_cycle.c +6 -15
  139. data/src/nginx/src/os/unix/ngx_readv_chain.c +8 -0
  140. data/src/nginx/src/os/unix/ngx_setaffinity.c +69 -0
  141. data/src/nginx/src/os/unix/ngx_setaffinity.h +23 -0
  142. data/src/nginx/src/os/unix/ngx_setproctitle.c +1 -1
  143. data/src/nginx/src/os/unix/ngx_solaris_config.h +2 -0
  144. data/src/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +11 -3
  145. data/src/nginx/src/os/unix/ngx_writev_chain.c +7 -3
  146. metadata +7 -4
  147. data/src/nginx/src/http/modules/ngx_http_limit_zone_module.c +0 -553
@@ -78,6 +78,7 @@ typedef struct {
78
78
  #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
79
79
  unsigned ipv6only:2;
80
80
  #endif
81
+ unsigned so_keepalive:2;
81
82
 
82
83
  int backlog;
83
84
  int rcvbuf;
@@ -85,6 +86,11 @@ typedef struct {
85
86
  #if (NGX_HAVE_SETFIB)
86
87
  int setfib;
87
88
  #endif
89
+ #if (NGX_HAVE_KEEPALIVE_TUNABLE)
90
+ int tcp_keepidle;
91
+ int tcp_keepintvl;
92
+ int tcp_keepcnt;
93
+ #endif
88
94
 
89
95
  #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
90
96
  char *accept_filter;
@@ -398,6 +404,11 @@ struct ngx_http_core_loc_conf_s {
398
404
  #endif
399
405
  #endif
400
406
 
407
+ #if (NGX_HAVE_OPENAT)
408
+ ngx_uint_t disable_symlinks; /* disable_symlinks */
409
+ ngx_http_complex_value_t *disable_symlinks_from;
410
+ #endif
411
+
401
412
  ngx_array_t *error_pages; /* error_page */
402
413
  ngx_http_try_file_t *try_files; /* try_files */
403
414
 
@@ -499,6 +510,10 @@ ngx_int_t ngx_http_output_filter(ngx_http_request_t *r, ngx_chain_t *chain);
499
510
  ngx_int_t ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *chain);
500
511
 
501
512
 
513
+ ngx_int_t ngx_http_set_disable_symlinks(ngx_http_request_t *r,
514
+ ngx_http_core_loc_conf_t *clcf, ngx_str_t *path, ngx_open_file_info_t *of);
515
+
516
+
502
517
  extern ngx_module_t ngx_http_core_module;
503
518
 
504
519
  extern ngx_uint_t ngx_http_max_module;
@@ -11,6 +11,9 @@
11
11
  #include <ngx_md5.h>
12
12
 
13
13
 
14
+ static ngx_int_t ngx_http_file_cache_lock(ngx_http_request_t *r,
15
+ ngx_http_cache_t *c);
16
+ static void ngx_http_file_cache_lock_wait_handler(ngx_event_t *ev);
14
17
  static ngx_int_t ngx_http_file_cache_read(ngx_http_request_t *r,
15
18
  ngx_http_cache_t *c);
16
19
  static ssize_t ngx_http_file_cache_aio_read(ngx_http_request_t *r,
@@ -31,8 +34,7 @@ static time_t ngx_http_file_cache_forced_expire(ngx_http_file_cache_t *cache);
31
34
  static time_t ngx_http_file_cache_expire(ngx_http_file_cache_t *cache);
32
35
  static void ngx_http_file_cache_delete(ngx_http_file_cache_t *cache,
33
36
  ngx_queue_t *q, u_char *name);
34
- static ngx_int_t
35
- ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache);
37
+ static void ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache);
36
38
  static ngx_int_t ngx_http_file_cache_noop(ngx_tree_ctx_t *ctx,
37
39
  ngx_str_t *path);
38
40
  static ngx_int_t ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx,
@@ -183,13 +185,13 @@ ngx_http_file_cache_create(ngx_http_request_t *r)
183
185
  return NGX_ERROR;
184
186
  }
185
187
 
188
+ cln->handler = ngx_http_file_cache_cleanup;
189
+ cln->data = c;
190
+
186
191
  if (ngx_http_file_cache_exists(cache, c) == NGX_ERROR) {
187
192
  return NGX_ERROR;
188
193
  }
189
194
 
190
- cln->handler = ngx_http_file_cache_cleanup;
191
- cln->data = c;
192
-
193
195
  if (ngx_http_file_cache_name(r, cache->path) != NGX_OK) {
194
196
  return NGX_ERROR;
195
197
  }
@@ -246,15 +248,24 @@ ngx_http_file_cache_open(ngx_http_request_t *r)
246
248
 
247
249
  c = r->cache;
248
250
 
251
+ if (c->waiting) {
252
+ return NGX_AGAIN;
253
+ }
254
+
249
255
  if (c->buf) {
250
256
  return ngx_http_file_cache_read(r, c);
251
257
  }
252
258
 
253
259
  cache = c->file_cache;
254
260
 
255
- cln = ngx_pool_cleanup_add(r->pool, 0);
256
- if (cln == NULL) {
257
- return NGX_ERROR;
261
+ if (c->node == NULL) {
262
+ cln = ngx_pool_cleanup_add(r->pool, 0);
263
+ if (cln == NULL) {
264
+ return NGX_ERROR;
265
+ }
266
+
267
+ cln->handler = ngx_http_file_cache_cleanup;
268
+ cln->data = c;
258
269
  }
259
270
 
260
271
  rc = ngx_http_file_cache_exists(cache, c);
@@ -266,9 +277,6 @@ ngx_http_file_cache_open(ngx_http_request_t *r)
266
277
  return rc;
267
278
  }
268
279
 
269
- cln->handler = ngx_http_file_cache_cleanup;
270
- cln->data = c;
271
-
272
280
  if (rc == NGX_AGAIN) {
273
281
  return NGX_HTTP_CACHE_SCARCE;
274
282
  }
@@ -308,7 +316,7 @@ ngx_http_file_cache_open(ngx_http_request_t *r)
308
316
  }
309
317
 
310
318
  if (!test) {
311
- return NGX_DECLINED;
319
+ goto done;
312
320
  }
313
321
 
314
322
  clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
@@ -332,7 +340,7 @@ ngx_http_file_cache_open(ngx_http_request_t *r)
332
340
 
333
341
  case NGX_ENOENT:
334
342
  case NGX_ENOTDIR:
335
- return rv;
343
+ goto done;
336
344
 
337
345
  default:
338
346
  ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
@@ -356,6 +364,114 @@ ngx_http_file_cache_open(ngx_http_request_t *r)
356
364
  }
357
365
 
358
366
  return ngx_http_file_cache_read(r, c);
367
+
368
+ done:
369
+
370
+ if (rv == NGX_DECLINED) {
371
+ return ngx_http_file_cache_lock(r, c);
372
+ }
373
+
374
+ return rv;
375
+ }
376
+
377
+
378
+ static ngx_int_t
379
+ ngx_http_file_cache_lock(ngx_http_request_t *r, ngx_http_cache_t *c)
380
+ {
381
+ ngx_msec_t now, timer;
382
+ ngx_http_file_cache_t *cache;
383
+
384
+ if (!c->lock) {
385
+ return NGX_DECLINED;
386
+ }
387
+
388
+ cache = c->file_cache;
389
+
390
+ ngx_shmtx_lock(&cache->shpool->mutex);
391
+
392
+ if (!c->node->updating) {
393
+ c->node->updating = 1;
394
+ c->updating = 1;
395
+ }
396
+
397
+ ngx_shmtx_unlock(&cache->shpool->mutex);
398
+
399
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
400
+ "http file cache lock u:%d wt:%M",
401
+ c->updating, c->wait_time);
402
+
403
+ if (c->updating) {
404
+ return NGX_DECLINED;
405
+ }
406
+
407
+ c->waiting = 1;
408
+
409
+ now = ngx_current_msec;
410
+
411
+ if (c->wait_time == 0) {
412
+ c->wait_time = now + c->lock_timeout;
413
+
414
+ c->wait_event.handler = ngx_http_file_cache_lock_wait_handler;
415
+ c->wait_event.data = r;
416
+ c->wait_event.log = r->connection->log;
417
+ }
418
+
419
+ timer = c->wait_time - now;
420
+
421
+ ngx_add_timer(&c->wait_event, (timer > 500) ? 500 : timer);
422
+
423
+ r->main->blocked++;
424
+
425
+ return NGX_AGAIN;
426
+ }
427
+
428
+
429
+ static void
430
+ ngx_http_file_cache_lock_wait_handler(ngx_event_t *ev)
431
+ {
432
+ ngx_uint_t wait;
433
+ ngx_msec_t timer;
434
+ ngx_http_cache_t *c;
435
+ ngx_http_request_t *r;
436
+ ngx_http_file_cache_t *cache;
437
+
438
+ r = ev->data;
439
+ c = r->cache;
440
+
441
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ev->log, 0,
442
+ "http file cache wait handler wt:%M cur:%M",
443
+ c->wait_time, ngx_current_msec);
444
+
445
+ timer = c->wait_time - ngx_current_msec;
446
+
447
+ if ((ngx_msec_int_t) timer <= 0) {
448
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
449
+ "http file cache lock timeout");
450
+ c->lock = 0;
451
+ goto wakeup;
452
+ }
453
+
454
+ cache = c->file_cache;
455
+ wait = 0;
456
+
457
+ ngx_shmtx_lock(&cache->shpool->mutex);
458
+
459
+ if (c->node->updating) {
460
+ wait = 1;
461
+ }
462
+
463
+ ngx_shmtx_unlock(&cache->shpool->mutex);
464
+
465
+ if (wait) {
466
+ ngx_add_timer(ev, (timer > 500) ? 500 : timer);
467
+ return;
468
+ }
469
+
470
+ wakeup:
471
+
472
+ c->waiting = 0;
473
+ r->main->blocked--;
474
+ r->connection->write->handler(r->connection->write);
359
475
  }
360
476
 
361
477
 
@@ -520,13 +636,19 @@ ngx_http_file_cache_exists(ngx_http_file_cache_t *cache, ngx_http_cache_t *c)
520
636
 
521
637
  ngx_shmtx_lock(&cache->shpool->mutex);
522
638
 
523
- fcn = ngx_http_file_cache_lookup(cache, c->key);
639
+ fcn = c->node;
640
+
641
+ if (fcn == NULL) {
642
+ fcn = ngx_http_file_cache_lookup(cache, c->key);
643
+ }
524
644
 
525
645
  if (fcn) {
526
646
  ngx_queue_remove(&fcn->queue);
527
647
 
528
- fcn->uses++;
529
- fcn->count++;
648
+ if (c->node == NULL) {
649
+ fcn->uses++;
650
+ fcn->count++;
651
+ }
530
652
 
531
653
  if (fcn->error) {
532
654
 
@@ -623,6 +745,10 @@ ngx_http_file_cache_name(ngx_http_request_t *r, ngx_path_t *path)
623
745
 
624
746
  c = r->cache;
625
747
 
748
+ if (c->file.name.len) {
749
+ return NGX_OK;
750
+ }
751
+
626
752
  c->file.name.len = path->name.len + 1 + path->len
627
753
  + 2 * NGX_HTTP_CACHE_KEY_LEN;
628
754
 
@@ -954,6 +1080,10 @@ ngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t *tf)
954
1080
  }
955
1081
  }
956
1082
  }
1083
+
1084
+ if (c->wait_event.timer_set) {
1085
+ ngx_del_timer(&c->wait_event);
1086
+ }
957
1087
  }
958
1088
 
959
1089
 
@@ -1267,59 +1397,53 @@ ngx_http_file_cache_loader(void *data)
1267
1397
 
1268
1398
 
1269
1399
  static ngx_int_t
1270
- ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache)
1400
+ ngx_http_file_cache_noop(ngx_tree_ctx_t *ctx, ngx_str_t *path)
1401
+ {
1402
+ return NGX_OK;
1403
+ }
1404
+
1405
+
1406
+ static ngx_int_t
1407
+ ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx, ngx_str_t *path)
1271
1408
  {
1272
- ngx_msec_t elapsed;
1409
+ ngx_msec_t elapsed;
1410
+ ngx_http_file_cache_t *cache;
1273
1411
 
1274
- if (cache->files++ > 100) {
1412
+ cache = ctx->data;
1413
+
1414
+ if (ngx_http_file_cache_add_file(ctx, path) != NGX_OK) {
1415
+ (void) ngx_http_file_cache_delete_file(ctx, path);
1416
+ }
1275
1417
 
1418
+ if (++cache->files >= cache->loader_files) {
1419
+ ngx_http_file_cache_loader_sleep(cache);
1420
+
1421
+ } else {
1276
1422
  ngx_time_update();
1277
1423
 
1278
1424
  elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last));
1279
1425
 
1280
1426
  ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
1281
- "http file cache manager time: %M", elapsed);
1282
-
1283
- if (elapsed > 200) {
1284
-
1285
- /*
1286
- * if processing 100 files takes more than 200ms,
1287
- * it seems that many operations require disk i/o,
1288
- * therefore sleep 200ms
1289
- */
1290
-
1291
- ngx_msleep(200);
1427
+ "http file cache loader time elapsed: %M", elapsed);
1292
1428
 
1293
- ngx_time_update();
1429
+ if (elapsed >= cache->loader_threshold) {
1430
+ ngx_http_file_cache_loader_sleep(cache);
1294
1431
  }
1295
-
1296
- cache->last = ngx_current_msec;
1297
- cache->files = 0;
1298
1432
  }
1299
1433
 
1300
1434
  return (ngx_quit || ngx_terminate) ? NGX_ABORT : NGX_OK;
1301
1435
  }
1302
1436
 
1303
1437
 
1304
- static ngx_int_t
1305
- ngx_http_file_cache_noop(ngx_tree_ctx_t *ctx, ngx_str_t *path)
1306
- {
1307
- return NGX_OK;
1308
- }
1309
-
1310
-
1311
- static ngx_int_t
1312
- ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx, ngx_str_t *path)
1438
+ static void
1439
+ ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache)
1313
1440
  {
1314
- ngx_http_file_cache_t *cache;
1441
+ ngx_msleep(cache->loader_sleep);
1315
1442
 
1316
- cache = ctx->data;
1443
+ ngx_time_update();
1317
1444
 
1318
- if (ngx_http_file_cache_add_file(ctx, path) != NGX_OK) {
1319
- (void) ngx_http_file_cache_delete_file(ctx, path);
1320
- }
1321
-
1322
- return ngx_http_file_cache_loader_sleep(cache);
1445
+ cache->last = ngx_current_msec;
1446
+ cache->files = 0;
1323
1447
  }
1324
1448
 
1325
1449
 
@@ -1468,6 +1592,8 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1468
1592
  time_t inactive;
1469
1593
  ssize_t size;
1470
1594
  ngx_str_t s, name, *value;
1595
+ ngx_int_t loader_files;
1596
+ ngx_msec_t loader_sleep, loader_threshold;
1471
1597
  ngx_uint_t i, n;
1472
1598
  ngx_http_file_cache_t *cache;
1473
1599
 
@@ -1482,6 +1608,9 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1482
1608
  }
1483
1609
 
1484
1610
  inactive = 600;
1611
+ loader_files = 100;
1612
+ loader_sleep = 50;
1613
+ loader_threshold = 200;
1485
1614
 
1486
1615
  name.len = 0;
1487
1616
  size = 0;
@@ -1571,7 +1700,7 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1571
1700
  s.data = value[i].data + 9;
1572
1701
 
1573
1702
  inactive = ngx_parse_time(&s, 1);
1574
- if (inactive < 0) {
1703
+ if (inactive == (time_t) NGX_ERROR) {
1575
1704
  ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1576
1705
  "invalid inactive value \"%V\"", &value[i]);
1577
1706
  return NGX_CONF_ERROR;
@@ -1595,6 +1724,48 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1595
1724
  continue;
1596
1725
  }
1597
1726
 
1727
+ if (ngx_strncmp(value[i].data, "loader_files=", 13) == 0) {
1728
+
1729
+ loader_files = ngx_atoi(value[i].data + 13, value[i].len - 13);
1730
+ if (loader_files == NGX_ERROR) {
1731
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1732
+ "invalid loader_files value \"%V\"", &value[i]);
1733
+ return NGX_CONF_ERROR;
1734
+ }
1735
+
1736
+ continue;
1737
+ }
1738
+
1739
+ if (ngx_strncmp(value[i].data, "loader_sleep=", 13) == 0) {
1740
+
1741
+ s.len = value[i].len - 13;
1742
+ s.data = value[i].data + 13;
1743
+
1744
+ loader_sleep = ngx_parse_time(&s, 0);
1745
+ if (loader_sleep == (ngx_msec_t) NGX_ERROR) {
1746
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1747
+ "invalid loader_sleep value \"%V\"", &value[i]);
1748
+ return NGX_CONF_ERROR;
1749
+ }
1750
+
1751
+ continue;
1752
+ }
1753
+
1754
+ if (ngx_strncmp(value[i].data, "loader_threshold=", 17) == 0) {
1755
+
1756
+ s.len = value[i].len - 17;
1757
+ s.data = value[i].data + 17;
1758
+
1759
+ loader_threshold = ngx_parse_time(&s, 0);
1760
+ if (loader_threshold == (ngx_msec_t) NGX_ERROR) {
1761
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1762
+ "invalid loader_threshold value \"%V\"", &value[i]);
1763
+ return NGX_CONF_ERROR;
1764
+ }
1765
+
1766
+ continue;
1767
+ }
1768
+
1598
1769
  ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1599
1770
  "invalid parameter \"%V\"", &value[i]);
1600
1771
  return NGX_CONF_ERROR;
@@ -1612,6 +1783,9 @@ ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1612
1783
  cache->path->data = cache;
1613
1784
  cache->path->conf_file = cf->conf_file->file.name.data;
1614
1785
  cache->path->line = cf->conf_file->line;
1786
+ cache->loader_files = loader_files;
1787
+ cache->loader_sleep = loader_sleep;
1788
+ cache->loader_threshold = loader_threshold;
1615
1789
 
1616
1790
  if (ngx_add_path(cf, &cache->path) != NGX_OK) {
1617
1791
  return NGX_CONF_ERROR;
@@ -1665,7 +1839,7 @@ ngx_http_file_cache_valid_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
1665
1839
  n = cf->args->nelts - 1;
1666
1840
 
1667
1841
  valid = ngx_parse_time(&value[n], 1);
1668
- if (valid < 0) {
1842
+ if (valid == (time_t) NGX_ERROR) {
1669
1843
  ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1670
1844
  "invalid time value \"%V\"", &value[n]);
1671
1845
  return NGX_CONF_ERROR;