Mercurial > hg > nginx-quic
annotate src/core/ngx_open_file_cache.h @ 4207:4fc91bae6f83
Better recheck of dead upstream servers.
Previously nginx used to mark backend again as live as soon as fail_timeout
passes (10s by default) since last failure. On the other hand, detecting
dead backend takes up to 60s (proxy_connect_timeout) in typical situation
"backend is down and doesn't respond to any packets". This resulted in
suboptimal behaviour in the above situation (up to 23% of requests were
directed to dead backend with default settings).
More detailed description of the problem may be found here (in Russian):
http://mailman.nginx.org/pipermail/nginx-ru/2011-August/042172.html
Fix is to only allow one request after fail_timeout passes, and
mark backend as "live" only if this request succeeds.
Note that with new code backend will not be marked "live" unless "check"
request is completed, and this may take a while in some specific workloads
(e.g. streaming). This is believed to be acceptable.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 12 Oct 2011 14:22:48 +0000 |
parents | e7cd13b7f759 |
children | d620f497c50f |
rev | line source |
---|---|
1453 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 | |
10 | |
11 #ifndef _NGX_OPEN_FILE_CACHE_H_INCLUDED_ | |
12 #define _NGX_OPEN_FILE_CACHE_H_INCLUDED_ | |
13 | |
14 | |
2277 | 15 #define NGX_OPEN_FILE_DIRECTIO_OFF NGX_MAX_OFF_T_VALUE |
16 | |
17 | |
1453 | 18 typedef struct { |
19 ngx_fd_t fd; | |
20 ngx_file_uniq_t uniq; | |
21 time_t mtime; | |
22 off_t size; | |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3178
diff
changeset
|
23 off_t fs_size; |
2129 | 24 off_t directio; |
3178 | 25 size_t read_ahead; |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2277
diff
changeset
|
26 |
1453 | 27 ngx_err_t err; |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2277
diff
changeset
|
28 char *failed; |
1453 | 29 |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1765
diff
changeset
|
30 time_t valid; |
1453 | 31 |
1772 | 32 ngx_uint_t min_uses; |
33 | |
1453 | 34 unsigned test_dir:1; |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2277
diff
changeset
|
35 unsigned test_only:1; |
2072 | 36 unsigned log:1; |
1453 | 37 unsigned errors:1; |
1457 | 38 unsigned events:1; |
1453 | 39 |
40 unsigned is_dir:1; | |
41 unsigned is_file:1; | |
42 unsigned is_link:1; | |
43 unsigned is_exec:1; | |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
44 unsigned is_directio:1; |
1453 | 45 } ngx_open_file_info_t; |
46 | |
47 | |
48 typedef struct ngx_cached_open_file_s ngx_cached_open_file_t; | |
49 | |
50 struct ngx_cached_open_file_s { | |
51 ngx_rbtree_node_t node; | |
1765 | 52 ngx_queue_t queue; |
1453 | 53 |
54 u_char *name; | |
55 time_t created; | |
56 time_t accessed; | |
57 | |
58 ngx_fd_t fd; | |
59 ngx_file_uniq_t uniq; | |
60 time_t mtime; | |
61 off_t size; | |
62 ngx_err_t err; | |
63 | |
1772 | 64 uint32_t uses; |
65 | |
1453 | 66 unsigned count:24; |
67 unsigned close:1; | |
1775 | 68 unsigned use_event:1; |
1453 | 69 |
70 unsigned is_dir:1; | |
71 unsigned is_file:1; | |
72 unsigned is_link:1; | |
73 unsigned is_exec:1; | |
2246
987831d73bd8
cache directio flag in open file cache
Igor Sysoev <igor@sysoev.ru>
parents:
2231
diff
changeset
|
74 unsigned is_directio:1; |
1453 | 75 |
76 ngx_event_t *event; | |
77 }; | |
78 | |
79 | |
80 typedef struct { | |
81 ngx_rbtree_t rbtree; | |
1761 | 82 ngx_rbtree_node_t sentinel; |
1765 | 83 ngx_queue_t expire_queue; |
1453 | 84 |
85 ngx_uint_t current; | |
86 ngx_uint_t max; | |
87 time_t inactive; | |
88 } ngx_open_file_cache_t; | |
89 | |
90 | |
91 typedef struct { | |
92 ngx_open_file_cache_t *cache; | |
93 ngx_cached_open_file_t *file; | |
1772 | 94 ngx_uint_t min_uses; |
1453 | 95 ngx_log_t *log; |
96 } ngx_open_file_cache_cleanup_t; | |
97 | |
98 | |
99 typedef struct { | |
100 | |
101 /* ngx_connection_t stub to allow use c->fd as event ident */ | |
102 void *data; | |
103 ngx_event_t *read; | |
104 ngx_event_t *write; | |
105 ngx_fd_t fd; | |
106 | |
107 ngx_cached_open_file_t *file; | |
108 ngx_open_file_cache_t *cache; | |
109 } ngx_open_file_cache_event_t; | |
110 | |
111 | |
112 ngx_open_file_cache_t *ngx_open_file_cache_init(ngx_pool_t *pool, | |
113 ngx_uint_t max, time_t inactive); | |
114 ngx_int_t ngx_open_cached_file(ngx_open_file_cache_t *cache, ngx_str_t *name, | |
115 ngx_open_file_info_t *of, ngx_pool_t *pool); | |
116 | |
117 | |
118 #endif /* _NGX_OPEN_FILE_CACHE_H_INCLUDED_ */ |