5 use lib
'../../api/perl/lib';
7 use Time
::HiRes
qw(time);
10 die "Usage: stress-memcached.pl ip:port threads\n";
16 my $memc = new Cache
::Memcached
;
17 $memc->set_servers([$host]);
19 unless ($memc->set("foo", "bar") &&
20 $memc->get("foo") eq "bar") {
21 die "memcached not running at $host ?\n";
23 $memc->disconnect_all();
28 if ($running < $threads) {
32 #print "Launched $cpid. Running $running threads.\n";
45 $memc = new Cache
::Memcached
;
46 $memc->set_servers([$host]);
49 my $start = sub { $t1 = time(); };
53 my $td = sprintf("%0.3f", $t2 - $t1);
54 if ($td > 0.25) { print "Took $td seconds for: $op\n"; }
60 for (my $i = 0; $i < $max; $i++) {
62 my $set = $memc->set($key, $key);
66 for (1..int(rand(500))) {
67 my $rand = int(rand($max));
69 my $meth = int(rand(3));
70 my $exp = int(rand(3));
71 undef $exp unless $exp;
74 $memc->add($key, $key, $exp);
76 } elsif ($meth == 1) {
80 $memc->set($key, $key, $exp);
83 $rand = int(rand($max));
86 my $v = $memc->get($key);
88 if ($v && $v ne $key) { die "Bogus: $v for key $rand\n"; }
92 my $multi = $memc->get_multi(map { key
(int(rand($max))) } (1..$max));
98 $_ = sprintf("%04d", $n);
99 if ($n % 2) { $_ .= "a"x20
; }