tokuhirom's Blog

Using memcached with LZ4

Cache::Memcached::Fast uses Compress::Zlib by default to use compression. It's bit slow on high traffic environment. I got a Compress::Zlib as a bottleneck in our web application.

In this case, you can use Compress::LZ4 for better performance.

I'm using this as following form:

use Cache::Memcached::Fast;
use Compress::LZ4;

    my $memcache = Cache::Memcached::Fast->new(+{
        %{config->cache},
        utf8               => 1,
        ketama_points      => 150,
        hash_namespace     => 0,
        compress_threshold => 5_000,
        compress_methods => [
            sub { ${$_[1]} = Compress::LZ4::compress(${$_[0]})   },
            sub { ${$_[1]} = Compress::LZ4::decompress(${$_[0]}) },
        ],
    });

Enjoy!