comparison t/memcached-keepalive.t @ 1:ca955a7f651b

Keepalive: common cache for all backends. Known limitations: Connections cached to the upstream pool as a whole, not to individual backend servers, and therefore load distribution may be less than ideal (especially under light load).
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 22 Oct 2008 03:52:29 +0400
parents
children bef88ba0b378
comparison
equal deleted inserted replaced
0:725ee11164f3 1:ca955a7f651b
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Test for memcached with keepalive.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13 use Test::Nginx;
14
15 ###############################################################################
16
17 select STDERR; $| = 1;
18 select STDOUT; $| = 1;
19
20 eval { require Cache::Memcached; };
21 plain(skip_all => 'Cache::Memcached not installed') if $@;
22
23 my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(7)
24 ->write_file_expand('nginx.conf', <<'EOF');
25
26 master_process off;
27 daemon off;
28
29 events {
30 worker_connections 1024;
31 }
32
33 http {
34 access_log off;
35
36 client_body_temp_path %%TESTDIR%%/client_body_temp;
37 fastcgi_temp_path %%TESTDIR%%/fastcgi_temp;
38 proxy_temp_path %%TESTDIR%%/proxy_temp;
39
40 upstream memd {
41 server 127.0.0.1:8081;
42 keepalive;
43 }
44
45 server {
46 listen localhost:8080;
47 server_name localhost;
48
49 location / {
50 set $memcached_key $uri;
51 memcached_pass memd;
52 }
53
54 location /next {
55 set $memcached_key $uri;
56 memcached_next_upstream not_found;
57 memcached_pass memd;
58 }
59 }
60 }
61
62 EOF
63
64 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8081');
65 $t->run();
66
67 ###############################################################################
68
69 my $memd = Cache::Memcached->new(servers => [ '127.0.0.1:8081' ]);
70 $memd->set('/', 'SEE-THIS');
71
72 my $total = $memd->stats()->{total}->{total_connections};
73
74 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request');
75 like(http_get('/notfound'), qr/404/, 'keepalive memcached not found');
76 like(http_get('/next'), qr/404/,
77 'keepalive not found with memcached_next_upstream');
78 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request again');
79 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request again');
80 like(http_get('/'), qr/SEE-THIS/, 'keepalive memcached request again');
81
82 is($memd->stats()->{total}->{total_connections}, $total + 1, 'keepalive used');
83
84 ###############################################################################