Ticket #7 (assigned enhancement)

Opened 6 years ago

Last modified 6 years ago

Add access to more stats and a possibility to dump the cache

Reported by: darix@… Owned by: deveiant
Priority: major Milestone: Add New Features
Component: Source Version: 0.0.3
Keywords: additional statistics stats slabs Cc:

Description

as a proof of concept i wrote a small enhancement to the memcached class. it allows you to dump the content of the memcached. I did:

  • add a function to read stats slabs
  • get the keys of all items in each slab
  • iterate over all slabs at get the item keys.
  • query all items and return their values.

this really helps to debug.

my current code:

require 'rubygems'

require_gem 'Ruby-MemCache'

class MemCache
    def cache_dump( servers=@servers )
        asvrs = servers.select {|svr| svr.alive?}...
        cmds = self.make_command_map( "stats slabs", asvrs )..

        # Send them in parallel.
        keys = Array.new
        self.send( cmds ) do |svr,reply|
            slab_stats = self.get_items_keys(self.parse_slab_reply(reply))
        end     
        self.get_items(asvrs, keys)
    end

    def get_items (asvrs, keys)
        values = Array.new
        keys.each do | key | 
            cmds = self.make_command_map( "get #{key}", asvrs ) 
            self.send( cmds ) do |svr,value|
                values << value
            end     
        end     
        return values
    end

    def get_items_keys (asvrs, slab_ids)
        keys = Array.new
        slab_ids.each do | slab_id |
            kcmds = self.make_command_map( "stats cachedump #{slab_id} 0", asvrs ) 
            self.send( kcmds ) do |svr,reply|
                keys += self.parse_items_lines(reply)
            end     
        end     
        return keys

    end
    def parse_items_lines (reply)
        reply.map { | line | line.split(' ')[1] }
    end

    def parse_slab_reply (reply)
        reply.map{|line| line[/(\d+):/, 1].to_i }.uniq
    end
end
cache = MemCache::new '127.0.0.1:11211'
cache.debug = true
puts cache.cache_dump()

Change History

comment:1 Changed 6 years ago by deveiant

  • Keywords additional statistics stats slabs added
  • Status changed from new to assigned
  • Version set to 0.0.6
  • Milestone set to Maintenance

I'll look at adding this. If I can't get to it before the upcoming release, then I'll put it in a release of its own shortly thereafter.

comment:2 Changed 6 years ago by deveiant

  • Version changed from 0.0.6 to 0.0.3

Oops. Wrong version.

comment:3 Changed 6 years ago by deveiant

  • Milestone changed from Performance Improvements to Add New Features

Pushing this into the next milestone so I can release Ron's performance enhancements.

Note: See TracTickets for help on using tickets.