Memcached Replication On Server Clusters

When I was looking for ways to replicate the contents of memcached for high-availability performance, I found this memcached-repcached application. that has the ability to replicate the contents of one memcached to another.

Repcached key features

  • Multi master replication.
  • Asynchronous data repliacation.
  • Support all memcached command (set, add, delete, incr/decr, flush_all, cas)

People probably already know about memcached . It’s a robust, high performance key-value based memory object cache interface. but unfortunately, lack the ability to create redundancy and replication in memcached server clusters. although replication could be done at the application level. However, it all depends on each individual’s taste.

This is a quick and dirty experiment I have tried using memcached-repcached application on 2 servers.

Download memcached-repcached from repcached.lab.klab.org
Or you can download source rpm version from here
[download#33]

On the first server and second server extract memcached-1.2.8-repcached-2.2.tar.gz, compile with –enable-replication option when configure.

$ tar xvzf memcached-1.2.8-repcached-2.2.tar.gz
$ cd memcached-1.2.8-repcached-2.2
$ ./configure --enable-replication
$ make


On the first server, while still being in the directory when doing the compilation, run this command

[first server]$ ./memcached -u nobody -l 192.168.1.1 -p 22122 -m 64 -x 192.168.1.2 -v
replication: connect (peer=192.168.1.2:11212)
replication: marugoto copying
replication: close
replication: listen

On the second server, also run this command

[second server]$ ./memcached -u nobody -l 192.168.1.2 -p 22122 -m 64 -x 192.168.1.1 -v
replication: connect (peer=192.168.1.1:11212)
replication: marugoto copying
replication: start

Now, let’s try to simulate the process of replication on both memcached server.

[third server]$ telnet 192.168.1.1 22122
Trying 192.168.1.1...
Connected to 192.168.1.1.
Escape character is '^]'.
set hey 0 0 4
dude
STORED
get hey
VALUE hey 0 4
dude
END
quit
Connection closed by foreign host.

We stored a value “dude” with the key “hey” and verified with “get hey” command.

Now connecting to the second memcached server.

[third server]$ telnet 192.168.1.2 22122
Trying 192.168.1.2...
Connected to 192.168.1.2.
Escape character is '^]'.
get hey
VALUE hello 0 4
dude
END
quit
Connection closed by foreign host.

We got the same result on a second memcached server. recent memcached-repcached only capable for 2 node replication setup only. but it was pretty good. 🙂

6 Comments

  1. Joe

    I’ve done this and i’m getting the same message on both servers
    replication: connect (peer=192.168.1.2:11212)
    replication: marugoto copying
    replication: close
    replication: listen

    But when i telnet from a 3rd server into the 1st server and store a key and a value, I can telnet into the 2nd server but “get hey” just returns END.

    What am i doing wrong here? I want a master master setup so server 1 replicates server 2 and visa versa.

  2. Bash

    Nice Example of using repmemcached, but at the end you must get hey 04 values not get hello 0 5 .

    Joe,

    use get hey 0 4 not get hey only

  3. ck

    When I run the following command :

    ./memcached -u ck -l 127.0.0.1 -p 22122 -m 64 -x 127.0.0.1

    There are no errors but nothing is printed on the console and the command waits infinitely with a blinking cursor.

    What am I doing wrong? I am trying this on Ubuntu 10.04.

    • in what command specifically?and why did you running both memcached in the same localhost machine?
      anyway you can simulate replication in the same machine, you have to specified different port, i guess (not tested).

      memcached instance #1

      ./memcached -u nobody -l 127.0.0.1 -p 22122 -m 64 -x 127.0.0.1&
      

      memcached instance #2

      ./memcached -u nobody -l 127.0.0.1 -p 22123 -m 64 -x 127.0.0.1&
      

Leave a Reply

Your email address will not be published. Required fields are marked *