Introduction to memcached

Matt Sergeant <matt@sergeant.org>

Memory Based Object Caching

The Problem

Memcached

Running Memcached

memcached -d -m 128 -p 11211
Simply start it on all servers.

Using memcached

sub does_user_exist {
    my ($name) = @_;
    if ($::Cache->get("user_exists:$name")) {
        return 1;
    }
    my $search = $::LDAP->search(base => "ou=People,dc=company,dc=net",
                                 scope => 'sub',
                                 filter => "(uid=$name)",
                                 );
    if ($search->is_error || ($search->count == 0)) {
        return 0;
    }
    $::Cache->set("user_exists:$name", 1);
    return 1;
}

It's that simple?

The Architecture

How it all works (client)

How it all works (server)

All operations atomic

Increment and Decrement

my $ret = $::MemCache->incr($key, $value);
if (!defined $ret) {
  $value = 1 unless defined $value;
  $ret = $::MemCache->set($key, $value);
}

Use Persistent Connections

$::Memd = Cache::Memcached->new(...);

Unusual Usage

Unusual Usage

How we could use at ML

Complex Issues

Basic Hashing

Basic Hashing

Consistent Hashing

Monitoring

STAT uptime 2398603
STAT rusage_user 1.029843
STAT rusage_system 89.927328
STAT curr_items 0
STAT bytes 0
STAT curr_connections 1
STAT connection_structures 2
STAT cmd_get 0
STAT cmd_set 0
STAT get_hits 0
STAT get_misses 0
STAT evictions 0
STAT bytes_read 7
STAT bytes_written 0
STAT limit_maxbytes 134217728
STAT threads 4

Monitoring Stats

More Information