Use ringcache to improve Cassandra read and write Efficiency

Source: Internet
Author: User
Tags cassandra

Our previousArticle(Talk About the Cassandra client) explains how to query data in Cassandra on the client side.

Why use ringcache?

Cassandra's internal read/write process is like this:

1 The client first randomly finds a machine in the Cassandra cluster, and then sends the query request to this Cassandra machine.

2. The Cassandra machine that receives the query request will determine whether the data to be queried is in the Local Machine: directly query the data if it is in the local machine; if it is not in the local machine, forward the request to another machine for query and wait for the query result of the other machine.

3. The Cassandra machine that queries the request returns the final result to the client.

We can see that in the preceding query process, if the client sends the data to be queried to an unrelated Cassandra machine, then the unrelated Cassandra machine acts as a proxy.

The worst case is that all requests are sent to a certain Cassandra machine, which makes this Cassandra machine a bottleneck.

The ideal status is that the client directly sends the query request to the Cassandra machine that stores the data to be queried, thus eliminating the unnecessary proxy layer.

What if we reach this ideal state? Consider using the ringcache that comes with Cassandra (my version is 0.6.2.

How to Use ringcache

Ringcache is very easy to use.CodeYou can obtain the actual machine responsible for a specific data:

Ringcache = new ringcache (); List <inetaddress> endpoints = ringcache. getendpoint (keyspacename, key );

Here, we use only two lines of code to get the address of all machines under a keyspace key (if you are interested in the Cassandra model, you can refer to: big case Cassandra Data Model. In this way, we can directly perform read and write operations on these machines.

Note that the above Code depends on the Cassandra configuration file, so you must specify the environment variable to work properly.

How ringcache works

Why can ringcache find the desired node?

When executing ringcache rc = new ringcache ();, we will read the seed information in the configuration file, find a valid seed node, and request the token map information, and cache all the token map information on the local machine.

We are executing list <inetaddress> endpoints = ringcache. when getendpoint (keyspacename, key); is used, ringcache obtains the corresponding abstractreplicationstrategy Based on the token map found previously. This abstractreplicationstrategy can be based on the keyspacename specified by us, then locate the node information we need.

This explains how ringcache works.

Notes for using ringcache

Since ringcache allows us to quickly find the corresponding Cassandra node, can we use ringcache for all our queries in the future?

Of course not. After all, ringcache is only a cache, and the information in the Cassandra cluster changes at any time. Some machines may leave or new machines may be added. However, once ringcache is used, the information in it remains unchanged.

Therefore, we need to pay attention to this point in actual use and perform corresponding processing to better play the role of ringcache.

 

More about Cassandra: http://www.cnblogs.com/gpcuster/tag/Cassandra/

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.