Mercurial > hg > ngx_http_upstream_keepalive
annotate 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 |
rev | line source |
---|---|
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 # (C) Maxim Dounin |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 # Test for memcached with keepalive. |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 ############################################################################### |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 use warnings; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 use strict; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 use Test::More; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 use Test::Nginx; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 ############################################################################### |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 select STDERR; $| = 1; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 select STDOUT; $| = 1; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 eval { require Cache::Memcached; }; |
13
181a487581b7
Keepalive: fix typo in tests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
12
diff
changeset
|
21 plan(skip_all => 'Cache::Memcached not installed') if $@; |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
45
489c5d4318ff
Keepalive: "single" parameter deprecated.
Maxim Dounin <mdounin@mdounin.ru>
parents:
24
diff
changeset
|
23 my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(16) |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 ->write_file_expand('nginx.conf', <<'EOF'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 |
20 | 26 %%TEST_GLOBALS%% |
27 | |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 daemon off; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 events { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 http { |
20 | 34 %%TEST_GLOBALS_HTTP%% |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 upstream memd { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 server 127.0.0.1:8081; |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
38 keepalive 1; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
39 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
40 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
41 upstream memd3 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
42 server 127.0.0.1:8081; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
43 server 127.0.0.1:8082; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
44 keepalive 1; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
45 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
46 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
47 upstream memd4 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
48 server 127.0.0.1:8081; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
49 server 127.0.0.1:8082; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
50 keepalive 10; |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 server { |
20 | 54 listen 127.0.0.1:8080; |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 server_name localhost; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 location / { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 set $memcached_key $uri; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 memcached_pass memd; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 location /next { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 set $memcached_key $uri; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 memcached_next_upstream not_found; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 memcached_pass memd; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 } |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
67 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
68 location /memd3 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
69 set $memcached_key "/"; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
70 memcached_pass memd3; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
71 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
72 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
73 location /memd4 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
74 set $memcached_key "/"; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
75 memcached_pass memd4; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
76 } |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
77 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
78 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
79 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
80 EOF |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
81 |
19
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
82 my $memhelp = `memcached -h`; |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
83 my @memopts1 = (); |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
84 my @memopts2 = (); |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
85 |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
86 if ($memhelp =~ /repcached/) { |
12
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
87 # repcached patches adds additional listen socket memcached |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
88 # that should be different too |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
89 |
19
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
90 push @memopts1, '-X', '8091'; |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
91 push @memopts2, '-X', '8092'; |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
92 } |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
93 if ($memhelp =~ /-U/) { |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
94 # UDP ports no longer off by default in memcached 1.2.7+ |
12
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
95 |
19
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
96 push @memopts1, '-U', '0'; |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
97 push @memopts2, '-U', '0'; |
12
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
98 } |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
99 |
19
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
100 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8081', @memopts1); |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
101 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8082', @memopts2); |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
102 |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
103 $t->run(); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
104 |
12
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
105 $t->waitforsocket('127.0.0.1:8081') |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
106 or die "Unable to start memcached"; |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
107 $t->waitforsocket('127.0.0.1:8082') |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
108 or die "Unable to start second memcached"; |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
109 |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
110 ############################################################################### |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
111 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
112 my $memd1 = Cache::Memcached->new(servers => [ '127.0.0.1:8081' ]); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
113 my $memd2 = Cache::Memcached->new(servers => [ '127.0.0.1:8082' ]); |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
114 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
115 $memd1->set('/', 'SEE-THIS'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
116 $memd2->set('/', 'SEE-THIS'); |
11
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
117 $memd1->set('/big', 'X' x 1000000); |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
118 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
119 my $total = $memd1->stats()->{total}->{total_connections}; |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
120 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
121 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
122 like(http_get('/notfound'), qr/404/, 'keepalive memcached not found'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
123 like(http_get('/next'), qr/404/, |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
124 'keepalive not found with memcached_next_upstream'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
125 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request again'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
126 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request again'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
127 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request again'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
128 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
129 is($memd1->stats()->{total}->{total_connections}, $total + 1, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
130 'only one connection used'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
131 |
11
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
132 # Since nginx doesn't read all data from connection in some situations (head |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
133 # requests, post_action, errors writing to client) we have to close such |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
134 # connections. Check if we really do close them. |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
135 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
136 $total = $memd1->stats()->{total}->{total_connections}; |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
137 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
138 unlike(http_head('/'), qr/SEE-THIS/, 'head request'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
139 like(http_get('/'), qr/SEE-THIS/, 'get after head'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
140 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
141 is($memd1->stats()->{total}->{total_connections}, $total + 1, |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
142 'head request closes connection'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
143 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
144 $total = $memd1->stats()->{total}->{total_connections}; |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
145 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
146 unlike(http_head('/big'), qr/XXX/, 'big head'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
147 like(http_get('/'), qr/SEE-THIS/, 'get after big head'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
148 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
149 is($memd1->stats()->{total}->{total_connections}, $total + 1, |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
150 'big head request closes connection'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
151 |
45
489c5d4318ff
Keepalive: "single" parameter deprecated.
Maxim Dounin <mdounin@mdounin.ru>
parents:
24
diff
changeset
|
152 # two backends with maximum number of cached connections set to 1, |
489c5d4318ff
Keepalive: "single" parameter deprecated.
Maxim Dounin <mdounin@mdounin.ru>
parents:
24
diff
changeset
|
153 # should establish new connection on each request |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
154 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
155 $total = $memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
156 $memd2->stats()->{total}->{total_connections}; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
157 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
158 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
159 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
160 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
161 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
162 is($memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
163 $memd2->stats()->{total}->{total_connections}, $total + 3, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
164 '3 connections should be established'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
165 |
45
489c5d4318ff
Keepalive: "single" parameter deprecated.
Maxim Dounin <mdounin@mdounin.ru>
parents:
24
diff
changeset
|
166 # two backends with maximum number of cached connections set to 10, |
489c5d4318ff
Keepalive: "single" parameter deprecated.
Maxim Dounin <mdounin@mdounin.ru>
parents:
24
diff
changeset
|
167 # should establish only two connections (1 per backend) |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
168 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
169 $total = $memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
170 $memd2->stats()->{total}->{total_connections}; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
171 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
172 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
173 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
174 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
175 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
176 is($memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
177 $memd2->stats()->{total}->{total_connections}, $total + 2, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
178 'connection per backend'); |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
179 |
24
2ee28064a04a
Keepalive: correctly close connections on gracefull shutdown.
Maxim Dounin <mdounin@mdounin.ru>
parents:
20
diff
changeset
|
180 $t->stop(); |
2ee28064a04a
Keepalive: correctly close connections on gracefull shutdown.
Maxim Dounin <mdounin@mdounin.ru>
parents:
20
diff
changeset
|
181 |
2ee28064a04a
Keepalive: correctly close connections on gracefull shutdown.
Maxim Dounin <mdounin@mdounin.ru>
parents:
20
diff
changeset
|
182 like(`grep -F '[alert]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no alerts'); |
2ee28064a04a
Keepalive: correctly close connections on gracefull shutdown.
Maxim Dounin <mdounin@mdounin.ru>
parents:
20
diff
changeset
|
183 |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
184 ############################################################################### |