This series of articles <memcached walkthrough, this is the 6th article, the previous article, has elaborated, memcached installation, access, session management, storage management. Starting from this article, there are several walkthroughs under the high-availability correlation of memcached.
The security of memcached, which carries a huge access to the backend database, is of great significance.
Brief description of Ha, if time allows to practice the next scenario as much as possible, then compare the pros and cons of each scheme horizontally.
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/86/09/wKiom1ezHaqg5aLkAABQEOh39c8884.png "title=" Sogou 20160816220056.png "alt=" Wkiom1ezhaqg5alkaabqeoh39c8884.png "/>
The main content of this article
Test of pseudo-cluster scheme
Clear memcached high-availability scenarios
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/86/0A/wKiom1ezHnfz3kJ3AAEgJSaYpQ0412.png "title=" 111. PNG "alt=" Wkiom1ezhnfz3kj3aaegjsaypq0412.png "/>
By comparing the two nosql schemes of memcached and Redis, it is easy to find out that the memcached cluster scheme design is simple, mainly in the client implementation.
Pseudo-cluster Scenario test steps
Preparing for the walkthrough environment
Host
|
Memcached Home Directory
|
Port
|
192.168.163.146 (HADOOP1)
|
/usr/local/memcached/
|
11211
|
192.168.163.156 (HADOOP2) |
/usr/local/memcached/ |
11211 |
192.168.163.166 (HADOOP3) |
/usr/local/memcached/ |
11211 |
Installation soon listed, please refer to the "memcached Walkthrough (1) Build memcached service"
2. Prepare the test code
public void testset () throws ExecutionException, interruptedexception, ioexception { final Memcachedclient mcc = new memcachedclient (New binaryconnectionfactory (), Addrutil.getaddresses ("192.168.163.146:11211 192.168.163.156:11211 192.168.163.166:11211")); for (int i=0;i<50;i++) { mcc.set ("Clusterkey_" +stringutils.leftpad ("" +i,4, "0"), 19000, " Clustervalue_ "+i); } system.out.println ("Set ok"); for (int i=0;i< 50;i++) { object o = Mcc.get ("Clusterkey_" + stringutils. Leftpad ("" +i,4, "0")); System.out.println (o); }// mcc.shutdown (); }
3. Test Result Analysis
[[Email protected] scripts]# ./memcached-tool hadoop1:11211 dump |sortdumping memcache contents Number of buckets: 1 Number of Items : 16dumping bucket 1 - 16 total itemsadd clusterkey_ 0002 0 1471374793 14add clusterkey_0005 0 1471374793 14add clusterkey_ 0008 0 1471374793 14add clusterkey_0011 0 1471374793 15add clusterkey_ 0014 0 1471374793 15add clusterkey_0017 0 1471374793 15add clusterkey_ 0020 0 1471374793 15add clusterkey_0023 0 1471374793 15add clusterkey_ 0026 0 1471374793 15add clusterkey_0029 0 1471374793 15add clusterkey_ 0032 0 1471374793 15add clusterkey_0035 0 1471374793 15add clusterkey_ 0038 0 1471374793 15add clusterkey_0041 0 1471374793 15add clusterkey_0044 0 1471374793 15add clusterkey_0047 0 1471374793 15[[email protected] scripts] # ./memcached-tool hadoop2:11211 dump |sortdumping memcache contents number of buckets: 1 number of items : 17dumping Bucket 1 - 17 total itemsadd clusterkey_0000 0 1471374795 14add clusterkey_0003 0 1471374795 14add clusterkey_0006 0 1471374795 14add clusterkey_0009 0 1471374795 14add clusterkey_0012 0 1471374795 15add clusterkey_0015 0 1471374795 15add clusterkey_0018 0 1471374795 15add clusterkey_0021 0 1471374795 15add clusterkey_0024 0 1471374795 15add clusterkey_0027 0 1471374795 15add clusterkey_0030 0 1471374795 15add clusterkey _0033 0 1471374795 15add clusterkey_0036 0 1471374795 15add clusterkey _0039 0 1471374795 15add clusterkey_0042 0 1471374795 15add clusterkey _0045 0 1471374795 15add clusterkey_0048 0 1471374795 15[[email Protected] scripts]# ./memcached-tool hadoop3:11211 dump |sortdumping memcache contents Number of buckets: 1 Number of items : 17dumping bucket 1 - 17 total itemsadd clusterkey_0001 0 1471374794 14add clusterkey_0004 0 1471374794 14add clusterkey_0007 0 1471374794 14add clusterkey_0010 0 1471374794 15add clusterkey_0013 0 1471374794 15add clusterkey_0016 0 1471374794 15add clusterkey_0019 0 1471374794 15add clusterkey_0022 0 1471374794 15add clusterkey_0025 0 1471374794 15add clusterkey_0028 0 1471374794 15add clusterkey_0031 0 1471374794 15add clusterkey_0034 0 1471374794 15add clusterkey_0037 0 1471374794 15add clusterkey_0040 0 1471374794 15add clusterkey_0043 0 1471374794 15add clusterkey_0046 0 1471374794 15add clusterkey_0049 0 1471374794 15
The above data, simple arrangement into a diagram, very intuitive, the data distribution is very scattered. Such an advantage can reduce hotspots.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/86/09/wKioL1ezIXnBL7KNAAByVS4wDqE461.png "title=" 1112. PNG "alt=" Wkiol1ezixnbl7knaabyvs4wdqe461.png "/>
It is important to note that
Final memcachedclient MCC = new Memcachedclient (new Binaryconnectionfactory (), Addrutil.getaddresses (" 192.168.163.146:11211 192.168.163.156:11211 192.168.163.166:11211 "));
Addrutil.getaddresses parameters, you can repeatedly add the node information, which is equivalent to the machine has the right to feel the weight, it will obviously result in uneven distribution of data.
4. Test the data distribution under the weight situation
public class spymemcachedclustertest extends testcase{ public Void testset () throws executionexception, interruptedexception, ioexception { final memcachedclient mcc = new memcachedclient (New binaryconnectionfactory (), Addrutil.getaddresses ("192.168.163.146:11211 192.168.163.146:11211 192.168.163.146:11211 192.168.163.156:11211 192.168.163.156:11211 192.168.163.166:11211 ")); for (int i=0;i<150;i++) { mcc.set ("Clusterkey_" +StringUtils.leftPad ("" " +i,4, "0"), 19000, "Clustervalue_" +i); } system.out.println ("OK");// mcc.shutdown (); &nbSp; for (int i=0;i<150;i++) { object o = mcc.get ("Clusterkey_" + Stringutils.leftpad ("" +i,4, "0")); System.out.println (o); } }}
Test results
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/86/0A/wKiom1ezI76hDt6nAAA7-miCN8c134.png "title=" 12sss.png "alt=" Wkiom1ezi76hdt6naaa7-micn8c134.png "/>
Comparison between the two graphs: it is not easy to see. Consistency can be considered in terms of data distribution, or very average, but the distribution of data volume is related to weight. Basic is 3:2:1. It is basically consistent with the weights configured in the program code above.
Keep doing the experiment.
5. Out of a node to see the hit rate
Public void testgets () throws ExecutionException, InterruptedException, ioexception{ final memcachedclient mcc = new Memcachedclient (New binaryconnectionfactory (), Addrutil.getaddresses (" 192.168.163.146:11211 192.168.163.146:11211 192.168.163.156:11211 192.168.163.156:11211 192.168.163.166:11211 ")); int nohit=0; for (int i=0;i<150;i++) { String key = "Clusterkey_" + stringutils.leftpad ( " + i, 4, " 0 "); object o = Mcc.get (key); if (O==null) { system.out.println (key+ "Miss"); nohit++; } } System.out.println ("lost:" +nohit);}
Modify the content, HADOOP1:HADOOP2:HADOOP3, have the original 3:2:1 distribution, modified into 2:2:1 distribution.
Test results
clusterkey_0001 Miss clusterkey_0002 Miss clusterkey_0010 Miss clusterkey_0011 Miss clusterkey_0019 Miss clusterkey_0020 Miss clusterkey_0028 Miss clusterkey_0037 Miss clusterkey_0039 Miss clusterkey_0046 Miss clusterkey_0048 Miss clusterkey_0049 Miss clusterkey_0055 Miss clusterkey_0057 Miss clusterkey_0058 Miss clusterkey_0064 Miss clusterkey_0066 Miss clusterkey_0067 Miss clusterkey_0069 Miss clusterkey_0073 Miss clusterkey_0075 Miss clusterkey_0076 Miss clusterkey_0078 Miss clusterkey_0079 Miss clusterkey_0082 Miss clusterkey_0084 Miss clusterkey_0085 Miss clusterkey_0087 Miss clusterkey_0088 Miss clusterkey_0089 Miss clusterkey_0091 Miss clusterkey_0093 Miss clusterkey_0094 Miss clusterkey_0096 Miss clusterkey_0097 Miss clusterkey_0098 Miss clusterkey_0099 Miss clusterkey_0100 Miss clusterkey_0101 Miss Clusterkey_0109 Miss clusterkey_0110 Miss clusterkey_0118 Miss clusterkey_0127 Miss clusterkey_0129 Miss clusterkey_0136 Miss clusterkey_0138 Miss clusterkey_0139 Miss clusterkey_0145 Miss &NBSP;&Nbsp; clusterkey_0147 Miss clusterkey_0148 Miss missing: 50
1/3 were lost.
Changed to 3:2 in time, lost also basically reached 1/3. This issue needs to be taken seriously, otherwise it is very easy to create a cache penetration situation.
In the future, we will study the consistency algorithm of spymemcached.
This article is from a "simple" blog, so be sure to keep this source http://dba10g.blog.51cto.com/764602/1839379
Memcached Walkthrough (6) high-availability instance ha (pseudo-cluster scenario)