Memcached Cluster high Availability (HA) architecture

Source: Internet
Author: User

Memcache itself does not implement cluster functionality. Suppose you want to use a MEMCAHCE cluster using third-party software or programming to implement your own design, which will be used to memagent implement proxies, Memagent is also known as magent. We note that both of these are two tools. For memcache, magent installation Please refer to the article on Linux installation memcached services and magent compilation installation and common errors

Overall architecture

Direct:

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbgl1mjuxodkwmzq3/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast ">

Can see that there are two magent nodes, two memcached nodes, each magent node and proxy two memcached nodes, the application system side using Magent pool to call memcache for storage.

The hardware structure is two sets of linuxserver. Install the magent and memcached services separately on each server and set the boot to on.

The advantage of this is that no matter what one server goes down, it does not affect the magent pool to get memcache information, that is, to achieve memcached high availability (HA), assuming both machines are down. Just to show that your RP is too bad.

Of course. You can also use three, four, or many other servers to improve ha.

Test ha

Test background, Local LAN two server172.18.117.71 (memcacheport11211,magentport11210), 172.18.117.113 (memcacheport11211,magentport11210), and two serve R on the same LAN test machine, below is the test code:

Import Com.danga.memcached.memcachedclient;import Com.danga.memcached.sockiopool;public class MainTest {public static void Main (string[] arg) {Sockiopool pool = sockiopool.getinstance ();//magent Connection Pool pool.setservers (new string[] {" 172.18.117.71:11210 "," 172.18.117.113:11210 "});p Ool.setsocketto;p Ool.setnagle (false); Pool.setsocketconnectto (0);p ool.initialize (); Memcachedclient memcachedclient = new Memcachedclient () memcachedclient.set ("becd0000", "Test Sample");// System.out.println (Memcachedclient.get ("becd0000"));//system.out.println (Memcachedclient.flushall ());}}

Step 1: Key is "becd0000", Value is "test sample" through Magent pool in memcache

Step 2: Change the magent connection pool to a single memcache connection, code such as the following

Import Com.danga.memcached.memcachedclient;import Com.danga.memcached.sockiopool;public class MainTest {public static void Main (string[] arg) {Sockiopool pool = sockiopool.getinstance ();//magent Connection Pool pool.setservers (new string[] {" 172.18.117.71:11211 "});p Ool.setsocketto;p Ool.setnagle (False);p Ool.setsocketconnectto (0);p ool.initialize ( ); Memcachedclient memcachedclient = new Memcachedclient ()//memcachedclient.set ("becd0000", "Test sample"); System.out.println (Memcachedclient.get ("becd0000"));//system.out.println (Memcachedclient.flushall ());}}

Being able to see the individual interview Memcache is able to fetch the value that was stored just now.

Step 3: Change

Pool.setservers (new string[] {"172.18.117.71:11211"});
For

Pool.setservers (new string[] {"172.18.117.113:11211"});
Run again to see the same results as in step 2, you can take a value, indicating that the value stored through the Magent agent will be placed in two memcache

Step 4: Stop the memcached service on the 172.18.117.113

Stop memcached service command: Kill "Cat/tmp/memcached.pid"

Step 5: Take the value again through the magent agent, code such as the following:

Import Com.danga.memcached.memcachedclient;import Com.danga.memcached.sockiopool;public class MainTest {public static void Main (string[] arg) {Sockiopool pool = sockiopool.getinstance ();//magent Connection Pool pool.setservers (new string[] {" 172.18.117.71:11210 "," 172.18.117.113:11210 "});p Ool.setsocketto;p Ool.setnagle (false); Pool.setsocketconnectto (0);p ool.initialize (); Memcachedclient memcachedclient = new Memcachedclient ()//memcachedclient.set ("becd0000", "Test sample"); System.out.println (Memcachedclient.get ("becd0000"));//system.out.println (Memcachedclient.flushall ());}}

You can see that values can still be taken.

Step 6: Start the memcached service that you just stopped, and all the information in Memcache will be emptied after the reboot

Step 7: Go through the magent proxy pool again to fetch the value of key "becd0000". The code is as follows:

Import Com.danga.memcached.memcachedclient;import Com.danga.memcached.sockiopool;public class MainTest {public static void Main (string[] arg) {Sockiopool pool = sockiopool.getinstance ();//magent Connection Pool pool.setservers (new string[] {" 172.18.117.71:11210 "," 172.18.117.113:11210 "});p Ool.setsocketto;p Ool.setnagle (false); Pool.setsocketconnectto (0);p ool.initialize (); Memcachedclient memcachedclient = new Memcachedclient ()//memcachedclient.set ("becd0000", "Test sample"); System.out.println (Memcachedclient.get ("becd0000"));//system.out.println (Memcachedclient.flushall ());}}

Can see that the value taken here is null.

Results analysis

Through the above test can draw a conclusion

1, the value of the connection pool by Magent will be the magent agent of all memcached up

2, assume that there is a memcached down through the Magent proxy mode can also be taken to the value

3, assume that the memcached repair after the restart through the Magent proxy method to the value will be null, this is because the value of memcache after the restart after the stop of the Memcache service disappears (due in memory). However, Magent is assigned to a machine by hashing the key. Memcache will also be taken from this machine after the restart, all the values will not be empty.

How to Solve

1, after each memcache downtime repair can write a program to all the other memcache in the cluster to replicate all the information to the current downtime repaired memcache.

2, write their own agent. When the value that is taken from a memcached service is null, then the value on the other memcached is taken


Precautions

Magent are called in the same way as memcached. The client can switch to magent mode without changing the code


Copyright All points, reproduced please specify, resources.



Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Memcached Cluster high Availability (HA) architecture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.