Freitag, 8. Juli 2011

Kyoto Tycoon a memcached alternative with replication?

Today i searched for a replication mechanism for memcached. I only found an extension for memcache repcached  => don't know if it's maintained,  last update was 2009. I searched further and found Membase but that didn't fit my needs.
After that i read something about kyoto tycoon which offers full replication support for an in memory cache/database and it has a module addon which speaks the memcache protocol so the client side doesn't need to be changed if i switch to tyccon => That sounds good.
It also has many other features which you can read about at, like different backends ...
The Installation was quite easy.
kyotocabinet-1.2.65> ./configure --prefix=/home/test/kyotocabinet-1.2.65 && make && make check && make install
kyototycoon-0.9.49> ./configure --prefix=/home/test/kyototycoon-0.9.49 --with-kc=/home/test/kyotocabinet-1.2.65 && make && make check && make install
make sure you use gcc 4.2+ or bear with the warnings.
For my testing i used a Dual Master configuration since i want to be able to save and get data from both servers and auto recovery should also work.
No manual intervention should be needed if one of the servers crashes and is started again after a while.
Start the first master server.
~/kyototycoon_0.9.49/bin>./ktserver -dmn -log /home/test/kyototycoon_0.9.49/ktserver0.log -ls -bgs /home/test/kyototycoon_0.9.49/backgroundsnap0 -bgsi 30 -pid /home/test/kyototycoon_0.9.49/ -host localhost -port 10000 -ulog /home/test/kyototycoon_0.9.49/0000.ulog -sid 0 -mhost localhost -mport 10001 -rts /home/test/kyototycoon_0.9.49/0000.rts -plsv /home/test/kyototycoon_0.9.49/libexec/ -plex 'port=10002' ':#bnum=10000000#ktcapsiz=1g'
Start the second master server
~/kyototycoon_0.9.49/bin>./ktserver -dmn -log /home/test/kyototycoon_0.9.49/ktserver1.log -ls -bgs /home/test/kyototycoon_0.9.49/backgroundsnap1 -bgsi 30 -pid /home/test/kyototycoon_0.9.49/ -host localhost -port 10001 -ulog /home/test/kyototycoon_0.9.49/0001.ulog -sid 1 -mhost localhost -mport 10000 -rts /home/test/kyototycoon_0.9.49/0001.rts -plsv /home/test/kyototycoon_0.9.49/libexec/ -plex 'port=10003' ':#bnum=10000000#ktcapsiz=1g'

The option used have the following meaning.

  • plsv plugable server
  • plex option for the plugable server (memcache)
  • port specifies the native port (you must use for the tools from tyccon like ktremotemgr)
  • mport specifies the remote port of the second master server.
  • bgs make a background copy of the cache/database
  • bgsi is the intervall for the background copy
  • ulog updatelog (needed for replication)
  • rts replication timestamp

Now test the functionality with
~/kyototycoon_0.9.49/bin> ./ktremotemgr set -host localhost -port 10000 test1 value1
~/kyototycoon_0.9.49/bin> ./ktremotemgr set -host localhost -port 10000 test2 value2
~/kyototycoon_0.9.49/bin> ./ktremotemgr list -pv -host localhost -port 10000
test1   value1
test2   value2
~/kyototycoon-0.9.49/bin> ./ktremotemgr list -pv -host localhost -port 10001
test1   value1
test2   value2
This shows that normal replication is working.
Now kill one master server
~/kyototycoon-0.9.49/bin>  kill `cat /home/test/kyototycoon_0.9.49/`
~/kyototycoon-0.9.49/bin> ./ktremotemgr set -host localhost -port 10000 test3 value3
~/kyototycoon-0.9.49/bin> ./ktremotemgr set -host localhost -port 10000 test4 value4
~/kyototycoon-0.9.49/bin> ./ktremotemgr list -pv -host localhost -port 10001
./ktremotemgr: DB::open failed: : 6: network error: connection failed
~/kyototycoon-0.9.49/bin> ./ktremotemgr list -pv -host localhost -port 10000
test1   value1
test4   value4
test2   value2
test3   value3
start the second master again.
~/kyototycoon-0.9.49/bin>./ktremotemgr list -pv -host localhost -port 10001
test1   value1
test4   value4
test2   value2
test3   value3
This shows that the values which where saved when the second master was down are also available.
I did some performance testing and it seems that even when replication is used with tycoon the response time is the same as memcached.
Maybe the next time i will post some performance metrics if i have time.


Keine Kommentare:

Kommentar veröffentlichen