Couchbase Introduction-Better Cache system

Source: Internet
Author: User
Tags couchbase memcached redis

In the mobile internet era, we are faced with more clients, lower request latency, which of course needs to do a lot of Cache data to improve read and write speed. Terminology

Node: Refers to a server in a cluster. features of the existing Cache system

At present the industry uses the most Cache system mainly is memcached and Redis. These two Cache systems have a large user base, can be said to be a more mature solution, but also a lot of systems of course choice. However, in the use of memcached and Redis process, still encountered a lot of problems and limitations: Cluster support is not enough. There are obvious shortages in capacity expansion, load balancing and high availability. Persistent support is not good, and the cost of recovery after a problem occurs. Memcached does not support persistence at all, and redis persistence can result in high system intermittent load. I look forward to the ideal Cache system

Good cluster support Key can be dynamically dispersed (Auto Sharding) on different servers, the system capacity can be increased by dynamically adding server nodes. Without a single point of failure, no single point will cause data to be inaccessible. Read and write loads can be distributed evenly across different nodes of the system.

Support for asynchronous persistence facilitates rapid recovery and can even be used directly as a key/value database. Often when communicating with friends in the industry, you will mention using the key segmentation method to do capacity expansion and load balancing. However, there are many problems with static key segmentation: Cache system itself and the use of cache
Clients need to preset a piecewise logic, which can be very difficult if you need to adjust later in the logic. Cannot solve the problem of single point of failure, but also need additional means. Operation needs more people to participate in, to avoid key beyond the existing partitions, once the key can not find the corresponding server, access directly failed. systems closest to demand: Couchbase

Based on these ideas, I spent a few days in Google, Stack overflow, Quora to see a lot of people on the cache cluster discussion, find a comparison of the new system couchbase.


Mem vs cb memcached vs Couchbase Couchbase's cluster design Peer-to-peer network

All points of the Couchbase cluster are equivalent, but you need to specify a master node when you create a group or join a cluster, and all nodes are equal once the node is successfully joined to the cluster.

The advantage of Peer-to-peer networking is that any node in the cluster fails, and the cluster's external services are completely uninterrupted, but the capacity of the cluster is affected. Smart Client

Because Couchbase is a peer-to-peer cluster, all nodes can serve the client at the same time, this requires a method to expose the cluster node information to the client, Couchbase provides a set of mechanisms, the client can obtain the state of all nodes and node changes, The client calculates the location of the key based on the current state of the cluster. Vbucket

The introduction of Vbucket concept is an important basis for couchbase to realize auto sharding and dynamically increase and decrease nodes on line.

The simple explanation vbucket can start from the static fragment, the static slicing method is generally uses the key to calculate a hash, obtains the corresponding server, this algorithm is very simple, also easy to understand. As shown in the following code:

Servers = [' server1:11211 ', ' server2:11211 ', ' server3:11211 ']
server_for_key (key) = Servers[hash (key)% Servers.length]

But there are also a few problems: If a server fails, it will cause all key of the fragment to fail. Management is cumbersome if the server capacity is different. As mentioned earlier, the operation of the dimension, configuration is very inconvenient.

In order to decouple the key from the server, Couchbase introduced the Vbucket. It can be said that Vbucket represents a cache subset, the main features: Key hash corresponds to a vbucket, no longer directly corresponding to the server. The cluster maintains a global Vbucket and Server counterpart table. The important function of the smart client mentioned earlier is to synchronize the Vbucket table.

As shown in the following code:

Servers = [' server1:11211 ', ' server2:11211 ', ' server3:11211 ']
vbuckets = [0, 0, 1, 1, 2, 2]
server_for_key (key) = Servers[vbuckets[hash (key)% vbuckets.length]]

Because Vbucket the key to the static correspondence of the server to decouple, based on Vbucket can achieve some very powerful interesting features, such as: Replica, vbucket as the unit of the master-slave backup. If a node fails, just update the vbucket mapping table and enable backup data immediately. Dynamic expansion. After adding a new node, you can move some vbucket to the new node and update the Vbucket mapping table.

Vbucket is very important and you can write a separate article to share later. Summary Couchbase Peer-to-peer network design, smart client
directly capture the entire cluster information, load Balancing on the client, the entire cluster has no single point of failure, and fully support parallel expansion. With the introduction of Vbucket, the auto sharding is realized, and the subset of data can be moved on different nodes conveniently and flexibly to realize cluster dynamic management. Couchbase has a very professional web management interface and supports RESTful API management, which is also memcached,
Redis unreachable. If just do key/value cache,couchbase can completely replace memcached. Couchbase has been widely used in our production environment.
http://segmentfault.com/a/1190000002907171

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.