Mercurial > hg > ngx_http_upstream_keepalive
annotate t/memcached-keepalive.t @ 11:15530a464dba
Keepalive: don't cache invalid connections.
1. Remember failed status, since peer.free() may be called more than once.
It's called twice if peer fails - once from ngx_http_upstream_next() with
NGX_PEER_FAILED set, and then from ngx_http_upstream_finalize_request()
without.
2. We shouldn't cache connection unless we aren't expecting anything from
upstream. For memcached this means either 404 response or 200 response with
all body read (body may not be read e.g. when serving HEAD request).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 13 Nov 2008 19:36:23 +0300 |
parents | bef88ba0b378 |
children | 067ddc059ee0 |
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; }; |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 plain(skip_all => 'Cache::Memcached not installed') if $@; |
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 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
97 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8081'); |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
98 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8082'); |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
99 $t->run(); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
100 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
101 ############################################################################### |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
102 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
103 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
|
104 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
|
105 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
106 $memd1->set('/', 'SEE-THIS'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
107 $memd2->set('/', 'SEE-THIS'); |
11
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
108 $memd1->set('/big', 'X' x 1000000); |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
109 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
110 my $total = $memd1->stats()->{total}->{total_connections}; |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
111 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
112 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
113 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
|
114 like(http_get('/next'), qr/404/, |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
115 'keepalive not found with memcached_next_upstream'); |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
116 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
|
117 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
|
118 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
|
119 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
120 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
|
121 'only one connection used'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
122 |
11
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
123 # 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
|
124 # 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
|
125 # connections. Check if we really do close them. |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
126 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
127 $total = $memd1->stats()->{total}->{total_connections}; |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
128 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
129 unlike(http_head('/'), qr/SEE-THIS/, 'head request'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
130 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
|
131 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
132 is($memd1->stats()->{total}->{total_connections}, $total + 1, |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
133 'head request closes connection'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
134 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
135 $total = $memd1->stats()->{total}->{total_connections}; |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
136 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
137 unlike(http_head('/big'), qr/XXX/, 'big head'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
138 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
|
139 |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
140 is($memd1->stats()->{total}->{total_connections}, $total + 1, |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
141 'big head request closes connection'); |
15530a464dba
Keepalive: don't cache invalid connections.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6
diff
changeset
|
142 |
6
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
143 # 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
|
144 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
145 $total = $memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
146 $memd2->stats()->{total}->{total_connections}; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
147 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
148 http_get('/memd2'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
149 http_get('/memd2'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
150 http_get('/memd2'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
151 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
152 is($memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
153 $memd2->stats()->{total}->{total_connections}, $total + 1, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
154 '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
|
155 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
156 $total = $memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
157 $memd2->stats()->{total}->{total_connections}; |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
158 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
159 # 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
|
160 # 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
|
161 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
162 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
163 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
164 http_get('/memd3'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
165 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
166 is($memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
167 $memd2->stats()->{total}->{total_connections}, $total + 3, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
168 '3 connections should be established'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
169 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
170 # 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
|
171 # 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
|
172 |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
173 $total = $memd1->stats()->{total}->{total_connections} + |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
174 $memd2->stats()->{total}->{total_connections}; |
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 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
177 http_get('/memd4'); |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
178 http_get('/memd4'); |
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 is($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}, $total + 2, |
bef88ba0b378
Keepalive: distinguish between upstream servers by default.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1
diff
changeset
|
182 'connection per backend'); |
1
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
183 |
ca955a7f651b
Keepalive: common cache for all backends.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
184 ############################################################################### |