Memcache Startup & Storage Principles & Clustering

Source: Internet
Author: User

first, under Windows installation start

First, add the Bin folder of the Memcache to the PATH environment variable. Easy to use later command:


  


Then run the Memcached–dinstall command to install the Memcache service:


  


Then go to the calculated services page to see that the installation was successful:


  


To start the Memcache background service program:


  


In the background service, you see that Memcache's background service is started:


  


and then run. Telnet 127.0.0.111211来 Open telnetclient:


  


It turns out that Telnet is not enabled:


  


So at the start or shut down Windows features. Open Telnetclient


  


Then you need to restart your computer. Make the change effective.

Then run Telnet 127.0.0.1 11211来 again to open the telnetclient and open it successfully:


  


Test whether it is available, we telnetclient in the command, stats. Occurs such as the following information indicates normal:


  


Then we save a data and then take it out:


  


End Instructions our memcache has been installed successfully and started.


second, the role
2.1 Distributed Cache

As we move from the IT era to the DT era, our software architecture is also from standalone to cluster and distributed. and The first step toward distribution is to solve the problem of sharing login information with multiple servers.

By and by far, it is to solve the problem that multiple servers share common information .

Solve the problem, we can store the public information in the state server, or store it in a database, and then store it in our "distributed cache" and so on.

Because the read cache plus network transfer time is much smaller than the time to read the database (IO), so distributed cache is an excellent solution to the problem.

  


2.2 Reduce database pressure

All of our data are basically stored in the database, each time the database is accessed frequently, resulting in a sharp decline in database performance. Unable to service many other users at the same time, such as MySQL, especially frequent lock table, then I can memcache to share the pressure of the database. That is, the ability to do data caching, due to the memcache read and write performance can say the ultimate perfect.


three, storage principle

Memcache uses key-value pairs to store the method.

It is essentially a large hash table, and the maximum length of a key is 255 characters. The maximum expiration time is 30 days.

Its memory model is, for example, the following: Memcache pre-partitions the disposable memory space (Slab). Each partition is divided into multiple blocks (Chunk) with a maximum of 1M. However, the size of the block in the same partition is fixed. And then. When inserting data, the most appropriate block is found based on the size of the data. Then insert, of course, there will be some memory waste, but to some extent reduce memory fragmentation, overall, the advantages outweigh the disadvantages. When the memcache memory is full. It cleans up old data in the following principles: LRU idle > Expire > Minimum access.

And it uses lazy deletion, it does not provide the mechanism to monitor data expiration, but is inert. When you query the data for a key. If it expires, discard it directly.


Four, the principle of cluster construction

Memcache's cluster-cluster building is super simple. Server-side configuration is not required at all. It is the configuration of the cluster through the driver of the client, and the configuration is super simple.

Client implementation of the principle of the cluster: the first client configuration of multiple cluster machine IP and port list. Then the client driver before writing the data, first processing the key to get the hash value, the total number of machines to take redundancy. Then select the machine that corresponds to the remainder.


  


For example, think of a C # storage data to the Memcache cluster code:


  


v. Comparison with Redis

Since Redis is also often used as a distributed cache, a simple experience such as the following (the two specific controls) follows the use of both. Please go online to find the topic can be):

First, both are Key-value-type storage.

The memcache is multi-threaded (with a corresponding lock mechanism). Need to consider thread safety issues . Redis is single-threaded and does not need to be considered for thread safety issues.

Memcache does not provide a master-slave replication mechanism, fault tolerance is not good . (No ha-high availability); Redis provides master-slave replication.

The memcache cluster configurationis very easy and does not require server side configuration. Just need to initialize a serverlist on the client. Redis needs to be configured on the server side.

Memcache can only be cached and not persisted . Redis is a NoSQL memory database that provides two persistence mechanisms.

Redis provides five types of value, very rich (string/list/hash/set/zset), and memcache data types are relatively single .


Vi. Summary

Because of some of our current problems, high concurrent access to database pain: deadlock, disk IO pain: Very low efficiency, multi-service sharing data and so on.

Memcache with its own advantages: Read and write performance is perfect (no master-slave replication, all the code basically only consider the best performance); Super simple cluster setup. Open source. Low learning costs, easy access, rich success stories, etc., has become a popular distributed cache framework today.

Memcache Startup & Storage Principles & Clustering

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.