diff options
author | Brad Fitzpatrick <brad@danga.com> | 2004-07-16 17:42:56 +0000 |
---|---|---|
committer | Brad Fitzpatrick <brad@danga.com> | 2004-07-16 17:42:56 +0000 |
commit | 0c84015a533d4e82eec004415cfdce4702f7de65 (patch) | |
tree | 04fac2b2ba9c7ebfa4b4bd47015c52c2d418d36a /scripts/memcached-tool | |
parent | 585d68ca18529aed6528f4b55292a94acf3b9a41 (diff) | |
download | memcached-0c84015a533d4e82eec004415cfdce4702f7de65.tar.gz |
new memcached tuning tool. observe:
lj@grimace:~$ memcached-tool.pl
Usage: memcached-tool <host[:port]> [mode]
memcached-tool 10.0.0.5:11211 display # shows slabs
memcached-tool 10.0.0.5:11211 # same. (default is display)
memcached-tool 10.0.0.5:11211 move 7 9 # takes 1MB slab from class #7
# to class #9.
You can only move slabs around once memory is totally allocated, and only
once the target class is full. (So you can't move from #6 to #9 and #7
to #9 at the same itme, since you'd have to wait for #9 to fill from
the first reassigned page)
lj@grimace:~$ memcached-tool.pl 10.0.0.41:11211
# Item_Size Max_age 1MB_pages Full?
6 64 B 12869 s 82 yes
7 128 B 12446 s 74 yes
8 256 B 11069 s 91 yes
9 512 B 12184 s 54 yes
10 1 kB 12120 s 106 yes
11 2 kB 11498 s 181 yes
12 4 kB 10087 s 189 yes
13 8 kB 8322 s 124 yes
14 16 kB 7335 s 69 yes
15 32 kB 4591 s 31 yes
16 64 kB 3378 s 17 yes
17 128 kB 39944 s 6 yes
lj@grimace:~$ memcached-tool.pl 10.0.0.41:11211 move 17 16
Success.
lj@grimace:~$ memcached-tool.pl 10.0.0.41:11211 move 17 16
Error: can't move from 17 to 16. Destination not yet full? See usage docs.
lj@grimace:~$ memcached-tool.pl 10.0.0.41:11211
# Item_Size Max_age 1MB_pages Full?
6 64 B 12687 s 82 yes
7 128 B 12338 s 74 yes
8 256 B 10968 s 91 yes
9 512 B 11950 s 54 yes
10 1 kB 11931 s 106 yes
11 2 kB 11421 s 181 yes
12 4 kB 9986 s 189 yes
13 8 kB 8356 s 124 yes
14 16 kB 7240 s 69 yes
15 32 kB 4584 s 31 yes
16 64 kB 3257 s 18 no
17 128 kB 40287 s 5 yes
git-svn-id: http://code.sixapart.com/svn/memcached/trunk@212 b0b603af-a30f-0410-a34e-baf09ae79d0b
Diffstat (limited to 'scripts/memcached-tool')
-rwxr-xr-x | scripts/memcached-tool | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/scripts/memcached-tool b/scripts/memcached-tool new file mode 100755 index 0000000..4de3a8a --- /dev/null +++ b/scripts/memcached-tool @@ -0,0 +1,117 @@ +#!/usr/bin/perl +# +# memcached-tool: +# stats/management tool for memcached. +# +# Author: +# Brad Fitzpatrick <brad@danga.com> +# +# License: +# public domain. I give up all rights to this +# tool. modify and copy at will. +# + +use strict; +use IO::Socket::INET; + +my $host = shift; +my $mode = shift || "display"; +my ($from, $to); + +if ($mode eq "display") { + undef $mode if @ARGV; +} elsif ($mode eq "move") { + $from = shift; + $to = shift; + undef $mode if $from < 6 || $from > 17; + undef $mode if $to < 6 || $to > 17; + print STDERR "ERROR: parameters out of range\n\n" unless $mode; +} else { + undef $mode; +} + +undef $mode if @ARGV; + +die +"Usage: memcached-tool <host[:port]> [mode]\n + memcached-tool 10.0.0.5:11211 display # shows slabs + memcached-tool 10.0.0.5:11211 # same. (default is display) + memcached-tool 10.0.0.5:11211 move 7 9 # takes 1MB slab from class #7 + # to class #9. + +You can only move slabs around once memory is totally allocated, and only +once the target class is full. (So you can't move from #6 to #9 and #7 +to #9 at the same itme, since you'd have to wait for #9 to fill from +the first reassigned page) +" unless $host && $mode; + +$host .= ":11211" unless $host =~ /:\d+/; + +my $sock = IO::Socket::INET->new(PeerAddr => $host, + Proto => 'tcp'); +die "Couldn't connect to $host\n" unless $sock; + + +if ($mode eq "move") { + my $tries = 0; + while (1) { + print $sock "slabs reassign $from $to\r\n"; + my $res = <$sock>; + $res =~ s/\s+//; + if ($res eq "DONE") { + print "Success.\n"; + exit 0; + } elsif ($res eq "CANT") { + print "Error: can't move from $from to $to. Destination not yet full? See usage docs.\n"; + exit; + } elsif ($res eq "BUSY") { + if (++$tries == 3) { + print "Failed to move after 3 tries. Try again later.\n"; + exit; + } + + print "Page busy, retrying...\n"; + sleep 1; + } + } + + exit; +} + +# display mode: + +my %items; # class -> { number, age, chunk_size, chunks_per_page, + # total_pages, total_chunks, used_chunks, + # free_chunks, free_chunks_end } + +print $sock "stats items\r\n"; +while (<$sock>) { + last if /^END/; + if (/^STAT items:(\d+):(\w+) (\d+)/) { + $items{$1}{$2} = $3; + } +} + +print $sock "stats slabs\r\n"; +while (<$sock>) { + last if /^END/; + if (/^STAT (\d+):(\w+) (\d+)/) { + $items{$1}{$2} = $3; + } +} + +print " # Item_Size Max_age 1MB_pages Full?\n"; +foreach my $n (6..17) { + my $it = $items{$n}; + my $size = $it->{chunk_size} < 1024 ? "$it->{chunk_size} B" : + sprintf("%d kB", $it->{chunk_size} / 1024); + my $full = $it->{free_chunks_end} == 0 ? "yes" : " no"; + printf "%3d %6s%7d s %7d $full\n", $n, $size, $it->{age}, $it->{total_pages}; + + +} + +use Data::Dumper; +#print Dumper(\%items); + + |