Apsaradb for memcache distributed Deployment Solution

Source: Internet
Author: User

Preface
A long time ago, I began to study memcache and wrote a series of learning experiences, such as discuz! . The dozens of replies that follow have also made this article a popular topic in this blog.

Meanwhile, in Baidu and Google, the keyword memcache occupies the second place (the first is official) for more than a year, providing some information for many friends who need to know or use memcache, but I always felt that it was not enough, so this article was born.

I have been talking about it for a long time. If you think it is too long, please read the last section, which is the focus of this article.

Basic Environment
In fact, the PHP-based extended memcache client has already been implemented and is very stable. First, I would like to explain some terms. memcache is an open-source project of danga.com, which can be analogous to services such as MySQL. The memcache extended by PHP is actually connected to memcache.

First, you can view the details of installing memcache:
Install memcache in Linux: http://www.ccvita.com/257.html
Install memcache in Windows: http://www.ccvita.com/258.html;
Second, the PHP extension installation, the official address is http://pecl.php.net/package/memcache
Finally, start the memcache service, such

/Usr/local/bin/memcached-D-P 11213-u root-M 10-C 1024-T 8-P/tmp/memcached. PID
/Usr/local/bin/memcached-D-P 11214-u root-M 10-C 1024-T 8-P/tmp/memcached. PID
/Usr/local/bin/memcached-D-P 11215-u root-M 10-C 1024-T 8-P/tmp/memcached. PID

Start three instances and use only 10 MB of memory for testing.

Distributed deployment
Memcache In the PECL extension of PHP has actually implemented multi-server support in version 2.0.0 and is now 2.2.5. See the following code.

$ Memcache = new memcache;
$ Memcache-> addserver ('localhost', 11213 );
$ Memcache-> addserver ('localhost', 11214 );
$ Memcache-> addserver ('localhost', 11215 );
$ Memstats = $ memcache-> getextendedstats ();
Print_r ($ memstats );

In the previous example, the distributed deployment of memcache has been implemented. Is it very simple.

Benign operation of Distributed Systems
In the actual use of memcache, the most serious problem is that when the server is increased or decreased, it will lead to a wide range of cache loss, which may lead to database performance bottlenecks, to avoid this problem, first look at the consistent hashing algorithm. For Chinese introduction, refer to here to achieve this by selecting a server algorithm change during access.

Modify the PHP memcache extension in the source code of memcache. c

"Memcache. hash_strategy" = Standard

Is

"Memcache. hash_strategy" = consistent

Re-compile. At this time, we use the consistent hashing algorithm to find the server to access data.

Effective test data shows that the use of consistent hashing can greatly improve the situation of large cache loss when memcache is added or deleted.
Nonconsistenthash: 92% of lookups changed after adding a target to the existing 10
Non consistenthash: 90% of lookups changed after removing 1 of 10 targets
Consistenthash: 6% of lookups changed after adding a target to the existing 10
Consistenthash: 9% of lookups changed after removing 1 of 10 targets

Tag: deployment, memcache, distributed

Kimi at 21:19:00 in memcache

Copyright statement: original works. You are welcome to reprint them.HyperlinkIndicate the original address, author information, and the statement.

"Memcache distributed Deployment Solution"

7 replies

  1. Deeka09:30:53Reply

    I think it is best to have a stable machine on the addserver connect.

  2. Guest15:44:40Reply

    Come on, boy! It shoshould be "memcached "....

    KimiJune 9 th, 2009 at 09:46:33Reply

    @ Guest, TKs for reminding me

     

  3. Dan Mu Qiu Feng16:51:01Reply

    I have made some improvements when I look at it again.

  4. Small14:18:53Reply

    I recently looked at the memcache source code. I don't know if I can write some source code analysis or analyze the implementation principle of memcache.

  5. Chen min08:39:26Reply

    I searched for memcached and found your website.
    The tag for seeing your daughter-in-law is big too.
    Made a link
    Please refer to the Technical article for more information.

  6. Liaofuqian10:20:48Reply

    Thanks for sharing. It is very powerful and learning.

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.