Mercurial > hg > ngx_http_upstream_keepalive
annotate t/memcached-keepalive.t @ 19:2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
UDP ports are on by default in 1.2.7+, so we have to explicitly switch them
off to avoid conflicts when running two memcached servers.
Do it conditionally for now to keep compatibility with old memcached servers
without UDP support. Not sure it's really needed since UDP support is here
since memcached 1.2.1, probably should be done unconditionally instead.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 28 Aug 2009 20:45:15 +0400 |
parents | 181a487581b7 |
children | 8d8eaaf07663 |
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 |
11
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
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 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 master_process off; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 daemon off; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 events { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 worker_connections 1024; |
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 { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 access_log off; |
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 client_body_temp_path %%TESTDIR%%/client_body_temp; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 proxy_temp_path %%TESTDIR%%/proxy_temp; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 upstream memd { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 server 127.0.0.1:8081; |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
42 keepalive 1; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
43 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
44 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
45 upstream memd2 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
46 server 127.0.0.1:8081; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
47 server 127.0.0.1:8082; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
48 keepalive 1 single; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
49 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
50 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
51 upstream memd3 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
52 server 127.0.0.1:8081; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
53 server 127.0.0.1:8082; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
54 keepalive 1; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
55 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
56 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
57 upstream memd4 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
58 server 127.0.0.1:8081; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
59 server 127.0.0.1:8082; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
60 keepalive 10; |
1
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 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
63 server { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
64 listen localhost:8080; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
65 server_name localhost; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
66 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
67 location / { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
68 set $memcached_key $uri; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
69 memcached_pass memd; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
70 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
71 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
72 location /next { |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
73 set $memcached_key $uri; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
74 memcached_next_upstream not_found; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
75 memcached_pass memd; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
76 } |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
77 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
78 location /memd2 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
79 set $memcached_key "/"; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
80 memcached_pass memd2; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
81 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
82 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
83 location /memd3 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
84 set $memcached_key "/"; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
85 memcached_pass memd3; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
86 } |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
87 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
88 location /memd4 { |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
89 set $memcached_key "/"; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
90 memcached_pass memd4; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
91 } |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
92 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
93 } |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
94 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
95 EOF |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
96 |
19
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
97 my $memhelp = `memcached -h`; |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
98 my @memopts1 = (); |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
99 my @memopts2 = (); |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
100 |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
101 if ($memhelp =~ /repcached/) { |
12
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
102 # 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
|
103 # that should be different too |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
104 |
19
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
105 push @memopts1, '-X', '8091'; |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
106 push @memopts2, '-X', '8092'; |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
107 } |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
108 if ($memhelp =~ /-U/) { |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
109 # 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
|
110 |
19
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
111 push @memopts1, '-U', '0'; |
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
112 push @memopts2, '-U', '0'; |
12
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
113 } |
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
114 |
19
2ce9d8a1ca93
Keepalive: fix tests for memcached 1.2.7+.
Maxim Dounin <mdounin@mdounin.ru>
parents:
13
diff
changeset
|
115 $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
|
116 $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
|
117 |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
118 $t->run(); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
119 |
12
067ddc059ee0
Keepalive: fix tests to be compatible with repcached patches.
Maxim Dounin <mdounin@mdounin.ru>
parents:
11
diff
changeset
|
120 $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
|
121 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
|
122 $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
|
123 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
|
124 |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
125 ############################################################################### |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
126 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
127 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
|
128 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
|
129 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
130 $memd1->set('/', 'SEE-THIS'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
131 $memd2->set('/', 'SEE-THIS'); |
11
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
132 $memd1->set('/big', 'X' x 1000000); |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
133 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
134 my $total = $memd1->stats()->{total}->{total_connections}; |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
135 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
136 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
137 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
|
138 like(http_get('/next'), qr/404/, |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
139 'keepalive not found with memcached_next_upstream'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
144 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
|
145 'only one connection used'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
146 |
11
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
147 # 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
|
148 # 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
|
149 # connections. Check if we really do close them. |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
150 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
151 $total = $memd1->stats()->{total}->{total_connections}; |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
152 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
153 unlike(http_head('/'), qr/SEE-THIS/, 'head request'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
154 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
|
155 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
156 is($memd1->stats()->{total}->{total_connections}, $total + 1, |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
157 'head request closes connection'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
158 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
159 $total = $memd1->stats()->{total}->{total_connections}; |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
160 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
161 unlike(http_head('/big'), qr/XXX/, 'big head'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
162 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
|
163 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
164 is($memd1->stats()->{total}->{total_connections}, $total + 1, |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
165 'big head request closes connection'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
166 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
167 # two backends with 'single' option - should establish only one connection |
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('/memd2'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
173 http_get('/memd2'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
174 http_get('/memd2'); |
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 + 1, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
178 'only one connection with two backends and single'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
179 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
180 $total = $memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
181 $memd2->stats()->{total}->{total_connections}; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
182 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
183 # two backends without 'single' option and maximum number of cached |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
184 # connections set to 1 - should establish new connection on each request |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
185 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
186 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
187 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
188 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
189 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
190 is($memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
191 $memd2->stats()->{total}->{total_connections}, $total + 3, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
192 '3 connections should be established'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
193 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
194 # two backends without 'single' option and maximum number of cached |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
195 # connections set to 10 - should establish only two connections (1 per backend) |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
196 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
197 $total = $memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
198 $memd2->stats()->{total}->{total_connections}; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
199 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
200 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
201 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
202 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
203 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
204 is($memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
205 $memd2->stats()->{total}->{total_connections}, $total + 2, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
206 'connection per backend'); |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
207 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
208 ############################################################################### |