Cassandra Concurrency Technology Introduction

Source: Internet
Author: User
Tags cassandra

Summary

This article mainly introduces Cassandra Threading technology, the implementation of Cassandra is Java-based, so threading technology is also used by the JDK package provided by the threading class. Cassandra is a distributed database, and the entire concurrency architecture is based on a phased event-driven architecture (staged Envent-driven architecture) that can use the queue to decompose complex event drivers into stages.

one. Java Concurrency

Executor Frame
Http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Executor.html
We can create multithreading by integrating the thread class, implementing the Runnable interface, and so on. The Java concurrent package provides a more flexible way to implement.

public interface Executor{    void execute(Runnable command);}

Executor separates the task submission process from the execution process and uses runnable to represent the task directly. Based on the producer-consumer model, the task submission is the producer, and the thread performing the task corresponds to the consumer.

Executorservice provides life cycle management

Executorservice inherits the Executor interface, provides lifecycle management, and Executorservice has three states
Run, close, terminate.

Public interface Executorservice extends Executor {void shutdown (); List<runnable> Shutdownnow (); Boolean IsShutDown (); Boolean isterminated (); Boolean awaittermination (Long Timeout, Timeunit unit) throws interruptedexception;<t> future<t> submit (callable<t> Task); <t > future<t> Submit (Runnable task, T result); Future<?> Submit (Runnable Task);<t> list<future<t>> InvokeAll (collection<? extends callable<t>> tasks) throws interruptedexception;<t> list<future<t>> InvokeAll (Collection <? Extends callable<t>> tasks, long timeout, timeunit unit) throws Interruptedexcept Ion;<t> T invokeany (collection<? extends callable<t>> tasks) throws Interruptedexception, ExecutionE Xception;<t> T invokeany (collection<? extends callable<t>> tasks, long timeout, timeunit Unit) throws Interruptedexception, Executionexception, TimeoutException;} 

Executor is an asynchronous way to execute a task, so at some point, there are tasks that are not completed and some are waiting in the queue. The shutdown method provides a gentle shutdown that completes a task that has already been started and does not accept new tasks. Shutdownnow is the force to close all tasks.

Future provides tasks with return results
Executor does not provide return results, so a future with a return result is required

public interface Future<V> {    boolean cancel(boolean mayInterruptIfRunning);    boolean isCancelled();    boolean isDone();    V get() throws InterruptedException, ExecutionException;    V get(long timeout, TimeUnit unit)    throws InterruptedException, ExecutionException, TimeoutException;}

In the Executorservice Submit method above we can see that the future class is needed so that the executor can get the result of the task or cancel the task based on the future of the return. The Get method of the future is used to get the task execution, if the task is completed, it will immediately return or throw an exception, if not completed will block, waiting for the task to complete.

http://www.javaworld.com/article/2078809/java-concurrency/ java-concurrency-java-101-the-next-generation-java-concurrency-without-the-pain-part-1.html?page=2

two. Seda Architecture

The SEDA architecture was first proposed by Matt Welsh of the University of California, Berkeley, David Culler, and Eric Brewer.
(Please visit the original paper): Http://www.eecs.harvard.edu/~mdw/papers/seda-sosp01.pdf
The Seda architecture divides the application into different stages. Each phase is built independently, responsible for resource management alone, and has an event queue associated with it. Each stage is connected by a queue. Seda uses dynamic resource thresholds to control resource management so that the system can adapt to overload situations.

three. Cassandra Threading Technology

The Cassandra phase is single-threaded and multithreaded, and you can view information at each stage through Nodetool tpstats. It can also be monitored by the metrics exposed by JMX.
Cassandra the health condition of each stage to judge the bottleneck and problem of the cluster. There are five main properties of the

mbean tpstats /tr>
activecount active line is impersonating the number of tasks processed
pendingtasks pending queue the number of tasks waiting for a thread
completedtasks completed< /td> The number of tasks completed
currentlyblockedtasks blocked when thread in the threads pool is assigned, the pending task in the queue is also set to the maximum value. The incoming task will be blocked by the block
totalblockedtasks all time blocked

Generally normal systems do not appear in block tasks. There is a block, usually the system will be a problem. Operations personnel need to take relevant measures. The default value for the number of Cassandra Multi-thread pool threads is 32.

Cassandra Single Thread Stage

stage name function
Antientropystage Create Merkle tree to fix data consistency issues
Commitlogarchiver Backup or Restore commit log
Gossipstage Gossip communication between nodes
Migrationstage Data table schema Change
Miscstage Snapshot and copying data after a node has been completely removed
Memtablepostflusher After the mebtable is flush to disk, delete the corresponding Commitlog,flush secondary indexes
Tracing Query Trace

Cassandra Multithreading phase

flushwriter
hintedhandoff
intern Alresponsestage
mem Orymeter Calculate memory usage and memtable size
mutationstage
readstage
readrepairstage Execute read Repair operation
replicateonwritestage
requestresponsestage request reply

These stage definitions can be seen in the Org.apache.cassandra.concurrent.StageManager class

four. Splitting a write operation from a stage perspective

In this article there is a brief mention of Cassandra's writing process http://blog.csdn.net/fs1360472174/article/details/51174487
Write operation mainly involves the stage has mutationstage,flushwriter,memtablepostflusher,countermutation,
Migrationstage
Details will be detailed in a separate article

Five. Reference

http://blog.csdn.net/lxlzhn/article/details/8163380
Https://wiki.apache.org/cassandra/ArchitectureInternals

Cassandra Concurrency Technology Introduction

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.