First draft of stats patch

Brad Fitzpatrick brad@danga.com
Mon, 1 Dec 2003 11:08:54 -0800 (PST)


Jamie,

Finally merged.  Sorry for month delay.

Hit me back if there's anything I missed.  (also, I didn't test it at all,
but should work fine....)

- Brad


On Wed, 29 Oct 2003, Jamie McCarthy wrote:

> It's here:
>
> http://lvalue.com/cache-memcached-1.0.11-stats-patch.txt
>
> Let me know what you think, and in a day or two, I can edit it into
> a form that will be closer to what you want.  In particular:
>
> * I know you'll probably want to yank the extra debugging code in
> _load_items(), but I left it in, just in case you're as much of a
> debug code freak as I am.
>
> * I tried to keep my code all-spaces, but you may have to expand
> some of my 8-space tabs.  For a second draft I'll double-check
> that for you.
>
> * On several lines I removed whitespace at the end of the line
> (pet peeve of mine);  if you don't care, let me know, and in the
> next draft I'll leave it in.  OK, that was pretty anal of me.
>
> * I need to make the documentation more clear as to what arg the
> stats() method takes, and the format of the hashref it returns --
> I'll work on that.
>
> I did stick to your coding style as much as possible, even when it
> annoyed me (the apostrophes in $self->{'buckets'} serve no purpose,
> and IMHO are just visual clutter, but if you like it that way, it's
> your business :)
>
> I had to reuse some code in get_sock();  I pulled it out and made a
> new method init_buckets(), which get_sock() now calls.  That wasn't
> strictly necessary, but if someone calls stats() before anything
> else, I'd like it to still work.
>
> Obviously the stats() method is the main thing.  By default (no args
> passed), here's the data structure it returns on my test box. Having
> the {hosts} field for individual memcached servers, and the {total}
> field with its summary of the data probably most-wanted, seemed to
> me a good mix. If someone wants to just know, say, how full their
> space is, is it overly complicated to demand that they write:
>
>
> $s = $mcd_client->stats();
> $full = $s->{total}{malloc_total_alloc} / $s->{total}{malloc_mmapped_space};
>
>
> Here's the data returned:
>
>
> $VAR1 = {
>           'hosts' => {
>                        '127.0.0.1:11211' => {
>                                               'malloc' => {
>                                                             'arena_size' => 136648,
>                                                             'fastbin_blocks' => 0,
>                                                             'fastbin_space' => 0,
>                                                             'free_chunks' => 5,
>                                                             'max_total_alloc' => 0,
>                                                             'mmapped_regions' => 8,
>                                                             'mmapped_space' => 11567104,
>                                                             'releasable_space' => 70960,
>                                                             'total_alloc' => 61440,
>                                                             'total_free' => 75208
>                                                           },
>                                               'misc' => {
>                                                           'bytes' => 412609,
>                                                           'bytes_read' => 972017,
>                                                           'bytes_written' => 25841274,
>                                                           'cmd_get' => 29234,
>                                                           'cmd_set' => 437,
>                                                           'connection_structures' => 6,
>                                                           'curr_connections' => '3',
>                                                           'curr_items' => 295,
>                                                           'get_hits' => 18045,
>                                                           'get_misses' => 11189,
>                                                           'limit_maxbytes' => '10485760',
>                                                           'pid' => '11765',
>                                                           'rusage_system' => '3:340000',
>                                                           'rusage_user' => '1:900000',
>                                                           'time' => '1067432681',
>                                                           'total_connections' => 14604,
>                                                           'total_items' => 437,
>                                                           'uptime' => '120611',
>                                                           'version' => '1.1.9'
>                                                         },
>                                               'sizes' => {
>                                                            '1024' => '3',
>                                                            '1056' => '2',
>                                                            '1088' => '1',
>                                                            '1120' => '1',
> [snip]
>                                                            '896' => '2',
>                                                            '928' => '3',
>                                                            '96' => '3',
>                                                            '960' => '1',
>                                                            '992' => '6'
>                                                          }
>                                             }
>                      },
>           'self' => {
>                       'get' => 1
>                     },
>           'total' => {
>                        'bytes' => 412609,
>                        'bytes_read' => 972017,
>                        'bytes_written' => 25841274,
>                        'cmd_get' => 29234,
>                        'cmd_set' => 437,
>                        'connection_structures' => 6,
>                        'curr_items' => 295,
>                        'get_hits' => 18045,
>                        'get_misses' => 11189,
>                        'malloc_arena_size' => 136648,
>                        'malloc_fastbin_blocks' => 0,
>                        'malloc_fastbin_space' => 0,
>                        'malloc_free_chunks' => 5,
>                        'malloc_max_total_alloc' => 0,
>                        'malloc_mmapped_regions' => 8,
>                        'malloc_mmapped_space' => 11567104,
>                        'malloc_releasable_space' => 70960,
>                        'malloc_total_alloc' => 61440,
>                        'malloc_total_free' => 75208,
>                        'total_connections' => 14604,
>                        'total_items' => 437
>                      }
>         };
>
> --
>   Jamie McCarthy
>  http://mccarthy.vg/
>   jamie@mccarthy.vg
>
>