Mercurial > hg > ngx_http_upstream_keepalive
comparison t/memcached-keepalive.t @ 45:489c5d4318ff draft
Keepalive: "single" parameter deprecated.
The original idea was to optimize edge cases in case of interchangeable
backends, i.e. don't establish a new connection if we have any one
cached. This causes more harm than good though, as it screws up
underlying balancer's idea about backends used and may result in
various unexpected problems.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 25 Jun 2012 22:55:53 +0400 |
parents | 2ee28064a04a |
children |
comparison
equal
deleted
inserted
replaced
44:d9ac9ad67f45 | 45:489c5d4318ff |
---|---|
18 select STDOUT; $| = 1; | 18 select STDOUT; $| = 1; |
19 | 19 |
20 eval { require Cache::Memcached; }; | 20 eval { require Cache::Memcached; }; |
21 plan(skip_all => 'Cache::Memcached not installed') if $@; | 21 plan(skip_all => 'Cache::Memcached not installed') if $@; |
22 | 22 |
23 my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(17) | 23 my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(16) |
24 ->write_file_expand('nginx.conf', <<'EOF'); | 24 ->write_file_expand('nginx.conf', <<'EOF'); |
25 | 25 |
26 %%TEST_GLOBALS%% | 26 %%TEST_GLOBALS%% |
27 | 27 |
28 daemon off; | 28 daemon off; |
34 %%TEST_GLOBALS_HTTP%% | 34 %%TEST_GLOBALS_HTTP%% |
35 | 35 |
36 upstream memd { | 36 upstream memd { |
37 server 127.0.0.1:8081; | 37 server 127.0.0.1:8081; |
38 keepalive 1; | 38 keepalive 1; |
39 } | |
40 | |
41 upstream memd2 { | |
42 server 127.0.0.1:8081; | |
43 server 127.0.0.1:8082; | |
44 keepalive 1 single; | |
45 } | 39 } |
46 | 40 |
47 upstream memd3 { | 41 upstream memd3 { |
48 server 127.0.0.1:8081; | 42 server 127.0.0.1:8081; |
49 server 127.0.0.1:8082; | 43 server 127.0.0.1:8082; |
67 | 61 |
68 location /next { | 62 location /next { |
69 set $memcached_key $uri; | 63 set $memcached_key $uri; |
70 memcached_next_upstream not_found; | 64 memcached_next_upstream not_found; |
71 memcached_pass memd; | 65 memcached_pass memd; |
72 } | |
73 | |
74 location /memd2 { | |
75 set $memcached_key "/"; | |
76 memcached_pass memd2; | |
77 } | 66 } |
78 | 67 |
79 location /memd3 { | 68 location /memd3 { |
80 set $memcached_key "/"; | 69 set $memcached_key "/"; |
81 memcached_pass memd3; | 70 memcached_pass memd3; |
158 like(http_get('/'), qr/SEE-THIS/, 'get after big head'); | 147 like(http_get('/'), qr/SEE-THIS/, 'get after big head'); |
159 | 148 |
160 is($memd1->stats()->{total}->{total_connections}, $total + 1, | 149 is($memd1->stats()->{total}->{total_connections}, $total + 1, |
161 'big head request closes connection'); | 150 'big head request closes connection'); |
162 | 151 |
163 # two backends with 'single' option - should establish only one connection | 152 # two backends with maximum number of cached connections set to 1, |
153 # should establish new connection on each request | |
164 | 154 |
165 $total = $memd1->stats()->{total}->{total_connections} + | 155 $total = $memd1->stats()->{total}->{total_connections} + |
166 $memd2->stats()->{total}->{total_connections}; | 156 $memd2->stats()->{total}->{total_connections}; |
167 | |
168 http_get('/memd2'); | |
169 http_get('/memd2'); | |
170 http_get('/memd2'); | |
171 | |
172 is($memd1->stats()->{total}->{total_connections} + | |
173 $memd2->stats()->{total}->{total_connections}, $total + 1, | |
174 'only one connection with two backends and single'); | |
175 | |
176 $total = $memd1->stats()->{total}->{total_connections} + | |
177 $memd2->stats()->{total}->{total_connections}; | |
178 | |
179 # two backends without 'single' option and maximum number of cached | |
180 # connections set to 1 - should establish new connection on each request | |
181 | 157 |
182 http_get('/memd3'); | 158 http_get('/memd3'); |
183 http_get('/memd3'); | 159 http_get('/memd3'); |
184 http_get('/memd3'); | 160 http_get('/memd3'); |
185 | 161 |
186 is($memd1->stats()->{total}->{total_connections} + | 162 is($memd1->stats()->{total}->{total_connections} + |
187 $memd2->stats()->{total}->{total_connections}, $total + 3, | 163 $memd2->stats()->{total}->{total_connections}, $total + 3, |
188 '3 connections should be established'); | 164 '3 connections should be established'); |
189 | 165 |
190 # two backends without 'single' option and maximum number of cached | 166 # two backends with maximum number of cached connections set to 10, |
191 # connections set to 10 - should establish only two connections (1 per backend) | 167 # should establish only two connections (1 per backend) |
192 | 168 |
193 $total = $memd1->stats()->{total}->{total_connections} + | 169 $total = $memd1->stats()->{total}->{total_connections} + |
194 $memd2->stats()->{total}->{total_connections}; | 170 $memd2->stats()->{total}->{total_connections}; |
195 | 171 |
196 http_get('/memd4'); | 172 http_get('/memd4'); |